Skip to content

Commit

Permalink
Merge pull request #2270 from greymistcube/bump/libplanet-to-3.6.0
Browse files Browse the repository at this point in the history
⬆️ Bump libplanet to 3.6.0
  • Loading branch information
greymistcube authored Oct 16, 2023
2 parents 94dfb96 + ea34b9c commit 55b232e
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 48 deletions.
2 changes: 1 addition & 1 deletion Lib9c
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@
using Libplanet.Types.Blocks;
using Libplanet.Common;
using Libplanet.Crypto;
using Libplanet.Extensions.ActionEvaluatorCommonComponents;
using Libplanet.Types.Tx;
using ActionEvaluation = Libplanet.Extensions.ActionEvaluatorCommonComponents.ActionEvaluation;
using ArgumentOutOfRangeException = System.ArgumentOutOfRangeException;
using Random = Libplanet.Extensions.ActionEvaluatorCommonComponents.Random;

namespace Libplanet.Extensions.ForkableActionEvaluator.Tests;

Expand Down Expand Up @@ -64,53 +61,47 @@ public void CheckPairs()
class PostActionEvaluator : IActionEvaluator
{
public IActionLoader ActionLoader => throw new NotSupportedException();
public IReadOnlyList<IActionEvaluation> Evaluate(IPreEvaluationBlock block, HashDigest<SHA256>? baseStateroothash)
public IReadOnlyList<ICommittedActionEvaluation> Evaluate(IPreEvaluationBlock block, HashDigest<SHA256>? baseStateroothash)
{
return new IActionEvaluation[]
return new ICommittedActionEvaluation[]
{
new ActionEvaluation(
new CommittedActionEvaluation(
(Text)"POST",
new ActionContext(
null,
new CommittedActionContext(
default,
null,
default,
0,
0,
false,
new AccountStateDelta(),
default,
0,
null,
false),
new AccountStateDelta(),
null)
default)
};
}
}

class PreActionEvaluator : IActionEvaluator
{
public IActionLoader ActionLoader => throw new NotSupportedException();
public IReadOnlyList<IActionEvaluation> Evaluate(IPreEvaluationBlock block, HashDigest<SHA256>? baseStateRootHash)
public IReadOnlyList<ICommittedActionEvaluation> Evaluate(IPreEvaluationBlock block, HashDigest<SHA256>? baseStateRootHash)
{
return new IActionEvaluation[]
return new ICommittedActionEvaluation[]
{
new ActionEvaluation(
new CommittedActionEvaluation(
(Text)"PRE",
new ActionContext(
null,
new CommittedActionContext(
default,
null,
default,
0,
0,
false,
new AccountStateDelta(),
default,
0,
null,
false),
new AccountStateDelta(),
null)
default)
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public ForkableActionEvaluator(IEnumerable<((long StartIndex, long EndIndex) Ran

public IActionLoader ActionLoader => throw new NotSupportedException();

public IReadOnlyList<IActionEvaluation> Evaluate(
public IReadOnlyList<ICommittedActionEvaluation> Evaluate(
IPreEvaluationBlock block, HashDigest<SHA256>? baseStateRootHash)
{
var actionEvaluator = _router.GetEvaluator(block.Index);
Expand Down
2 changes: 1 addition & 1 deletion Libplanet.Headless/Hosting/LibplanetNodeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ IActionEvaluator BuildActionEvaluator(IActionEvaluatorConfiguration actionEvalua
return actionEvaluatorConfiguration switch
{
RemoteActionEvaluatorConfiguration remoteActionEvaluatorConfiguration => new RemoteActionEvaluator(
new Uri(remoteActionEvaluatorConfiguration.StateServiceEndpoint), blockChainStates),
new Uri(remoteActionEvaluatorConfiguration.StateServiceEndpoint)),
DefaultActionEvaluatorConfiguration _ => new ActionEvaluator(
_ => blockPolicy.BlockAction,
stateStore: StateStore,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,24 @@ public void PruneState(StoreType storeType)
stateStore,
genesisBlock,
actionEvaluator);

// Additional pruning is now required since in-between commits are made
store.Dispose();
stateStore.Dispose();
_command.PruneStates(storeType, _storePath);
store = storeType.CreateStore(_storePath);
stateKeyValueStore = new RocksDBKeyValueStore(statesPath);
stateStore = new TrieStateStore(stateKeyValueStore);
int prevStatesCount = stateKeyValueStore.ListKeys().Count();

stateKeyValueStore.Set(
new KeyBytes("alpha"),
ByteUtil.ParseHex("00"));
stateKeyValueStore.Set(
new KeyBytes("beta"),
ByteUtil.ParseHex("00"));
Assert.Equal(prevStatesCount + 2, stateKeyValueStore.ListKeys().Count());

store.Dispose();
stateStore.Dispose();
_command.PruneStates(storeType, _storePath);
Expand Down
4 changes: 2 additions & 2 deletions NineChronicles.Headless.Executable/Commands/ChainCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ public void Truncate(
}

snapshotTipHash = hash;
} while (!stateStore.ContainsStateRoot(store.GetBlock(snapshotTipHash).StateRootHash));
} while (!stateStore.GetStateRoot(store.GetBlock(snapshotTipHash).StateRootHash).Recorded);

var forkedId = Guid.NewGuid();

Expand Down Expand Up @@ -484,7 +484,7 @@ public void Snapshot(
}

snapshotTipHash = hash;
} while (!stateStore.ContainsStateRoot(store.GetBlock(snapshotTipHash).StateRootHash));
} while (!stateStore.GetStateRoot(store.GetBlock(snapshotTipHash).StateRootHash).Recorded);

var forkedId = Guid.NewGuid();

Expand Down
1 change: 1 addition & 0 deletions NineChronicles.Headless/GraphQLServiceExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public static IServiceCollection AddLibplanetScalarTypes(this IServiceCollection
services.TryAddSingleton<Libplanet.Explorer.GraphTypes.VoteType>();
services.TryAddSingleton<Libplanet.Explorer.GraphTypes.BlockCommitType>();
services.TryAddSingleton<Libplanet.Explorer.GraphTypes.BoundPeerType>();
services.TryAddSingleton<Libplanet.Explorer.GraphTypes.HashDigestSHA256Type>();

return services;
}
Expand Down
12 changes: 4 additions & 8 deletions NineChronicles.Headless/GraphTypes/StandaloneSubscription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -322,16 +322,12 @@ private IObservable<Tx> SubscribeTx(IResolveFieldContext context)
}
var txExecution = store.GetTxExecution(blockHash, transaction.Id);
var txExecutedBlock = chain[blockHash];
return txExecution.Fail
? new TxResult(
TxStatus.FAILURE,
txExecutedBlock.Index,
txExecutedBlock.Hash.ToString(),
txExecution.ExceptionNames)
: new TxResult(
TxStatus.SUCCESS,
return new TxResult(
txExecution.Fail ? TxStatus.FAILURE : TxStatus.SUCCESS,
txExecutedBlock.Index,
txExecutedBlock.Hash.ToString(),
txExecution.InputState,
txExecution.OutputState,
txExecution.ExceptionNames);
}

Expand Down
24 changes: 10 additions & 14 deletions NineChronicles.Headless/GraphTypes/TransactionHeadlessQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,29 +208,25 @@ public TransactionHeadlessQuery(StandaloneContext standaloneContext)
if (!(store.GetFirstTxIdBlockHashIndex(txId) is { } txExecutedBlockHash))
{
return blockChain.GetStagedTransactionIds().Contains(txId)
? new TxResult(TxStatus.STAGING, null, null, null)
: new TxResult(TxStatus.INVALID, null, null, null);
? new TxResult(TxStatus.STAGING, null, null, null, null, null)
: new TxResult(TxStatus.INVALID, null, null, null, null, null);
}
try
{
TxExecution execution = blockChain.GetTxExecution(txExecutedBlockHash, txId);
Block txExecutedBlock = blockChain[txExecutedBlockHash];
return execution.Fail
? new TxResult(
TxStatus.FAILURE,
txExecutedBlock.Index,
txExecutedBlock.Hash.ToString(),
execution.ExceptionNames)
: new TxResult(
TxStatus.SUCCESS,
txExecutedBlock.Index,
txExecutedBlock.Hash.ToString(),
execution.ExceptionNames);
return new TxResult(
execution.Fail ? TxStatus.FAILURE : TxStatus.SUCCESS,
txExecutedBlock.Index,
txExecutedBlock.Hash.ToString(),
execution.InputState,
execution.OutputState,
execution.ExceptionNames);
}
catch (Exception)
{
return new TxResult(TxStatus.INVALID, null, null, null);
return new TxResult(TxStatus.INVALID, null, null, null, null, null);
}
}
);
Expand Down

0 comments on commit 55b232e

Please sign in to comment.