Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,31 @@ public async Task Cache_block_headers_unless_peer_changed()
await newSyncPeer.Received(1).GetBlockHeaders(Arg.Any<long>(), Arg.Any<int>(), Arg.Any<int>(), Arg.Any<CancellationToken>());
}

[Test]
public async Task Cache_block_headers_with_disposal()
{
await using IContainer node = CreateNode();
Context ctx = node.Resolve<Context>();

ISyncPeer syncPeer = Substitute.For<ISyncPeer>();
syncPeer.TotalDifficulty.Returns(UInt256.MaxValue);
syncPeer.GetBlockHeaders(Arg.Any<long>(), Arg.Any<int>(), Arg.Any<int>(), Arg.Any<CancellationToken>())
.Returns(ci => ctx.ResponseBuilder.BuildHeaderResponse(ci.ArgAt<long>(0), ci.ArgAt<int>(1), Response.AllCorrect));

PeerInfo peerInfo = new(syncPeer);
syncPeer.HeadNumber.Returns(1000);
ctx.ConfigureBestPeer(peerInfo);

IForwardHeaderProvider forwardHeader = ctx.ForwardHeaderProvider;

using IOwnedReadOnlyList<BlockHeader?>? headers1 = await forwardHeader.GetBlockHeaders(0, 128, CancellationToken.None);
headers1.Should().NotBeNull();
using IOwnedReadOnlyList<BlockHeader?>? headers2 = await forwardHeader.GetBlockHeaders(0, 128, CancellationToken.None);
headers2.Should().NotBeNull();

await syncPeer.Received(1).GetBlockHeaders(Arg.Any<long>(), Arg.Any<int>(), Arg.Any<int>(), Arg.Any<CancellationToken>());
}

private class SlowSealValidator : ISealValidator
{
public bool ValidateParams(BlockHeader parent, BlockHeader header, bool isUncle = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ private IOwnedReadOnlyList<BlockHeader>? LastResponseBatch
}

LastResponseBatch = newResponse;
return LastResponseBatch;
return newResponse.ToPooledList(newResponse.Count);
}

private void OnNewBestPeer(PeerInfo newBestPeer)
Expand Down