Skip to content

Commit

Permalink
Merge pull request #250 from planetarium/bump/sloth
Browse files Browse the repository at this point in the history
Bump sloth
  • Loading branch information
area363 authored Jul 9, 2024
2 parents 628c4bf + a59a95e commit 45205b5
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 9 deletions.
49 changes: 41 additions & 8 deletions NineChronicles.Snapshot/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,22 +154,21 @@ public void Snapshot(
_stateStore,
new NCActionLoader()
);
var originalChain = new BlockChain(blockPolicy, stagePolicy, _store, _stateStore, _store.GetBlock(genesisHash), blockChainStates, actionEvaluator);
var tip = _store.GetBlock(tipHash);

var potentialSnapshotTipIndex = tipIndex - blockBefore;
var potentialSnapshotTipHash = (BlockHash)_store.IndexBlockHash(chainId, potentialSnapshotTipIndex)!;
var snapshotTip = _store.GetBlock(potentialSnapshotTipHash);

_logger.Debug("Original Store Tip: #{0}\n1. LastCommit: {1}\n2. BlockCommit in Chain: {2}\n3. BlockCommit in Store: {3}",
tip.Index, tip.LastCommit, originalChain.GetBlockCommit(tipHash), _store.GetBlockCommit(tipHash));
tip.Index, tip.LastCommit, GetChainBlockCommit(tipHash, chainId), _store.GetBlockCommit(tipHash));
_logger.Debug("Potential Snapshot Tip: #{0}\n1. LastCommit: {1}\n2. BlockCommit in Chain: {2}\n3. BlockCommit in Store: {3}",
potentialSnapshotTipIndex, snapshotTip.LastCommit, originalChain.GetBlockCommit(potentialSnapshotTipHash), _store.GetBlockCommit(potentialSnapshotTipHash));
potentialSnapshotTipIndex, snapshotTip.LastCommit, GetChainBlockCommit(potentialSnapshotTipHash, chainId), _store.GetBlockCommit(potentialSnapshotTipHash));

var tipBlockCommit = _store.GetBlockCommit(tipHash) ??
originalChain.GetBlockCommit(tipHash);
GetChainBlockCommit(tipHash, chainId);
var potentialSnapshotTipBlockCommit = _store.GetBlockCommit(potentialSnapshotTipHash) ??
originalChain.GetBlockCommit(potentialSnapshotTipHash);
GetChainBlockCommit(potentialSnapshotTipHash, chainId);

// Add tip and the snapshot tip's block commit to store to avoid block validation during preloading
if (potentialSnapshotTipBlockCommit != null)
Expand Down Expand Up @@ -247,11 +246,12 @@ public void Snapshot(
count++;
}

var newChain = new BlockChain(blockPolicy, stagePolicy, _store, _stateStore, _store.GetBlock(genesisHash), blockChainStates, actionEvaluator);
var newTip = newChain.Tip;
var newTipHash = _store.IndexBlockHash(forkedId, -1)
?? throw new CommandExitedException("The given chain seems empty.", -1);
var newTip = _store.GetBlock(newTipHash);
var latestEpoch = (int) (newTip.Timestamp.ToUnixTimeSeconds() / epochUnitSeconds);
_logger.Debug("Official Snapshot Tip: #{0}\n1. Timestamp: {1}\n2. Latest Epoch: {2}\n3. BlockCommit in Chain: {3}\n4. BlockCommit in Store: {4}",
newTip.Index, newTip.Timestamp.UtcDateTime, latestEpoch, newChain.GetBlockCommit(newTip.Hash), _store.GetBlockCommit(newTip.Hash));
newTip.Index, newTip.Timestamp.UtcDateTime, latestEpoch, GetChainBlockCommit(newTip.Hash, forkedId), _store.GetBlockCommit(newTip.Hash));

_logger.Debug($"Snapshot-{snapshotType.ToString()} CopyStates Start.");
var start = DateTimeOffset.Now;
Expand Down Expand Up @@ -693,6 +693,39 @@ private JObject AddPreviousEpochs(
return jsonObject;
}

