Skip to content

Commit

Permalink
Merge pull request #3005 from planetarium/pos-migration
Browse files Browse the repository at this point in the history
Add features for PoS with Guild
  • Loading branch information
OnedgeLee authored Nov 15, 2024
2 parents 9f16611 + 5d4a9d6 commit cd378f2
Show file tree
Hide file tree
Showing 289 changed files with 14,534 additions and 2,455 deletions.
88 changes: 0 additions & 88 deletions .Lib9c.Benchmarks/Actions/AutoJoinGuild.cs

This file was deleted.

128 changes: 128 additions & 0 deletions .Lib9c.Benchmarks/Actions/MigrateDelegation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
using BenchmarkDotNet.Attributes;
using Bencodex.Types;
using Lib9c.Tests.Action;
using Lib9c.Tests.Util;
using Libplanet.Action.State;
using Libplanet.Crypto;
using Libplanet.Mocks;
using Nekoyume;
using Nekoyume.Action.Guild;
using Nekoyume.Action.Guild.Migration;
using Nekoyume.Action.Guild.Migration.LegacyModels;
using Nekoyume.Extensions;
using Nekoyume.TypedAddress;

namespace Lib9c.Benchmarks.Actions;

public class MigrateDelegation
{
private GuildAddress planetariumGuild = AddressUtil.CreateGuildAddress();
private AgentAddress target = AddressUtil.CreateAgentAddress();
private AgentAddress signer = AddressUtil.CreateAgentAddress();
private IWorld worldEmpty;
private IWorld worldBeforeGuildMigration;
private IWorld worldBeforeParticipantMigration;
private IWorld worldAfterMigration;

[GlobalSetup]
public void Setup()
{
worldEmpty = new World(MockUtil.MockModernWorldState);
var legacyPlanetariumGuild = new LegacyGuild(GuildConfig.PlanetariumGuildOwner);
var legacyPlanetariumGuildParticipant = new LegacyGuildParticipant(planetariumGuild);
worldBeforeGuildMigration = worldEmpty
.MutateAccount(
Addresses.Guild,
account => account.SetState(planetariumGuild, legacyPlanetariumGuild.Bencoded))
.MutateAccount(
Addresses.GuildParticipant,
account => account.SetState(GuildConfig.PlanetariumGuildOwner, legacyPlanetariumGuildParticipant.Bencoded))
.MutateAccount(
Addresses.GuildParticipant,
account => account.SetState(target, legacyPlanetariumGuildParticipant.Bencoded))
.MutateAccount(
Addresses.GuildMemberCounter,
account => account.SetState(planetariumGuild, (Integer)2));
worldBeforeParticipantMigration = new MigratePlanetariumGuild().Execute(new ActionContext
{
PreviousState = worldBeforeGuildMigration,
Signer = new PrivateKey().Address,
});
}

[Benchmark]
public void Execute_Empty()
{
var action = new Nekoyume.Action.Guild.Migration.MigrateDelegation(target);
try
{
action.Execute(new ActionContext
{
IsPolicyAction = false,
PreviousState = worldEmpty,
Signer = signer,
});
}
catch
{
// Do nothing.
}
}

[Benchmark]
public void Execute_Before_Guild_Migration()
{
var action = new Nekoyume.Action.Guild.Migration.MigrateDelegation(target);
try
{
action.Execute(new ActionContext
{
IsPolicyAction = false,
PreviousState = worldBeforeGuildMigration,
Signer = signer,
});
}
catch
{
// Do nothing.
}
}

[Benchmark]
public void Execute_Before_Participant_Migration()
{
var action = new Nekoyume.Action.Guild.Migration.MigrateDelegation(target);
try
{
action.Execute(new ActionContext
{
IsPolicyAction = false,
PreviousState = worldBeforeParticipantMigration,
Signer = signer,
});
}
catch
{
// Do nothing.
}
}

[Benchmark]
public void Execute_After_Migration()
{
var action = new Nekoyume.Action.Guild.Migration.MigrateDelegation(target);
try
{
action.Execute(new ActionContext
{
IsPolicyAction = false,
PreviousState = worldAfterMigration,
Signer = signer,
});
}
catch
{
// Do nothing.
}
}
}
110 changes: 0 additions & 110 deletions .Lib9c.Benchmarks/Actions/MigratePledgeToGuild.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void LoadPlainValue(IValue plainValue)

public IWorld Execute(IActionContext context)
{
context.UseGas(1);
GasTracer.UseGas(1);
return context.PreviousState;
}
}
Expand Down
2 changes: 0 additions & 2 deletions .Lib9c.Plugin/PluginActionEvaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
using Libplanet.Store;
using Nekoyume.Action;
using Nekoyume.Action.Loader;
using Nekoyume.PolicyAction.Tx.Begin;


namespace Lib9c.Plugin
{
Expand Down
16 changes: 5 additions & 11 deletions .Lib9c.Tests/Action/ActionContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ namespace Lib9c.Tests.Action
using Libplanet.Action.State;
using Libplanet.Common;
using Libplanet.Crypto;
using Libplanet.Types.Assets;
using Libplanet.Types.Blocks;
using Libplanet.Types.Evidence;
using Libplanet.Types.Tx;

public class ActionContext : IActionContext
{
private long _gasUsed;

private IRandom _random = null;

private IReadOnlyList<ITransaction> _txs = null;
Expand All @@ -35,6 +34,8 @@ public class ActionContext : IActionContext

public int BlockProtocolVersion { get; set; } = BlockMetadata.CurrentProtocolVersion;

public BlockCommit LastCommit { get; set; }

public IWorld PreviousState { get; set; }

public int RandomSeed { get; set; }
Expand All @@ -43,6 +44,8 @@ public class ActionContext : IActionContext

public bool IsPolicyAction { get; set; }

public FungibleAssetValue? MaxGasPrice { get; set; }

public IReadOnlyList<ITransaction> Txs
{
get => _txs ?? ImmutableList<ITransaction>.Empty;
Expand All @@ -55,17 +58,8 @@ public IReadOnlyList<EvidenceBase> Evidence
set => _evs = value;
}

public void UseGas(long gas)
{
_gasUsed += gas;
}

public IRandom GetRandom() => _random ?? new TestRandom(RandomSeed);

public long GasUsed() => _gasUsed;

public long GasLimit() => 0;

// FIXME: Temporary measure to allow inheriting already mutated IRandom.
public void SetRandom(IRandom random)
{
Expand Down
Loading

0 comments on commit cd378f2

Please sign in to comment.