Skip to content

Commit

Permalink
Merge pull request #3934 from greymistcube/refactor/block-demand
Browse files Browse the repository at this point in the history
♻️ Changed `BlockDemand` to hold an `IBlockExcerpt` instead of `BlockHeader`
  • Loading branch information
greymistcube authored Aug 23, 2024
2 parents cb2deed + 8385be7 commit 6ec04a5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
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

0 comments on commit 6ec04a5

Please sign in to comment.