Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix FindBranchPoint #468

Merged
merged 1 commit into from Aug 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.md
Expand Up @@ -18,9 +18,13 @@ To be released.
which consists of incomplete states (i.e., precalculated states downloaded
from trusted peers), encounters a new branch so that reorg is made.
[[#454], [#466]]
- Fixed a bug that unnecessarily received all blocks in multiple miner
situations. [[#457], [#468]]

[#454]: https://github.com/planetarium/libplanet/issues/454
[#457]: https://github.com/planetarium/libplanet/issues/457
[#466]: https://github.com/planetarium/libplanet/pull/466
[#468]: https://github.com/planetarium/libplanet/pull/468


Version 0.5.0
Expand Down
16 changes: 16 additions & 0 deletions Libplanet.Tests/Blockchain/BlockChainTest.cs
Expand Up @@ -492,6 +492,22 @@ public void FindNextHashes()
new BlockLocator(new[] { block0.Hash })));
}

[Fact]
public void FindNextHashesAfterFork()
{
_blockChain.MineBlock(_fx.Address1);
_blockChain.MineBlock(_fx.Address1);
_blockChain.MineBlock(_fx.Address1);

BlockChain<DumbAction> forked = _blockChain.Fork(_blockChain[0].Hash);
forked.MineBlock(_fx.Address1);

BlockLocator locator = _blockChain.GetBlockLocator();
IEnumerable<HashDigest<SHA256>> hashes = forked.FindNextHashes(locator);

Assert.Equal(new[] { forked[0].Hash, forked[1].Hash }, hashes);
}

[Fact]
public void Fork()
{
Expand Down
4 changes: 3 additions & 1 deletion Libplanet/Blockchain/BlockChain.cs
Expand Up @@ -738,7 +738,9 @@ internal HashDigest<SHA256> FindBranchPoint(BlockLocator locator)

foreach (HashDigest<SHA256> hash in locator)
{
if (Blocks.ContainsKey(hash))
if (Blocks.ContainsKey(hash)
&& Blocks[hash] is Block<T> block
earlbread marked this conversation as resolved.
Show resolved Hide resolved
&& hash.Equals(Store.IndexBlockHash(Id.ToString(), block.Index)))
{
return hash;
}
Expand Down