diff --git a/.Lib9c.Benchmarks/Program.cs b/.Lib9c.Benchmarks/Program.cs index b8a4cf1a78..c1a01a6f0c 100644 --- a/.Lib9c.Benchmarks/Program.cs +++ b/.Lib9c.Benchmarks/Program.cs @@ -89,8 +89,7 @@ static void Main(string[] args) var actionEvaluator = new ActionEvaluator( _ => policy.BlockAction, new BlockChainStates(store, stateStore), - new NCActionLoader(), - null); + new NCActionLoader()); var chain = new BlockChain( policy, stagePolicy, diff --git a/.Lib9c.Tests/Action/ActionContext.cs b/.Lib9c.Tests/Action/ActionContext.cs index 06ee898669..af7110a568 100644 --- a/.Lib9c.Tests/Action/ActionContext.cs +++ b/.Lib9c.Tests/Action/ActionContext.cs @@ -64,9 +64,5 @@ public IActionContext GetUnconsumedContext() public long GasUsed() => _gasUsed; public long GasLimit() => 0; - - public void PutLog(string log) - { - } } } diff --git a/.Lib9c.Tests/Action/Factory/ClaimStakeRewardFactoryTest.cs b/.Lib9c.Tests/Action/Factory/ClaimStakeRewardFactoryTest.cs index dc963525a6..2bdd67ed43 100644 --- a/.Lib9c.Tests/Action/Factory/ClaimStakeRewardFactoryTest.cs +++ b/.Lib9c.Tests/Action/Factory/ClaimStakeRewardFactoryTest.cs @@ -22,17 +22,14 @@ public static IEnumerable GetAllClaimStakeRewardV1() var arr = Assembly.GetAssembly(typeof(ClaimRaidReward))?.GetTypes() .Where(type => type.IsClass && - type.GetInterfaces().Contains(typeof(IClaimStakeRewardV1))) - .Select(ActionTypeAttribute.ValueOf) - .ToArray() ?? Array.Empty(); + typeof(IClaimStakeRewardV1).IsAssignableFrom(type)) + .Select(type => + type.GetCustomAttribute()?.TypeIdentifier) + .OfType() + .ToArray() ?? Array.Empty(); foreach (var value in arr) { - if (value is null) - { - continue; - } - var str = (string)(Text)value; var verStr = str.Replace("claim_stake_reward", string.Empty); var ver = string.IsNullOrEmpty(verStr) diff --git a/.Lib9c.Tests/Action/MockStateDelta.cs b/.Lib9c.Tests/Action/MockStateDelta.cs index f8e86e8793..0a984cafa4 100644 --- a/.Lib9c.Tests/Action/MockStateDelta.cs +++ b/.Lib9c.Tests/Action/MockStateDelta.cs @@ -16,57 +16,28 @@ namespace Lib9c.Tests.Action using Libplanet.State; /// - /// /// A rough replica of https://github.com/planetarium/libplanet/blob/main/Libplanet/State/AccountStateDelta.cs - /// except this has its constructors exposed as public for testing with many of - /// checks removed. - /// - /// - /// Notable differences from the original are: - /// - /// - /// There is no authority check for and , - /// i.e. any can mint and burn. - /// - /// - /// There is no amount check for , , - /// i.e. 0 or even a negative amount is allowed. - /// - /// - /// The behaves as if any given - /// has value equal to 0. - /// - /// - /// + /// except this has its constructors exposed as public for testing. /// [Pure] public class MockStateDelta : IAccountStateDelta { + private readonly IAccountState _baseState; + public MockStateDelta() : this(MockState.Empty) { } - public MockStateDelta(IAccountState mockState) - : this( - mockState.GetStates, - mockState.GetBalance, - mockState.GetTotalSupply, - mockState.GetValidatorSet) + public MockStateDelta(IAccountState baseState) + : this(baseState, new MockDelta()) { } - private MockStateDelta( - AccountStateGetter accountStateGetter, - AccountBalanceGetter accountBalanceGetter, - TotalSupplyGetter totalSupplyGetter, - ValidatorSetGetter validatorSetGetter) + private MockStateDelta(IAccountState baseState, IAccountDelta delta) { - Delta = new MockDelta(); - StateGetter = accountStateGetter; - BalanceGetter = accountBalanceGetter; - TotalSupplyGetter = totalSupplyGetter; - ValidatorSetGetter = validatorSetGetter; + _baseState = baseState; + Delta = delta; TotalUpdatedFungibles = ImmutableDictionary<(Address, Currency), BigInteger>.Empty; } @@ -78,15 +49,7 @@ private MockStateDelta( TotalUpdatedFungibles.Keys.ToImmutableHashSet(); public IImmutableDictionary<(Address, Currency), BigInteger> TotalUpdatedFungibles - { get; protected set; } - - private AccountStateGetter StateGetter { get; set; } - - private AccountBalanceGetter BalanceGetter { get; set; } - - private TotalSupplyGetter TotalSupplyGetter { get; set; } - - private ValidatorSetGetter ValidatorSetGetter { get; set; } + { get; private set; } /// [Pure] @@ -118,7 +81,7 @@ private MockStateDelta( if (notFoundIndices.Count > 0) { - IReadOnlyList restValues = StateGetter( + IReadOnlyList restValues = _baseState.GetStates( notFoundIndices.Select(index => addresses[index]).ToArray()); foreach ((var v, var i) in notFoundIndices.Select((v, i) => (v, i))) { @@ -158,13 +121,13 @@ public FungibleAssetValue GetTotalSupply(Currency currency) return FungibleAssetValue.FromRawValue(currency, totalSupplyValue); } - return TotalSupplyGetter(currency); + return _baseState.GetTotalSupply(currency); } /// [Pure] public ValidatorSet GetValidatorSet() => - Delta.ValidatorSet ?? ValidatorSetGetter(); + Delta.ValidatorSet ?? _baseState.GetValidatorSet(); /// [Pure] @@ -293,28 +256,24 @@ private FungibleAssetValue GetBalance( IImmutableDictionary<(Address, Currency), BigInteger> balances) => balances.TryGetValue((address, currency), out BigInteger balance) ? FungibleAssetValue.FromRawValue(currency, balance) - : BalanceGetter(address, currency); + : _baseState.GetBalance(address, currency); [Pure] - private IAccountStateDelta UpdateStates( - IImmutableDictionary updatedStates - ) => + private MockStateDelta UpdateStates( + IImmutableDictionary updatedStates) => new MockStateDelta( - StateGetter, - BalanceGetter, - TotalSupplyGetter, - ValidatorSetGetter) - { - Delta = new MockDelta( + _baseState, + new MockDelta( updatedStates, Delta.Fungibles, Delta.TotalSupplies, - Delta.ValidatorSet), + Delta.ValidatorSet)) + { TotalUpdatedFungibles = TotalUpdatedFungibles, }; [Pure] - private IAccountStateDelta UpdateFungibleAssets( + private MockStateDelta UpdateFungibleAssets( IImmutableDictionary<(Address, Currency), BigInteger> updatedFungibleAssets, IImmutableDictionary<(Address, Currency), BigInteger> totalUpdatedFungibles ) => @@ -324,40 +283,33 @@ private IAccountStateDelta UpdateFungibleAssets( Delta.TotalSupplies); [Pure] - private IAccountStateDelta UpdateFungibleAssets( + private MockStateDelta UpdateFungibleAssets( IImmutableDictionary<(Address, Currency), BigInteger> updatedFungibleAssets, IImmutableDictionary<(Address, Currency), BigInteger> totalUpdatedFungibles, IImmutableDictionary updatedTotalSupply ) => new MockStateDelta( - StateGetter, - BalanceGetter, - TotalSupplyGetter, - ValidatorSetGetter) - { - Delta = new MockDelta( + _baseState, + new MockDelta( Delta.States, updatedFungibleAssets, updatedTotalSupply, - Delta.ValidatorSet), + Delta.ValidatorSet)) + { TotalUpdatedFungibles = totalUpdatedFungibles, }; [Pure] - private IAccountStateDelta UpdateValidatorSet( - ValidatorSet updatedValidatorSet - ) => + private MockStateDelta UpdateValidatorSet( + ValidatorSet updatedValidatorSet) => new MockStateDelta( - StateGetter, - BalanceGetter, - TotalSupplyGetter, - ValidatorSetGetter) - { - Delta = new MockDelta( + _baseState, + new MockDelta( Delta.States, Delta.Fungibles, Delta.TotalSupplies, - updatedValidatorSet), + updatedValidatorSet)) + { TotalUpdatedFungibles = TotalUpdatedFungibles, }; diff --git a/.Lib9c.Tests/Action/RewardGoldTest.cs b/.Lib9c.Tests/Action/RewardGoldTest.cs index c0635c4d14..608fff9875 100644 --- a/.Lib9c.Tests/Action/RewardGoldTest.cs +++ b/.Lib9c.Tests/Action/RewardGoldTest.cs @@ -530,8 +530,7 @@ public async Task Genesis_StateRootHash(bool mainnet) blockChainStates: new BlockChainStates( new MemoryStore(), new TrieStateStore(new MemoryKeyValueStore())), - actionTypeLoader: new NCActionLoader(), - feeCalculator: null); + actionTypeLoader: new NCActionLoader()); genesis = BlockChain.ProposeGenesisBlock( tempActionEvaluator, transactions: ImmutableList.Empty @@ -554,8 +553,7 @@ public async Task Genesis_StateRootHash(bool mainnet) actionEvaluator: new ActionEvaluator( policyBlockActionGetter: _ => policy.BlockAction, blockChainStates: new BlockChainStates(store, stateStore), - actionTypeLoader: new NCActionLoader(), - feeCalculator: null + actionTypeLoader: new NCActionLoader() ), renderers: blockPolicySource.GetRenderers() ); diff --git a/.Lib9c.Tests/Policy/BlockPolicyTest.cs b/.Lib9c.Tests/Policy/BlockPolicyTest.cs index 49e5be0c99..0e01086332 100644 --- a/.Lib9c.Tests/Policy/BlockPolicyTest.cs +++ b/.Lib9c.Tests/Policy/BlockPolicyTest.cs @@ -66,8 +66,7 @@ public void ValidateNextBlockTx() new ActionEvaluator( policyBlockActionGetter: _ => policy.BlockAction, blockChainStates: new BlockChainStates(store, stateStore), - actionTypeLoader: new NCActionLoader(), - feeCalculator: null + actionTypeLoader: new NCActionLoader() ), renderers: new[] { blockPolicySource.BlockRenderer } ); @@ -177,8 +176,7 @@ public void ValidateNextBlockTx_Mead() new ActionEvaluator( policyBlockActionGetter: _ => policy.BlockAction, blockChainStates: new BlockChainStates(store, stateStore), - actionTypeLoader: new NCActionLoader(), - feeCalculator: null + actionTypeLoader: new NCActionLoader() ), renderers: new[] { blockPolicySource.BlockRenderer } ); @@ -266,8 +264,7 @@ public void BlockCommitFromNonValidator() new ActionEvaluator( policyBlockActionGetter: _ => policy.BlockAction, blockChainStates: new BlockChainStates(store, stateStore), - actionTypeLoader: new NCActionLoader(), - feeCalculator: null + actionTypeLoader: new NCActionLoader() ), renderers: new[] { blockPolicySource.BlockRenderer } ); @@ -321,8 +318,7 @@ public void MustNotIncludeBlockActionAtTransaction() new ActionEvaluator( policyBlockActionGetter: _ => policy.BlockAction, blockChainStates: new BlockChainStates(store, stateStore), - actionTypeLoader: actionLoader, - feeCalculator: null + actionTypeLoader: actionLoader ), renderers: new[] { blockPolicySource.BlockRenderer } ); @@ -375,8 +371,7 @@ public void EarnMiningGoldWhenSuccessMining() new ActionEvaluator( policyBlockActionGetter: _ => policy.BlockAction, blockChainStates: new BlockChainStates(store, stateStore), - actionTypeLoader: new NCActionLoader(), - feeCalculator: null + actionTypeLoader: new NCActionLoader() ), renderers: new[] { blockPolicySource.BlockRenderer } ); @@ -425,8 +420,7 @@ public void ValidateNextBlockWithManyTransactions() new ActionEvaluator( policyBlockActionGetter: _ => policy.BlockAction, blockChainStates: new BlockChainStates(store, stateStore), - actionTypeLoader: new NCActionLoader(), - feeCalculator: null + actionTypeLoader: new NCActionLoader() ) ); @@ -527,8 +521,7 @@ public void ValidateNextBlockWithManyTransactionsPerSigner() new ActionEvaluator( policyBlockActionGetter: _ => policy.BlockAction, blockChainStates: new BlockChainStates(store, stateStore), - actionTypeLoader: new NCActionLoader(), - feeCalculator: null + actionTypeLoader: new NCActionLoader() ) ); diff --git a/.Lib9c.Tests/TestHelper/BlockChainHelper.cs b/.Lib9c.Tests/TestHelper/BlockChainHelper.cs index b5e8a8b530..b43164264d 100644 --- a/.Lib9c.Tests/TestHelper/BlockChainHelper.cs +++ b/.Lib9c.Tests/TestHelper/BlockChainHelper.cs @@ -48,8 +48,7 @@ public static BlockChain MakeBlockChain( new ActionEvaluator( policyBlockActionGetter: _ => policy.BlockAction, blockChainStates: new BlockChainStates(store, stateStore), - actionTypeLoader: new NCActionLoader(), - feeCalculator: null + actionTypeLoader: new NCActionLoader() ), renderers: blockRenderers); } diff --git a/.Lib9c.Tools/SubCommand/State.cs b/.Lib9c.Tools/SubCommand/State.cs index ac52b815dd..68ae873adb 100644 --- a/.Lib9c.Tools/SubCommand/State.cs +++ b/.Lib9c.Tools/SubCommand/State.cs @@ -120,8 +120,7 @@ IStateStore stateStore var actionEvaluator = new ActionEvaluator( _ => policy.BlockAction, new BlockChainStates(store, stateStore), - actionLoader, - null); + actionLoader); HashDigest stateRootHash = block.Index < 1 ? BlockChain.DetermineGenesisStateRootHash( actionEvaluator, diff --git a/Lib9c.DevExtensions/Utils.cs b/Lib9c.DevExtensions/Utils.cs index 4cb2c01323..8024cd0a3d 100644 --- a/Lib9c.DevExtensions/Utils.cs +++ b/Lib9c.DevExtensions/Utils.cs @@ -88,8 +88,7 @@ Guid chainIdValue ActionEvaluator actionEvaluator = new ActionEvaluator( _ => policy.BlockAction, blockChainStates, - actionLoader, - null); + actionLoader); BlockChain chain; if (store.GetCanonicalChainId() is null) diff --git a/Lib9c.MessagePack/Formatters/NCActionFormatter.cs b/Lib9c.MessagePack/Formatters/NCActionFormatter.cs index 0eb5d8967d..629838a6d2 100644 --- a/Lib9c.MessagePack/Formatters/NCActionFormatter.cs +++ b/Lib9c.MessagePack/Formatters/NCActionFormatter.cs @@ -18,15 +18,6 @@ public class NCActionFormatter : IMessagePackFormatter { private readonly IActionLoader _actionLoader; - private static readonly IDictionary Types = typeof(ActionBase) - .Assembly - .GetTypes() - .Where(t => t.IsDefined(typeof(ActionTypeAttribute))) - .ToDictionary( - t => ActionTypeAttribute.ValueOf(t) - ?? throw new InvalidOperationException("Unreachable code."), - t => t); - public NCActionFormatter() { _actionLoader = new NCActionLoader(); diff --git a/Lib9c.Policy/Policy/DebugPolicy.cs b/Lib9c.Policy/Policy/DebugPolicy.cs index df4433fa0b..0ef3d96a53 100644 --- a/Lib9c.Policy/Policy/DebugPolicy.cs +++ b/Lib9c.Policy/Policy/DebugPolicy.cs @@ -20,8 +20,6 @@ public DebugPolicy() public IAction BlockAction { get; } = new RewardGold(); - public IFeeCalculator? FeeCalculator { get; } - public TxPolicyViolationException ValidateNextBlockTx( BlockChain blockChain, Transaction transaction) { diff --git a/Lib9c.Utils/BlockHelper.cs b/Lib9c.Utils/BlockHelper.cs index a4d5c1d3f7..11b444ef30 100644 --- a/Lib9c.Utils/BlockHelper.cs +++ b/Lib9c.Utils/BlockHelper.cs @@ -102,8 +102,7 @@ public static Block ProposeGenesisBlock( var actionEvaluator = new ActionEvaluator( _ => blockAction, new BlockChainStates(new MemoryStore(), new TrieStateStore(new MemoryKeyValueStore())), - actionLoader, - null); + actionLoader); return BlockChain.ProposeGenesisBlock( actionEvaluator, diff --git a/Lib9c/Action/ActionBaseExtensions.cs b/Lib9c/Action/ActionBaseExtensions.cs index 528ee53c18..665b81cce1 100644 --- a/Lib9c/Action/ActionBaseExtensions.cs +++ b/Lib9c/Action/ActionBaseExtensions.cs @@ -71,11 +71,6 @@ public void UseGas(long gas) public long GasUsed() => 0; public long GasLimit() => 0; - - public void PutLog(string log) - { - // Method intentionally left empty. - } } private class AddressTraceStateDelta : IAccountStateDelta diff --git a/Lib9c/FeeCalculator.cs b/Lib9c/FeeCalculator.cs deleted file mode 100644 index 76c4ea2280..0000000000 --- a/Lib9c/FeeCalculator.cs +++ /dev/null @@ -1,14 +0,0 @@ -using Lib9c; -using Libplanet.Action; -using Libplanet.Assets; - -namespace Nekoyume -{ - public class FeeCalculator : IFeeCalculator - { - public FungibleAssetValue CalculateFee(IAction action) - { - return 1 * Currencies.Mead; - } - } -}