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

♻️ Changed BlockDemand to hold an IBlockExcerpt instead of BlockHeader #3934

Merged
merged 2 commits into from
Aug 23, 2024
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
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ To be released.
[[#3913]]
- (Libplanet.Store) Removed unused `HashNode.Serialize()` method.
[[#3922], [#3924]]
- (Libplanet.Net) Removed `Header` property and added `BlockExcerpt` property
to `BlockDemand`. [[#3934]]

### Backward-incompatible network protocol changes

Expand All @@ -44,6 +46,7 @@ To be released.
[#3922]: https://github.com/planetarium/libplanet/issues/3922
[#3924]: https://github.com/planetarium/libplanet/pull/3924
[#3926]: https://github.com/planetarium/libplanet/pull/3926
[#3934]: https://github.com/planetarium/libplanet/pull/3934


Version 5.2.2
Expand Down
17 changes: 10 additions & 7 deletions src/Libplanet.Net/BlockDemand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ namespace Libplanet.Net
public readonly struct BlockDemand : IBlockExcerpt
{
/// <summary>
/// The <see cref="BlockHeader"/> of the block to request.
/// The <see cref="IBlockExcerpt"/> of the block to request.
/// </summary>
public readonly BlockHeader Header;
public readonly IBlockExcerpt BlockExcerpt;

/// <summary>
/// The <see cref="BoundPeer"/> to request block hash from.
Expand All @@ -24,17 +24,20 @@ namespace Libplanet.Net
/// </summary>
public readonly DateTimeOffset Timestamp;

public BlockDemand(BlockHeader header, BoundPeer peer, DateTimeOffset timestamp)
public BlockDemand(IBlockExcerpt blockExcerpt, BoundPeer peer, DateTimeOffset timestamp)
{
Header = header;
BlockExcerpt = blockExcerpt;
Peer = peer;
Timestamp = timestamp;
}

public int ProtocolVersion => Header.ProtocolVersion;
/// <inheritdoc cref="IBlockExcerpt.ProtocolVersion"/>
public int ProtocolVersion => BlockExcerpt.ProtocolVersion;

public long Index => Header.Index;
/// <inheritdoc cref="IBlockExcerpt.Index"/>
public long Index => BlockExcerpt.Index;

public BlockHash Hash => ((IBlockExcerpt)Header).Hash;
/// <inheritdoc cref="IBlockExcerpt.Hash"/>
public BlockHash Hash => BlockExcerpt.Hash;
}
}
2 changes: 1 addition & 1 deletion src/Libplanet.Net/BlockDemandTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void Add(
{
_blockDemands[demand.Peer] = demand;
Log.Debug(
"BlockDemand #{Index} {BlockHash} from peer {Peer} added",
"BlockDemand #{Index} {BlockHash} from peer {Peer} updated",
demand.Index,
demand.Hash,
demand.Peer);
Expand Down
8 changes: 4 additions & 4 deletions src/Libplanet.Net/Swarm.BlockCandidate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,8 @@ private async Task<bool> ProcessBlockDemandAsync(
"to fetch the block #{BlockIndex} {BlockHash} at {MethodName}()",
sessionId,
peer,
demand.Header.Index,
demand.Header.Hash,
demand.Index,
demand.Hash,
nameof(ProcessBlockDemandAsync));

try
Expand All @@ -375,7 +375,7 @@ private async Task<bool> ProcessBlockDemandAsync(
var result = await BlockCandidateDownload(
peer: peer,
blockChain: BlockChain,
stop: demand.Header,
stop: demand.BlockExcerpt,
logSessionId: sessionId,
cancellationToken: cancellationToken);

Expand Down Expand Up @@ -431,7 +431,7 @@ private async Task<bool> ProcessBlockDemandAsync(
private async Task<bool> BlockCandidateDownload(
BoundPeer peer,
BlockChain blockChain,
BlockHeader stop,
IBlockExcerpt stop,
int logSessionId,
CancellationToken cancellationToken)
{
Expand Down
Loading