Skip to content

Commit

Permalink
Merge pull request #3337 from OnedgeLee/feature/world-state
Browse files Browse the repository at this point in the history
Rename `IAccountStateDelta` as `IAccount`
  • Loading branch information
greymistcube authored Jul 31, 2023
2 parents 57dea63 + a831b2b commit 62860a3
Show file tree
Hide file tree
Showing 57 changed files with 303 additions and 298 deletions.
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ To be released.

### Backward-incompatible API changes

- (Libplanet.Action) Renamed `IAccountStateDelta` as `IAccount`.
[[#3337]]

### Backward-incompatible network protocol changes

### Backward-incompatible storage format changes
Expand All @@ -24,6 +27,8 @@ To be released.

### CLI tools

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


Version 3.1.0
-------------
Expand Down
12 changes: 6 additions & 6 deletions Libplanet.Action.Tests/ActionContextTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void RandomShouldBeDeterministic()
miner: _address,
blockIndex: 1,
blockProtocolVersion: Block.CurrentProtocolVersion,
previousState: AccountStateDelta.Create(MockAccountState.Empty),
previousState: Account.Create(MockAccountState.Empty),
randomSeed: seed,
gasLimit: 0
);
Expand All @@ -54,7 +54,7 @@ public void GuidShouldBeDeterministic()
miner: _address,
blockIndex: 1,
blockProtocolVersion: Block.CurrentProtocolVersion,
previousState: AccountStateDelta.Create(MockAccountState.Empty),
previousState: Account.Create(MockAccountState.Empty),
randomSeed: 0,
gasLimit: 0
);
Expand All @@ -65,7 +65,7 @@ public void GuidShouldBeDeterministic()
miner: _address,
blockIndex: 1,
blockProtocolVersion: Block.CurrentProtocolVersion,
previousState: AccountStateDelta.Create(MockAccountState.Empty),
previousState: Account.Create(MockAccountState.Empty),
randomSeed: 0,
gasLimit: 0
);
Expand All @@ -76,7 +76,7 @@ public void GuidShouldBeDeterministic()
miner: _address,
blockIndex: 1,
blockProtocolVersion: Block.CurrentProtocolVersion,
previousState: AccountStateDelta.Create(MockAccountState.Empty),
previousState: Account.Create(MockAccountState.Empty),
randomSeed: 1,
gasLimit: 0
);
Expand Down Expand Up @@ -112,7 +112,7 @@ public void GuidVersionAndVariant()
miner: _address,
blockIndex: 1,
blockProtocolVersion: Block.CurrentProtocolVersion,
previousState: AccountStateDelta.Create(MockAccountState.Empty),
previousState: Account.Create(MockAccountState.Empty),
randomSeed: i,
gasLimit: 0
);
Expand All @@ -132,7 +132,7 @@ public void GetUnconsumedContext()
miner: _address,
blockIndex: 1,
blockProtocolVersion: Block.CurrentProtocolVersion,
previousState: AccountStateDelta.Create(MockAccountState.Empty),
previousState: Account.Create(MockAccountState.Empty),
randomSeed: _random.Next(),
gasLimit: 0);

Expand Down
4 changes: 2 additions & 2 deletions Libplanet.Action.Tests/ActionEvaluationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ public void Constructor()
address,
1,
Block.CurrentProtocolVersion,
AccountStateDelta.Create(MockAccountState.Empty),
Account.Create(MockAccountState.Empty),
123,
0,
false
),
AccountStateDelta.Create(
Account.Create(
MockAccountState.Empty
.SetState(address, (Text)"item"))
);
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 @@ -29,11 +29,11 @@ public override void LoadPlainValue(IValue plainValue)
TargetAddress = new Address(values["target_address"]);
}

