diff --git a/src/Libplanet.Net/Swarm.MessageHandlers.cs b/src/Libplanet.Net/Swarm.MessageHandlers.cs index 2f33f5e8dd9..f49fafa8b31 100644 --- a/src/Libplanet.Net/Swarm.MessageHandlers.cs +++ b/src/Libplanet.Net/Swarm.MessageHandlers.cs @@ -50,18 +50,13 @@ private Task ProcessMessageHandlerAsync(Message message) "Received a {MessageType} message locator [{LocatorHead}]", nameof(GetBlockHashesMsg), getBlockHashes.Locator.Hash); - BlockChain.FindNextHashes( + IReadOnlyList hashes = BlockChain.FindNextHashes( getBlockHashes.Locator, - FindNextHashesChunkSize - ).Deconstruct( - out long? offset, - out IReadOnlyList hashes - ); + FindNextHashesChunkSize); _logger.Debug( - "Found {HashCount} hashes after the branchpoint (offset: {Offset}) " + + "Found {HashCount} hashes after the branchpoint " + "with locator [{LocatorHead}]", hashes.Count, - offset, getBlockHashes.Locator.Hash); var reply = new BlockHashesMsg(hashes); diff --git a/src/Libplanet/Blockchain/BlockChain.cs b/src/Libplanet/Blockchain/BlockChain.cs index 04797ab6508..3db6d05038a 100644 --- a/src/Libplanet/Blockchain/BlockChain.cs +++ b/src/Libplanet/Blockchain/BlockChain.cs @@ -666,7 +666,7 @@ public IImmutableSet GetStagedTransactionIds() /// including the branch point . If no branch point is found, /// returns a tuple of and an empty array of /// es. - public Tuple> FindNextHashes( + public IReadOnlyList FindNextHashes( BlockLocator locator, int count = 500) { @@ -675,12 +675,12 @@ public IImmutableSet GetStagedTransactionIds() if (!(FindBranchpoint(locator) is { } branchpoint)) { - return new Tuple>(null, Array.Empty()); + return Array.Empty(); } if (!(Store.GetBlockIndex(branchpoint) is { } branchpointIndex)) { - return new Tuple>(null, Array.Empty()); + return Array.Empty(); } var result = new List(); @@ -705,7 +705,7 @@ public IImmutableSet GetStagedTransactionIds() Store.ListChainIds().Count(), stopwatch.ElapsedMilliseconds); - return new Tuple>(branchpointIndex, result); + return result; } /// @@ -1194,19 +1194,13 @@ internal void AppendStateRootHashPreceded( { _rwlock.EnterReadLock(); - _logger.Debug( - "Finding a branchpoint with locator [{LocatorHead}]", - locator.Hash); - BlockHash hash = locator.Hash; - if (_blocks.ContainsKey(hash) - && _blocks[hash] is Block block - && hash.Equals(Store.IndexBlockHash(Id, block.Index))) + if (ContainsBlock(locator.Hash)) { _logger.Debug( "Found a branchpoint with locator [{LocatorHead}]: {Hash}", locator.Hash, - hash); - return hash; + locator.Hash); + return locator.Hash; } _logger.Debug( diff --git a/test/Libplanet.Tests/Blockchain/BlockChainTest.cs b/test/Libplanet.Tests/Blockchain/BlockChainTest.cs index 955984b3599..fdcc14c771f 100644 --- a/test/Libplanet.Tests/Blockchain/BlockChainTest.cs +++ b/test/Libplanet.Tests/Blockchain/BlockChainTest.cs @@ -433,12 +433,9 @@ public void RenderActionsAfterAppendComplete() public void FindNextHashes() { var key = new PrivateKey(); - long? offsetIndex; IReadOnlyList hashes; - _blockChain.FindNextHashes( - new BlockLocator(_blockChain.Genesis.Hash)) - .Deconstruct(out offsetIndex, out hashes); + hashes = _blockChain.FindNextHashes(new BlockLocator(_blockChain.Genesis.Hash)); Assert.Single(hashes); Assert.Equal(_blockChain.Genesis.Hash, hashes.First()); var block0 = _blockChain.Genesis; @@ -451,19 +448,13 @@ public void FindNextHashes() key, lastCommit: CreateBlockCommit(_blockChain.Tip)); _blockChain.Append(block3, CreateBlockCommit(block3)); - _blockChain.FindNextHashes(new BlockLocator(block0.Hash)) - .Deconstruct(out offsetIndex, out hashes); - Assert.Equal(0, offsetIndex); + hashes = _blockChain.FindNextHashes(new BlockLocator(block0.Hash)); Assert.Equal(new[] { block0.Hash, block1.Hash, block2.Hash, block3.Hash }, hashes); - _blockChain.FindNextHashes(new BlockLocator(block1.Hash)) - .Deconstruct(out offsetIndex, out hashes); - Assert.Equal(1, offsetIndex); + hashes = _blockChain.FindNextHashes(new BlockLocator(block1.Hash)); Assert.Equal(new[] { block1.Hash, block2.Hash, block3.Hash }, hashes); - _blockChain.FindNextHashes(new BlockLocator(block0.Hash), count: 2) - .Deconstruct(out offsetIndex, out hashes); - Assert.Equal(0, offsetIndex); + hashes = _blockChain.FindNextHashes(new BlockLocator(block0.Hash), count: 2); Assert.Equal(new[] { block0.Hash, block1.Hash }, hashes); }