Skip to content

Commit

Permalink
Changed BlockDemand to hold an IBlockExcerpt instead of BlockHeader
Browse files Browse the repository at this point in the history
  • Loading branch information
greymistcube committed Aug 23, 2024
1 parent cb2deed commit c3e932a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
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 c3e932a

Please sign in to comment.