Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
limebell committed Apr 25, 2024
1 parent cb147b7 commit cf150d6
Show file tree
Hide file tree
Showing 18 changed files with 159 additions and 38 deletions.
6 changes: 5 additions & 1 deletion Libplanet.Headless.Tests/Hosting/LibplanetNodeServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ public void Constructor()
stateStore);
var actionLoader = new SingleActionLoader(typeof(DummyAction));
var actionEvaluator = new ActionEvaluator(
_ => policy.BlockAction,
new PolicyActionsRegistry(
_ => policy.BeginBlockActions,
_ => policy.EndBlockActions,
_ => policy.BeginTxActions,
_ => policy.EndTxActions),
stateStore,
actionLoader);
var genesisBlock = BlockChain.ProposeGenesisBlock(actionEvaluator);
Expand Down
6 changes: 5 additions & 1 deletion Libplanet.Headless/Hosting/LibplanetNodeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,11 @@ IActionEvaluator BuildActionEvaluator(IActionEvaluatorConfiguration actionEvalua
actionLoader),
DefaultActionEvaluatorConfiguration _ =>
new ActionEvaluator(
_ => blockPolicy.BlockAction,
new PolicyActionsRegistry(
_ => blockPolicy.BeginBlockActions,
_ => blockPolicy.EndBlockActions,
_ => blockPolicy.BeginTxActions,
_ => blockPolicy.EndTxActions),
stateStore: StateStore,
actionTypeLoader: actionLoader),
ForkableActionEvaluatorConfiguration forkableActionEvaluatorConfiguration =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ public void Balance(StoreType storeType)
IStagePolicy stagePolicy = new VolatileStagePolicy();
IBlockPolicy blockPolicy = new BlockPolicySource().GetPolicy();
ActionEvaluator actionEvaluator = new ActionEvaluator(
_ => blockPolicy.BlockAction,
new PolicyActionsRegistry(
_ => blockPolicy.BeginBlockActions,
_ => blockPolicy.EndBlockActions,
_ => blockPolicy.BeginTxActions,
_ => blockPolicy.EndTxActions),
stateStore,
new NCActionLoader());
BlockChain chain = BlockChain.Create(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ public ChainCommandTest()
public void Tip(StoreType storeType)
{
var actionEvaluator = new ActionEvaluator(
_ => new BlockPolicy().BlockAction,
new PolicyActionsRegistry(
_ => new BlockPolicy().BeginBlockActions,
_ => new BlockPolicy().EndBlockActions,
_ => new BlockPolicy().BeginTxActions,
_ => new BlockPolicy().EndTxActions),
new TrieStateStore(new MemoryKeyValueStore()),
new NCActionLoader());
Block genesisBlock = BlockChain.ProposeGenesisBlock(actionEvaluator);
Expand Down Expand Up @@ -92,7 +96,11 @@ public void Inspect(StoreType storeType)
IStagePolicy stagePolicy = new VolatileStagePolicy();
IBlockPolicy blockPolicy = new BlockPolicySource().GetPolicy();
ActionEvaluator actionEvaluator = new ActionEvaluator(
_ => blockPolicy.BlockAction,
new PolicyActionsRegistry(
_ => blockPolicy.BeginBlockActions,
_ => blockPolicy.EndBlockActions,
_ => blockPolicy.BeginTxActions,
_ => blockPolicy.EndTxActions),
stateStore,
new NCActionLoader());
Block genesisBlock = BlockChain.ProposeGenesisBlock(
Expand Down Expand Up @@ -153,7 +161,11 @@ public void Truncate(StoreType storeType)
IStagePolicy stagePolicy = new VolatileStagePolicy();
IBlockPolicy blockPolicy = new BlockPolicySource().GetPolicy();
ActionEvaluator actionEvaluator = new ActionEvaluator(
_ => blockPolicy.BlockAction,
new PolicyActionsRegistry(
_ => blockPolicy.BeginBlockActions,
_ => blockPolicy.EndBlockActions,
_ => blockPolicy.BeginTxActions,
_ => blockPolicy.EndTxActions),
stateStore,
new NCActionLoader());
Block genesisBlock = BlockChain.ProposeGenesisBlock(
Expand Down Expand Up @@ -232,7 +244,11 @@ public void PruneState(StoreType storeType)
IStagePolicy stagePolicy = new VolatileStagePolicy();
IBlockPolicy blockPolicy = new BlockPolicySource().GetPolicy();
ActionEvaluator actionEvaluator = new ActionEvaluator(
_ => blockPolicy.BlockAction,
new PolicyActionsRegistry(
_ => blockPolicy.BeginBlockActions,
_ => blockPolicy.EndBlockActions,
_ => blockPolicy.BeginTxActions,
_ => blockPolicy.EndTxActions),
stateStore,
new NCActionLoader());
BlockChain chain = BlockChain.Create(
Expand Down Expand Up @@ -284,7 +300,11 @@ public void Snapshot(StoreType storeType)
IStagePolicy stagePolicy = new VolatileStagePolicy();
IBlockPolicy blockPolicy = new BlockPolicySource().GetPolicy();
ActionEvaluator actionEvaluator = new ActionEvaluator(
_ => blockPolicy.BlockAction,
new PolicyActionsRegistry(
_ => blockPolicy.BeginBlockActions,
_ => blockPolicy.EndBlockActions,
_ => blockPolicy.BeginTxActions,
_ => blockPolicy.EndTxActions),
stateStore,
new NCActionLoader());
BlockChain chain = BlockChain.Create(
Expand Down Expand Up @@ -445,6 +465,7 @@ private Block MineGenesisBlock()
block.Hash,
DateTimeOffset.UtcNow,
validator.PublicKey,
BigInteger.One,
VoteFlag.PreCommit).Sign(validator)))
: null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ public void GetGenesisBlock(StoreType storeType)
{
IStore store = storeType.CreateStore(_storePath);
IActionEvaluator actionEvaluator = new ActionEvaluator(
_ => new BlockPolicy().BlockAction,
new PolicyActionsRegistry(
_ => new BlockPolicy().BeginBlockActions,
_ => new BlockPolicy().EndBlockActions,
_ => new BlockPolicy().BeginTxActions,
_ => new BlockPolicy().EndTxActions),
new TrieStateStore(new MemoryKeyValueStore()),
new NCActionLoader());
Block genesisBlock = BlockChain.ProposeGenesisBlock(actionEvaluator);
Expand Down
12 changes: 10 additions & 2 deletions NineChronicles.Headless.Executable/Commands/ChainCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,11 @@ public void Inspect(
Block genesisBlock = store.GetBlock(gHash)!;
var blockChainStates = new BlockChainStates(store, stateStore);
var actionEvaluator = new ActionEvaluator(
_ => blockPolicy.BlockAction,
new PolicyActionsRegistry(
beginBlockActionsGetter: _ => blockPolicy.BeginBlockActions,
endBlockActionsGetter: _ => blockPolicy.EndBlockActions,
beginTxActionsGetter: _ => blockPolicy.BeginTxActions,
endTxActionsGetter: _ => blockPolicy.EndTxActions),
stateStore,
new NCActionLoader());
BlockChain chain = new BlockChain(
Expand Down Expand Up @@ -475,7 +479,11 @@ public void Snapshot(
new BlockPolicy();
var blockChainStates = new BlockChainStates(store, stateStore);
var actionEvaluator = new ActionEvaluator(
_ => blockPolicy.BlockAction,
new PolicyActionsRegistry(
beginBlockActionsGetter: _ => blockPolicy.BeginBlockActions,
endBlockActionsGetter: _ => blockPolicy.EndBlockActions,
beginTxActionsGetter: _ => blockPolicy.BeginTxActions,
endTxActionsGetter: _ => blockPolicy.EndTxActions),
stateStore,
new NCActionLoader()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Libplanet.Crypto;
using Libplanet.Action;
using Libplanet.Action.State;
using Libplanet.Types.Assets;
using Libplanet.Types.Blocks;
using Libplanet.Types.Tx;
using Serilog;
Expand All @@ -29,6 +30,8 @@ public ActionContext(
int blockProtocolVersion,
IWorld previousState,
int randomSeed,
bool isBlockAction,
FungibleAssetValue? maxGasPrice,
bool rehearsal = false)
{
Signer = signer;
Expand All @@ -39,6 +42,8 @@ public ActionContext(
Rehearsal = rehearsal;
PreviousState = previousState;
RandomSeed = randomSeed;
IsBlockAction = isBlockAction;
MaxGasPrice = maxGasPrice;
}

public Address Signer { get; }
Expand All @@ -59,7 +64,9 @@ public ActionContext(

public int RandomSeed { get; }

public bool BlockAction => TxId is null;
public bool IsBlockAction { get; }

public FungibleAssetValue? MaxGasPrice { get; }

public void UseGas(long gas)
{
Expand Down Expand Up @@ -96,6 +103,8 @@ private static IEnumerable<ActionEvaluation> EvaluateActions(
Address signer,
byte[] signature,
IImmutableList<IAction> actions,
bool isBlockAction,
FungibleAssetValue? maxGasPrice,
ILogger? logger = null)
{
ActionContext CreateActionContext(
Expand All @@ -109,7 +118,9 @@ ActionContext CreateActionContext(
blockIndex: blockIndex,
blockProtocolVersion: blockProtocolVersion,
previousState: prevState,
randomSeed: randomSeed);
randomSeed: randomSeed,
isBlockAction: isBlockAction,
maxGasPrice: maxGasPrice);
}

byte[] preEvaluationHashBytes = preEvaluationHash.ToByteArray();
Expand Down
21 changes: 16 additions & 5 deletions NineChronicles.Headless.Executable/Commands/ReplayCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@ public int Tx(
miner: targetBlock.Miner,
signer: tx.Signer,
signature: tx.Signature,
actions: actions.Cast<IAction>().ToImmutableList()
);
actions: actions.Cast<IAction>().ToImmutableList(),
isBlockAction: false,
maxGasPrice: tx.MaxGasPrice);
var actionNum = 1;
foreach (var actionEvaluation in actionEvaluations)
{
Expand Down Expand Up @@ -405,7 +406,9 @@ public int RemoteTx(
miner: miner,
signer: transaction.Signer,
signature: transaction.Signature,
actions: actions);
actions: actions,
isBlockAction: true,
maxGasPrice: transaction.MaxGasPrice);

actionEvaluations
.Select((evaluation, index) => (evaluation, index))
Expand Down Expand Up @@ -473,7 +476,11 @@ private static (FileStream? fs, StreamWriter? sw) GetOutputFileStream(
var stateStore = new TrieStateStore(stateKeyValueStore);
var blockChainStates = new BlockChainStates(store, stateStore);
var actionEvaluator = new ActionEvaluator(
_ => policy.BlockAction,
new PolicyActionsRegistry(
beginBlockActionsGetter: _ => policy.BeginBlockActions,
endBlockActionsGetter: _ => policy.EndBlockActions,
beginTxActionsGetter: _ => policy.BeginTxActions,
endTxActionsGetter: _ => policy.EndTxActions),
stateStore,
new NCActionLoader());
return (
Expand Down Expand Up @@ -520,7 +527,11 @@ private ActionEvaluator GetActionEvaluator(IStateStore stateStore)
var policy = new BlockPolicySource().GetPolicy();
IActionLoader actionLoader = new NCActionLoader();
return new ActionEvaluator(
_ => policy.BlockAction,
new PolicyActionsRegistry(
beginBlockActionsGetter: _ => policy.BeginBlockActions,
endBlockActionsGetter: _ => policy.EndBlockActions,
beginTxActionsGetter: _ => policy.BeginTxActions,
endTxActionsGetter: _ => policy.EndTxActions),
stateStore: stateStore,
actionTypeLoader: actionLoader);
}
Expand Down
6 changes: 5 additions & 1 deletion NineChronicles.Headless.Executable/Commands/StateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,11 @@ IStateStore stateStore
new MemoryStore(),
sStore);
var actionEvaluator = new ActionEvaluator(
_ => policy.BlockAction,
new PolicyActionsRegistry(
beginBlockActionsGetter: _ => policy.BeginBlockActions,
endBlockActionsGetter: _ => policy.EndBlockActions,
beginTxActionsGetter: _ => policy.BeginTxActions,
endTxActionsGetter: _ => policy.EndTxActions),
sStore,
new NCActionLoader());

Expand Down
3 changes: 3 additions & 0 deletions NineChronicles.Headless.Tests/Common/MockAccount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ public IAccount BurnAsset(
public IAccount SetValidator(Validator validator) =>
UpdateValidatorSet(GetValidatorSet().Update(validator));

public IAccount SetValidatorSet(ValidatorSet validatorSet) =>
UpdateValidatorSet(validatorSet);

[Pure]
private MockAccount UpdateState(
Address address,
Expand Down
12 changes: 10 additions & 2 deletions NineChronicles.Headless.Tests/GraphQLTestUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ public static StandaloneContext CreateStandaloneContext()
var stateStore = new TrieStateStore(new DefaultKeyValueStore(null));
var policy = new BlockPolicy();
var actionEvaluator = new ActionEvaluator(
_ => policy.BlockAction,
new PolicyActionsRegistry(
_ => policy.BeginBlockActions,
_ => policy.EndBlockActions,
_ => policy.BeginTxActions,
_ => policy.EndTxActions),
stateStore,
new NCActionLoader());
var genesisBlock = BlockChain.ProposeGenesisBlock(actionEvaluator);
Expand Down Expand Up @@ -114,7 +118,11 @@ PrivateKey minerPrivateKey
var stateStore = new TrieStateStore(new DefaultKeyValueStore(null));
var policy = new BlockPolicy();
var actionEvaluator = new ActionEvaluator(
_ => policy.BlockAction,
new PolicyActionsRegistry(
_ => policy.BeginBlockActions,
_ => policy.EndBlockActions,
_ => policy.BeginTxActions,
_ => policy.EndTxActions),
stateStore,
new NCActionLoader());
var genesisBlock = BlockChain.ProposeGenesisBlock(
Expand Down
8 changes: 6 additions & 2 deletions NineChronicles.Headless.Tests/GraphTypes/GraphQLTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,12 @@ public GraphQLTestBase(ITestOutputHelper output)
#pragma warning restore CS0618

var sheets = TableSheetsImporter.ImportSheets();
var blockAction = new PoSAction();
var actionEvaluator = new ActionEvaluator(
_ => blockAction,
new PolicyActionsRegistry(
_ => new DebugPolicy().BeginBlockActions,
_ => new DebugPolicy().EndBlockActions,
_ => new DebugPolicy().BeginTxActions,
_ => new DebugPolicy().EndTxActions),
new TrieStateStore(new MemoryKeyValueStore()),
new NCActionLoader());
var genesisBlock = BlockChain.ProposeGenesisBlock(
Expand Down Expand Up @@ -251,6 +254,7 @@ protected LibplanetNodeService CreateLibplanetNodeService(
hash,
DateTimeOffset.UtcNow,
validator.PublicKey,
BigInteger.One,
VoteFlag.PreCommit).Sign(validator)).ToImmutableArray())
: (BlockCommit?)null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,11 @@ private Block MakeGenesisBlock(
RankingState0? rankingState = null)
{
var actionEvaluator = new ActionEvaluator(
_ => ServiceBuilder.BlockPolicy.BlockAction,
new PolicyActionsRegistry(
_ => ServiceBuilder.BlockPolicy.BeginBlockActions,
_ => ServiceBuilder.BlockPolicy.EndBlockActions,
_ => ServiceBuilder.BlockPolicy.BeginTxActions,
_ => ServiceBuilder.BlockPolicy.EndTxActions),
new TrieStateStore(new MemoryKeyValueStore()),
new NCActionLoader());
return BlockChain.ProposeGenesisBlock(
Expand Down
Loading

0 comments on commit cf150d6

Please sign in to comment.