Skip to content

Commit

Permalink
include the consensus time into block intervals.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim8y committed Dec 12, 2024
1 parent 3b52a3c commit f016575
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ private void OnPrepareRequestReceived(ExtensiblePayload payload, PrepareRequest
// around 4*3/M=12.0/5 ~ 80% block time (for M=5)
ExtendTimerByFactor(4);

onPrepareReceivedTime = TimeProvider.Current.UtcNow;
onPrepareBlockIndex = message.BlockIndex;

context.Block.Header.Timestamp = message.Timestamp;
context.Block.Header.Nonce = message.Nonce;
context.TransactionHashes = message.TransactionHashes;
Expand Down
8 changes: 6 additions & 2 deletions src/Plugins/DBFTPlugin/Consensus/ConsensusService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ private class Timer { public uint Height; public byte ViewNumber; }
private readonly IActorRef blockchain;
private ICancelable timer_token;
private DateTime block_received_time;
private DateTime onPrepareReceivedTime;
private uint onPrepareBlockIndex;
private uint block_received_index;
private bool started = false;

Expand Down Expand Up @@ -95,9 +97,11 @@ private void InitializeConsensus(byte viewNumber)
else
{
TimeSpan span = neoSystem.Settings.TimePerBlock;
if (block_received_index + 1 == context.Block.Index)

if (block_received_index + 1 == context.Block.Index && onPrepareBlockIndex + 1 == context.Block.Index)
{
var diff = TimeProvider.Current.UtcNow - block_received_time;
// Include the consensus time into the consensus intervals.
var diff = TimeProvider.Current.UtcNow - onPrepareReceivedTime;
if (diff >= span)
span = TimeSpan.Zero;
else
Expand Down

0 comments on commit f016575

Please sign in to comment.