public override IAccountStateDelta Execute(IActionContext context)
public override IAccount Execute(IActionContext context)
{
IImmutableSet<string> usedWeapons = ImmutableHashSet<string>.Empty;
IImmutableSet<string> targets = ImmutableHashSet<string>.Empty;
IAccountStateDelta previousState = context.PreviousState;
IAccount previousState = context.PreviousState;

object value = previousState.GetState(TargetAddress);
if (!ReferenceEquals(value, null))
Expand Down
2 changes: 1 addition & 1 deletion Libplanet.Action.Tests/Common/BaseAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public abstract class BaseAction : IAction

public abstract IValue PlainValue { get; }

public abstract IAccountStateDelta Execute(IActionContext context);
public abstract IAccount Execute(IActionContext context);

public abstract void LoadPlainValue(IValue plainValue);

Expand Down
2 changes: 1 addition & 1 deletion Libplanet.Action.Tests/Common/DelayAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public IValue PlainValue
}
}

public IAccountStateDelta Execute(IActionContext context)
public IAccount Execute(IActionContext context)
{
var state = context.PreviousState;
var started = DateTimeOffset.UtcNow;
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 @@ -22,9 +22,9 @@ public override void LoadPlainValue(IValue plainValue)
TargetAddress = new Address(values["target_address"]);
}

public override IAccountStateDelta Execute(IActionContext context)
public override IAccount Execute(IActionContext context)
{
IAccountStateDelta previousState = context.PreviousState;
IAccount previousState = context.PreviousState;
ResultState = context.Rehearsal;
return previousState.SetState(
TargetAddress,
Expand Down
6 changes: 3 additions & 3 deletions Libplanet.Action.Tests/Common/DumbAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public IValue PlainValue
}
}