private BlockCommit GetChainBlockCommit(BlockHash blockHash, Guid chainId)
{
var tipHash = _store.IndexBlockHash(chainId, -1)
?? throw new CommandExitedException("The given chain seems empty.", -1);
if (!(_store.GetBlockIndex(tipHash) is { } tipIndex))
{
throw new CommandExitedException(
$"The index of {tipHash} doesn't exist.",
-1);
}

if (!(_store.GetBlockIndex(blockHash) is { } blockIndex))
{
throw new CommandExitedException(
$"The index of {blockHash} doesn't exist.",
-1);
}

if (blockIndex == tipIndex)
{
return _store.GetChainBlockCommit(chainId);
}

if (!(_store.IndexBlockHash(chainId, blockIndex + 1) is { } nextHash))
{
throw new CommandExitedException(
$"The hash of index {blockIndex + 1} doesn't exist.",
-1);
}

return _store.GetBlock(nextHash).LastCommit;
}

public class NCActionLoader : IActionLoader
{
private readonly IActionLoader _actionLoader;

Check warning on line 731 in NineChronicles.Snapshot/Program.cs

View workflow job for this annotation

GitHub Actions / build

Field 'Program.NCActionLoader._actionLoader' is never assigned to, and will always have its default value null

Check warning on line 731 in NineChronicles.Snapshot/Program.cs

View workflow job for this annotation

GitHub Actions / build

Field 'Program.NCActionLoader._actionLoader' is never assigned to, and will always have its default value null
Expand Down
2 changes: 1 addition & 1 deletion libplanet
Submodule libplanet updated 88 files
+141 −0 CHANGES.md
+1 −1 Docs/articles/overview.md
+26 −0 Libplanet.Action.Tests/BlockProtocolVersionNotSupportedExceptionTest.cs
+10 −0 Libplanet.Action/ActionEvaluator.cs
+0 −1 Libplanet.Action/AssemblyInfo.cs
+52 −0 Libplanet.Action/BlockProtocolVersionNotSupportedException.cs
+4 −0 Libplanet.Action/IActionEvaluator.cs
+11 −9 Libplanet.Action/State/IBlockChainStates.cs
+0 −62 Libplanet.Action/State/IStateStoreExtensions.cs
+0 −130 Libplanet.Common/Nonce.cs
+0 −4 Libplanet.Explorer.Executable/Options.cs
+0 −8 Libplanet.Explorer.Executable/Program.cs
+80 −0 Libplanet.Explorer.Tests/Fixtures/BlockChainStatesFixture.cs
+0 −2 Libplanet.Explorer.Tests/GeneratedBlockChainFixture.cs
+5 −0 Libplanet.Explorer.Tests/GraphTypes/BlockTypeTest.cs
+18 −31 Libplanet.Explorer.Tests/Queries/RawStateQueryTest.cs
+213 −159 Libplanet.Explorer.Tests/Queries/StateQueryTest.Legacy.cs
+0 −77 Libplanet.Explorer.Tests/Queries/StateQueryTest.Mocks.cs
+142 −149 Libplanet.Explorer.Tests/Queries/StateQueryTest.cs
+4 −0 Libplanet.Explorer/GraphTypes/AccountStateType.cs
+4 −0 Libplanet.Explorer/GraphTypes/BlockType.cs
+41 −0 Libplanet.Explorer/GraphTypes/WorldStateType.cs
+5 −14 Libplanet.Explorer/Queries/StateQuery.cs
+1 −6 Libplanet.Extensions.Cocona/Commands/BlockCommand.cs
+73 −0 Libplanet.Mocks/MockBlockChainStates.cs
+1 −1 Libplanet.Mocks/MockWorldState.cs
+9 −0 Libplanet.Net.Tests/Consensus/ConsensusContextTest.cs
+1 −2 Libplanet.Net.Tests/Consensus/ContextNonProposerTest.cs
+117 −3 Libplanet.Net.Tests/Consensus/ContextTest.cs
+1 −1 Libplanet.Net.Tests/Messages/MessageTest.cs
+3 −3 Libplanet.Net.Tests/SwarmTest.Preload.cs
+17 −14 Libplanet.Net.Tests/SwarmTest.cs
+1 −1 Libplanet.Net.Tests/TestUtils.cs
+50 −18 Libplanet.Net/Consensus/ConsensusContext.cs
+5 −0 Libplanet.Net/Consensus/Context.Async.cs
+6 −11 Libplanet.Net/Consensus/Context.Mutate.cs
+9 −26 Libplanet.Net/Consensus/Context.cs
+10 −1 Libplanet.Net/Swarm.BlockCandidate.cs
+0 −12 Libplanet.Net/Swarm.cs
+95 −0 Libplanet.RocksDBStore/RocksDBStore.cs
+12 −0 Libplanet.Store/BaseStore.cs
+59 −0 Libplanet.Store/DefaultStore.cs
+1 −1 Libplanet.Store/HashNodeCache.cs
+29 −0 Libplanet.Store/IStore.cs
+18 −0 Libplanet.Store/MemoryStore.cs
+0 −7 Libplanet.Store/TrieStateStore.cs
+5 −4 Libplanet.Tests/Action/ActionEvaluatorTest.Migration.cs
+27 −17 Libplanet.Tests/Action/ActionEvaluatorTest.cs
+105 −121 Libplanet.Tests/Action/WorldTest.cs
+15 −0 Libplanet.Tests/Action/WorldV0Test.cs
+15 −0 Libplanet.Tests/Action/WorldV1Test.cs
+83 −52 Libplanet.Tests/Blockchain/BlockChainTest.Append.cs
+2 −1 Libplanet.Tests/Blockchain/BlockChainTest.Internals.cs
+23 −23 Libplanet.Tests/Blockchain/BlockChainTest.ProposeBlock.cs
+178 −9 Libplanet.Tests/Blockchain/BlockChainTest.ValidateNextBlock.cs
+41 −41 Libplanet.Tests/Blockchain/BlockChainTest.cs
+0 −89 Libplanet.Tests/Blockchain/Renderers/AtomicActionRendererTest.cs
+65 −0 Libplanet.Tests/Blocks/BlockMarshalerTest.Legacy.cs
+1 −1 Libplanet.Tests/Blocks/BlockMarshalerTest.cs
+12 −72 Libplanet.Tests/Blocks/BlockMetadataTest.cs
+23 −23 Libplanet.Tests/Blocks/PreEvaluationBlockHeaderTest.cs
+14 −22 Libplanet.Tests/Blocks/PreEvaluationBlockTest.cs
+1 −5 Libplanet.Tests/Fixtures/IntegerSet.cs
+109 −0 Libplanet.Tests/Fixtures/LegacyBlocks.cs
+0 −58 Libplanet.Tests/NonceTest.cs
+14 −0 Libplanet.Tests/Store/ProxyStore.cs
+13 −8 Libplanet.Tests/Store/StoreFixture.cs
+33 −1 Libplanet.Tests/Store/StoreTest.cs
+20 −0 Libplanet.Tests/Store/StoreTracker.cs
+7 −16 Libplanet.Tests/TestUtils.cs
+10 −1 Libplanet.Tools/bin/npm-test.sh
+3 −5 Libplanet.Types/Blocks/BlockContent.cs
+19 −48 Libplanet.Types/Blocks/BlockMarshaler.cs
+27 −10 Libplanet.Types/Blocks/BlockMetadata.cs
+1 −2 Libplanet.Types/Blocks/IBlockHeader.cs
+3 −4 Libplanet.Types/Blocks/IPreEvaluationBlockHeader.cs
+2 −2 Libplanet.Types/Blocks/PreEvaluationBlockHeader.cs
+129 −74 Libplanet/Blockchain/BlockChain.Evaluate.cs
+21 −18 Libplanet/Blockchain/BlockChain.ProposeBlock.cs
+45 −5 Libplanet/Blockchain/BlockChain.States.cs
+1 −1 Libplanet/Blockchain/BlockChain.TxExecution.cs
+65 −7 Libplanet/Blockchain/BlockChain.Validate.cs
+260 −24 Libplanet/Blockchain/BlockChain.cs
+5 −9 Libplanet/Blockchain/BlockChainStates.cs
+0 −123 Libplanet/Blockchain/Renderers/AtomicActionRenderer.cs
+0 −3 Libplanet/Blockchain/Renderers/IActionRenderer.cs
+1 −1 Libplanet/Libplanet.csproj
+19 −5 scripts/determine-version.js

0 comments on commit 45205b5

Please sign in to comment.