Skip to content

Commit

Permalink
Revert "Merge pull request planetarium#3494 from limebell/feature/sys…
Browse files Browse the repository at this point in the history
…tem-accounts"

This reverts commit 11b9f54, reversing
changes made to eabf0b3.
  • Loading branch information
OnedgeLee committed Nov 23, 2023
1 parent 11b9f54 commit e3734ca
Show file tree
Hide file tree
Showing 73 changed files with 347 additions and 685 deletions.
7 changes: 0 additions & 7 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@ To be released.
- (Libplanet.Action) Type of `Initialize.States` property became
`IImmutableDictionary<Address, IImmutableDictionary<Address, IValue>>?`.
(was `IImmutableDictionary<Address, IValue>?`) [[#3462]]
- (Libplanet.Action) New property `SystemAccounts` added to
`IActionContext` interface. [[#3494]]
- (Libplanet.Action) New property `SystemAccountsGetter` added to
`IBlockPolicy` interface. [[#3494]]


### Backward-incompatible network protocol changes
Expand All @@ -89,8 +85,6 @@ To be released.
- Added `WorldBaseState` class.
- (Libplanet.Action) Added `ReservedAddresses` static class. [[#3462]]
- (Libplanet.Action) Added `WorldDeltaExtensions` static class. [[#3462]]
- (Libplanet.Action) Added `ISystemAccounts` interface. [[#3494]
- (Libplanet.Action) Added `ISystemAccountsGetter` interface. [[#3494]]
- (Libplanet.Explorer) Added `AccountStateType` class. [[#3462]]
- (Libplanet.Explorer) Added `WorldStateType` class. [[#3462]]
- (Libplanet.Explorer) Added `WorldStateType` class. [[#3462]]
Expand Down Expand Up @@ -123,7 +117,6 @@ To be released.
### CLI tools

[#3462]: https://github.com/planetarium/libplanet/pull/3462
[#3494]: https://github.com/planetarium/libplanet/pull/3494


Version 3.7.0
Expand Down
8 changes: 0 additions & 8 deletions Libplanet.Action.Tests/ActionContextTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,12 @@ public class ActionContextTest
private readonly System.Random _random;
private readonly Address _address;
private readonly TxId _txid;
private readonly ISystemAccounts _systemAccounts;

public ActionContextTest()
{
_random = new System.Random();
_address = _random.NextAddress();
_txid = _random.NextTxId();
_systemAccounts = new SystemAccounts(
new SystemAccountsGetter(_ => ReservedAddresses.DefaultAccount), null);
}

[Fact]
Expand All @@ -37,7 +34,6 @@ public void RandomShouldBeDeterministic()
signer: _address,
txid: _txid,
miner: _address,
systemAccounts: _systemAccounts,
blockIndex: 1,
blockProtocolVersion: Block.CurrentProtocolVersion,
previousState: new World(new MockWorldState()),
Expand All @@ -56,7 +52,6 @@ public void GuidShouldBeDeterministic()
signer: _address,
txid: _txid,
miner: _address,
systemAccounts: _systemAccounts,
blockIndex: 1,
blockProtocolVersion: Block.CurrentProtocolVersion,
previousState: new World(new MockWorldState()),
Expand All @@ -68,7 +63,6 @@ public void GuidShouldBeDeterministic()
signer: _address,
txid: _txid,
miner: _address,
systemAccounts: _systemAccounts,
blockIndex: 1,
blockProtocolVersion: Block.CurrentProtocolVersion,
previousState: new World(new MockWorldState()),
Expand All @@ -80,7 +74,6 @@ public void GuidShouldBeDeterministic()
signer: _address,
txid: _txid,
miner: _address,
systemAccounts: _systemAccounts,
blockIndex: 1,
blockProtocolVersion: Block.CurrentProtocolVersion,
previousState: new World(new MockWorldState()),
Expand Down Expand Up @@ -120,7 +113,6 @@ public void GuidVersionAndVariant()
signer: _address,
txid: _txid,
miner: _address,
systemAccounts: _systemAccounts,
blockIndex: 1,
blockProtocolVersion: Block.CurrentProtocolVersion,
previousState: new World(new MockWorldState()),
Expand Down
6 changes: 3 additions & 3 deletions Libplanet.Action.Tests/ActionEvaluationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ this IEnumerable<IActionEvaluation> evaluations
ImmutableDictionary<Address, IValue>.Empty,
(dirty, ev) => dirty.SetItems(
ev.OutputState.GetAccount(
ReservedAddresses.DefaultAccount).GetUpdatedStates())
ReservedAddresses.LegacyAccount).GetUpdatedStates())
);

public static IImmutableDictionary<(Address, Currency), FungibleAssetValue>
Expand All @@ -26,7 +26,7 @@ this IEnumerable<IActionEvaluation> evaluations
ImmutableDictionary<(Address, Currency), FungibleAssetValue>.Empty,
(dirty, ev) => dirty.SetItems(
ev.OutputState.GetAccount(
ReservedAddresses.DefaultAccount).GetUpdatedBalances())
ReservedAddresses.LegacyAccount).GetUpdatedBalances())
);

public static IImmutableDictionary<Currency, FungibleAssetValue>
Expand All @@ -35,7 +35,7 @@ public static IImmutableDictionary<Currency, FungibleAssetValue>
ImmutableDictionary<Currency, FungibleAssetValue>.Empty,
(dirty, ev) => dirty.SetItems(
ev.OutputState.GetAccount(
ReservedAddresses.DefaultAccount).GetUpdatedTotalSupplies())
ReservedAddresses.LegacyAccount).GetUpdatedTotalSupplies())
);
}
}
14 changes: 5 additions & 9 deletions Libplanet.Action.Tests/ActionEvaluationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ namespace Libplanet.Action.Tests
public class ActionEvaluationTest
{
private readonly ILogger _logger;
private readonly ISystemAccounts _systemAccounts = new SystemAccounts(
new SystemAccountsGetter(_ => ReservedAddresses.DefaultAccount), null);

public ActionEvaluationTest(ITestOutputHelper output)
{
Expand All @@ -29,19 +27,18 @@ public ActionEvaluationTest(ITestOutputHelper output)
[Fact]
public void Constructor()
{
var txid = new System.Random().NextTxId();
Address address = new PrivateKey().ToAddress();
IWorld world = new World(new MockWorldState());
world = world.SetAccount(
ReservedAddresses.DefaultAccount,
world.GetAccount(ReservedAddresses.DefaultAccount).SetState(address, (Text)"item"));
ReservedAddresses.LegacyAccount,
world.GetAccount(ReservedAddresses.LegacyAccount).SetState(address, (Text)"item"));
var txid = new System.Random().NextTxId();
var evaluation = new ActionEvaluation(
new DumbAction(address, "item"),
new ActionContext(
address,
txid,
address,
_systemAccounts,
1,
Block.CurrentProtocolVersion,
new World(new MockWorldState()),
Expand All @@ -60,12 +57,11 @@ public void Constructor()
Assert.Equal(1, evaluation.InputContext.BlockIndex);
Assert.Null(
evaluation.InputContext.PreviousState.GetAccount(
ReservedAddresses.DefaultAccount).GetState(address)
ReservedAddresses.LegacyAccount).GetState(address)
);
Assert.Equal(
(Text)"item",
evaluation.OutputState
.GetAccount(ReservedAddresses.DefaultAccount).GetState(address)
evaluation.OutputState.GetAccount(ReservedAddresses.LegacyAccount).GetState(address)
);
}
}
Expand Down
4 changes: 2 additions & 2 deletions Libplanet.Action.Tests/Common/Attack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public override IWorld Execute(IActionContext context)
IImmutableSet<string> usedWeapons = ImmutableHashSet<string>.Empty;
IImmutableSet<string> targets = ImmutableHashSet<string>.Empty;
IWorld previousState = context.PreviousState;
IAccount legacyAccount = previousState.GetAccount(ReservedAddresses.DefaultAccount);
IAccount legacyAccount = previousState.GetAccount(ReservedAddresses.LegacyAccount);

object value = legacyAccount.GetState(TargetAddress);
if (!ReferenceEquals(value, null))
Expand All @@ -49,7 +49,7 @@ public override IWorld Execute(IActionContext context)
var result = new BattleResult(usedWeapons, targets);
legacyAccount = legacyAccount.SetState(TargetAddress, result.ToBencodex());

return previousState.SetAccount(ReservedAddresses.DefaultAccount, legacyAccount);
return previousState.SetAccount(ReservedAddresses.LegacyAccount, legacyAccount);
}
}
}
4 changes: 2 additions & 2 deletions Libplanet.Action.Tests/Common/DelayAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ public IWorld Execute(IActionContext context)
Thread.Sleep(MilliSecond);
var ended = DateTimeOffset.UtcNow;
var delayAccount = state
.GetAccount(ReservedAddresses.DefaultAccount)
.GetAccount(ReservedAddresses.LegacyAccount)
.SetState(TrivialUpdatedAddress, new Bencodex.Types.Integer(MilliSecond));
state = state.SetAccount(ReservedAddresses.DefaultAccount, delayAccount);
state = state.SetAccount(ReservedAddresses.LegacyAccount, delayAccount);
Log.Debug(
"{MethodName} Total Executed Time: {Elapsed}. Delay target: {MilliSecond}",
nameof(DelayAction),
Expand Down
4 changes: 2 additions & 2 deletions Libplanet.Action.Tests/Common/DetectRehearsal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ public override void LoadPlainValue(IValue plainValue)
public override IWorld Execute(IActionContext context)
{
IWorld previousState = context.PreviousState;
IAccount legacyAccount = previousState.GetAccount(ReservedAddresses.DefaultAccount);
IAccount legacyAccount = previousState.GetAccount(ReservedAddresses.LegacyAccount);
ResultState = context.Rehearsal;
return previousState.SetAccount(
ReservedAddresses.DefaultAccount,
ReservedAddresses.LegacyAccount,
legacyAccount.SetState(
TargetAddress,
new Bencodex.Types.Boolean(context.Rehearsal)
Expand Down
4 changes: 2 additions & 2 deletions Libplanet.Action.Tests/Common/DumbAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public IWorld Execute(IActionContext context)
return world;
}

IAccount account = world.GetAccount(ReservedAddresses.DefaultAccount);
IAccount account = world.GetAccount(ReservedAddresses.LegacyAccount);
string items = (Text?)account.GetState(TargetAddress);
string item = RecordRehearsal
? $"{Item}:{context.Rehearsal}"
Expand Down Expand Up @@ -221,7 +221,7 @@ public IWorld Execute(IActionContext context)
Rehearsal = context.Rehearsal,
});

return world.SetAccount(ReservedAddresses.DefaultAccount, account);
return world.SetAccount(ReservedAddresses.LegacyAccount, account);
}

public void LoadPlainValue(IValue plainValue)
Expand Down
4 changes: 2 additions & 2 deletions Libplanet.Action.Tests/Common/MinerReward.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void LoadPlainValue(Dictionary plainValue)
public IWorld Execute(IActionContext ctx)
{
IWorld states = ctx.PreviousState;
IAccount legacyAccount = states.GetAccount(ReservedAddresses.DefaultAccount);
IAccount legacyAccount = states.GetAccount(ReservedAddresses.LegacyAccount);

string rewardRecord = (Text?)legacyAccount.GetState(RewardRecordAddress);

Expand All @@ -54,7 +54,7 @@ public IWorld Execute(IActionContext ctx)
int reward = previousReward + Reward;

legacyAccount = legacyAccount.SetState(ctx.Miner, (Integer)reward);
return states.SetAccount(ReservedAddresses.DefaultAccount, legacyAccount);
return states.SetAccount(ReservedAddresses.LegacyAccount, legacyAccount);
}
}
}
6 changes: 3 additions & 3 deletions Libplanet.Action.Tests/Common/RandomAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ public void LoadPlainValue(IValue plainValue)
public IWorld Execute(IActionContext context)
{
IWorld states = context.PreviousState;
IAccount legacyAccount = states.GetAccount(ReservedAddresses.DefaultAccount);
IAccount legacyAccount = states.GetAccount(ReservedAddresses.LegacyAccount);
if (context.Rehearsal)
{
return states.SetAccount(
ReservedAddresses.DefaultAccount,
ReservedAddresses.LegacyAccount,
legacyAccount.SetState(Address, Null.Value));
}

legacyAccount = legacyAccount.SetState(Address, (Integer)context.GetRandom().Next());
return states.SetAccount(ReservedAddresses.DefaultAccount, legacyAccount);
return states.SetAccount(ReservedAddresses.LegacyAccount, legacyAccount);
}
}
}
4 changes: 2 additions & 2 deletions Libplanet.Action.Tests/Common/SetValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public void LoadPlainValue(IValue plainValue)
public IWorld Execute(IActionContext context)
{
IWorld states = context.PreviousState;
IAccount legacyAccount = states.GetAccount(ReservedAddresses.DefaultAccount);
IAccount legacyAccount = states.GetAccount(ReservedAddresses.LegacyAccount);
return states.SetAccount(
ReservedAddresses.DefaultAccount, legacyAccount.SetValidator(Validator));
ReservedAddresses.LegacyAccount, legacyAccount.SetValidator(Validator));
}

/// <inheritdoc cref="IEquatable{T}.Equals(T)"/>
Expand Down
2 changes: 1 addition & 1 deletion Libplanet.Action.Tests/Loader/TypedActionLoaderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void LoadAction()
new List<Validator>()
{ new Validator(new PrivateKey().PublicKey, 1) }).Bencoded,
Dictionary.Empty.Add(
ReservedAddresses.DefaultAccount.ToByteArray(),
ReservedAddresses.LegacyAccount.ToByteArray(),
Dictionary.Empty.Add(
default(Address).ToByteArray(), "initial value"))));
var action = new Initialize();
Expand Down
6 changes: 3 additions & 3 deletions Libplanet.Action.Tests/Mocks/MockWorldState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public MockWorldState(
Legacy = Trie
.Get(new[]
{
ToStateKey(ReservedAddresses.DefaultAccount),
ToStateKey(ReservedAddresses.LegacyAccount),
})
.Any(v => v == null);
}
Expand All @@ -37,7 +37,7 @@ public MockWorldState(
public bool Legacy { get; private set; }

public IAccount GetAccount(Address address)
=> Legacy && address.Equals(ReservedAddresses.DefaultAccount)
=> Legacy && address.Equals(ReservedAddresses.LegacyAccount)
? new Account(new MockAccountState(_stateStore, Trie.Hash))
: new Account(new MockAccountState(
_stateStore,
Expand All @@ -46,7 +46,7 @@ public IAccount GetAccount(Address address)
: null));

public IWorldState SetAccountState(Address address, IAccount account)
=> Legacy && address.Equals(ReservedAddresses.DefaultAccount)
=> Legacy && address.Equals(ReservedAddresses.LegacyAccount)
? new MockWorldState(_stateStore, account.Trie.Hash)
: new MockWorldState(
_stateStore,
Expand Down
10 changes: 3 additions & 7 deletions Libplanet.Action.Tests/Sys/InitializeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ private static readonly IImmutableDictionary<Address, IValue>
[default] = (Text)"initial value",
}.ToImmutableDictionary();

private readonly ISystemAccounts _systemAccounts = new SystemAccounts(
new SystemAccountsGetter(_ => ReservedAddresses.DefaultAccount), null);

[Fact]
public void Constructor()
{
Expand All @@ -47,11 +44,11 @@ public void Execute()
var random = new System.Random();
Address signer = random.NextAddress();
var prevState = new World(new MockWorldState());
BlockHash genesisHash = random.NextBlockHash();
var context = new ActionContext(
signer: signer,
txid: random.NextTxId(),
miner: random.NextAddress(),
systemAccounts: _systemAccounts,
blockIndex: 0,
blockProtocolVersion: Block.CurrentProtocolVersion,
previousState: prevState,
Expand All @@ -67,10 +64,10 @@ public void Execute()

Assert.Equal(
_validatorSet,
nextState.GetAccount(ReservedAddresses.DefaultAccount).GetValidatorSet());
nextState.GetAccount(ReservedAddresses.LegacyAccount).GetValidatorSet());
Assert.Equal(
_states[default],
nextState.GetAccount(ReservedAddresses.DefaultAccount).GetState(default));
nextState.GetAccount(ReservedAddresses.LegacyAccount).GetState(default));
}

[Fact]
Expand All @@ -84,7 +81,6 @@ public void ExecuteInNonGenesis()
signer: signer,
txid: random.NextTxId(),
miner: random.NextAddress(),
systemAccounts: _systemAccounts,
blockIndex: 10,
blockProtocolVersion: Block.CurrentProtocolVersion,
previousState: prevState,
Expand Down
6 changes: 1 addition & 5 deletions Libplanet.Action/ActionContext.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics.Contracts;
using System.Threading;
using Libplanet.Action.State;
using Libplanet.Crypto;
Expand All @@ -16,7 +17,6 @@ public ActionContext(
Address signer,
TxId? txid,
Address miner,
ISystemAccounts systemAccounts,
long blockIndex,
int blockProtocolVersion,
IWorld previousState,
Expand All @@ -27,7 +27,6 @@ public ActionContext(
Signer = signer;
TxId = txid;
Miner = miner;
SystemAccounts = systemAccounts;
BlockIndex = blockIndex;
BlockProtocolVersion = blockProtocolVersion;
Rehearsal = rehearsal;
Expand All @@ -47,9 +46,6 @@ public ActionContext(
/// <inheritdoc cref="IActionContext.Miner"/>
public Address Miner { get; }

/// <inheritdoc cref="IActionContext.SystemAccounts"/>
public ISystemAccounts SystemAccounts { get; }

/// <inheritdoc cref="IActionContext.BlockIndex"/>
public long BlockIndex { get; }

Expand Down
Loading

0 comments on commit e3734ca

Please sign in to comment.