public IAccountStateDelta Execute(IActionContext context)
public IAccount Execute(IActionContext context)
{
if (RehearsalRecords.Value is null)
{
Expand All @@ -144,7 +144,7 @@ public IAccountStateDelta Execute(IActionContext context)
RehearsalRecords.Value.Add((TargetAddress, Item));
}

IAccountStateDelta states = context.PreviousState;
IAccount states = context.PreviousState;
if (Item is null)
{
return states;
Expand Down Expand Up @@ -187,7 +187,7 @@ public IAccountStateDelta Execute(IActionContext context)
Item = Item.ToUpperInvariant();
}

IAccountStateDelta nextState = states.SetState(TargetAddress, (Text)items);
IAccount nextState = states.SetState(TargetAddress, (Text)items);

if (!(Transfer is null))
{
Expand Down
2 changes: 1 addition & 1 deletion Libplanet.Action.Tests/Common/ExecuteRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public struct ExecuteRecord
{
public IAction Action { get; set; }

public IAccountStateDelta NextState { get; set; }
public IAccount NextState { get; set; }

public bool Rehearsal { get; set; }

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 @@ -36,9 +36,9 @@ public void LoadPlainValue(Dictionary plainValue)
Reward = plainValue.GetValue<Integer>("reward");
}

public IAccountStateDelta Execute(IActionContext ctx)
public IAccount Execute(IActionContext ctx)
{
IAccountStateDelta states = ctx.PreviousState;
IAccount states = ctx.PreviousState;

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

Expand Down
4 changes: 2 additions & 2 deletions Libplanet.Action.Tests/Common/RandomAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ public void LoadPlainValue(IValue plainValue)
Address = new Address((string)dictionary.GetValue<Text>("address"));
}

public IAccountStateDelta Execute(IActionContext context)
public IAccount Execute(IActionContext context)
{
IAccountStateDelta states = context.PreviousState;
IAccount states = context.PreviousState;
if (context.Rehearsal)
{
return states.SetState(Address, Null.Value);
Expand Down
4 changes: 2 additions & 2 deletions Libplanet.Action.Tests/Common/SetStatesAtBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ public void LoadPlainValue(IValue plainValue)
_blockIndex = dict.GetValue<Bencodex.Types.Integer>("block_index");
}

public IAccountStateDelta Execute(IActionContext context)
public IAccount Execute(IActionContext context)
{
IAccountStateDelta states = context.PreviousState;
IAccount states = context.PreviousState;
if (context.BlockIndex == _blockIndex)
{
states = states.SetState(_address, _value);
Expand Down
2 changes: 1 addition & 1 deletion Libplanet.Action.Tests/Common/SetValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void LoadPlainValue(IValue plainValue)
}

/// <inheritdoc cref="IAction.Execute(IActionContext)"/>
public IAccountStateDelta Execute(IActionContext context)
public IAccount Execute(IActionContext context)
{
return context.PreviousState.SetValidator(Validator);
}
Expand Down
2 changes: 1 addition & 1 deletion Libplanet.Action.Tests/Common/Sleep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class Sleep : BaseAction
.Add("values", Dictionary.Empty
.Add("zone_id", ZoneId));

public override IAccountStateDelta Execute(IActionContext context)
public override IAccount Execute(IActionContext context)
{
// No-op.
return context.PreviousState;
Expand Down
2 changes: 1 addition & 1 deletion Libplanet.Action.Tests/Common/ThrowException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void LoadPlainValue(Dictionary plainValue)
Deterministic = plainValue.GetValue<Boolean>("deterministic");
}

public IAccountStateDelta Execute(IActionContext context)
public IAccount Execute(IActionContext context)
{
if (context.Rehearsal ? ThrowOnRehearsal : ThrowOnExecution)
{
Expand Down
4 changes: 2 additions & 2 deletions Libplanet.Action.Tests/Sys/InitializeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void Execute()
{
var random = new System.Random();
Address signer = random.NextAddress();
var prevState = AccountStateDelta.Create(MockAccountState.Empty);
var prevState = Account.Create(MockAccountState.Empty);
BlockHash genesisHash = random.NextBlockHash();
var context = new ActionContext(
signer: signer,
Expand Down Expand Up @@ -70,7 +70,7 @@ public void ExecuteInNonGenesis()
{
var random = new System.Random();
Address signer = random.NextAddress();
var prevState = AccountStateDelta.Create(MockAccountState.Empty);
var prevState = Account.Create(MockAccountState.Empty);
BlockHash genesisHash = random.NextBlockHash();
var context = new ActionContext(
signer: signer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Libplanet.Action
{
public static class AccountStateDeltaMetrics
public static class AccountMetrics
{
public static readonly AsyncLocal<Stopwatch> GetStateTimer = new AsyncLocal<Stopwatch>();
public static readonly AsyncLocal<int> GetStateCount = new AsyncLocal<int>();
Expand Down
4 changes: 2 additions & 2 deletions Libplanet.Action/ActionContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public ActionContext(
Address miner,
long blockIndex,
int blockProtocolVersion,
IAccountStateDelta previousState,
IAccount previousState,
int randomSeed,
long gasLimit,
bool rehearsal = false)
Expand Down Expand Up @@ -58,7 +58,7 @@ public ActionContext(
public bool Rehearsal { get; }

/// <inheritdoc cref="IActionContext.PreviousState"/>
public IAccountStateDelta PreviousState { get; }
public IAccount PreviousState { get; }

/// <inheritdoc cref="IActionContext.Random"/>
public IRandom Random { get; }
Expand Down
4 changes: 2 additions & 2 deletions Libplanet.Action/ActionEvaluation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class ActionEvaluation : IActionEvaluation
public ActionEvaluation(
IAction action,
IActionContext inputContext,
IAccountStateDelta outputState,
IAccount outputState,
Exception? exception = null)
{
Action = action;
Expand All @@ -51,7 +51,7 @@ public ActionEvaluation(
/// <summary>
/// The result states that <see cref="Action"/> makes.
/// </summary>
public IAccountStateDelta OutputState { get; }
public IAccount OutputState { get; }

/// <summary>
/// An exception that had risen during evaluation.
Expand Down
Loading

0 comments on commit 62860a3

Please sign in to comment.