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

[Core Plugin DBFT] include consensus time into block interval #3637

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -98,6 +98,9 @@ private void OnPrepareRequestReceived(ExtensiblePayload payload, PrepareRequest
// around 2*15/M=30.0/5 ~ 40% block time (for M=5)
ExtendTimerByFactor(2);

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
7 changes: 5 additions & 2 deletions src/Plugins/DBFTPlugin/Consensus/ConsensusService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ private class Timer { public uint Height; public byte ViewNumber; }
private ICancelable timer_token;
private DateTime block_received_time;
private uint block_received_index;
private DateTime onPrepareReceivedTime;
private uint onPrepareBlockIndex;
private bool started = false;

/// <summary>
Expand Down Expand Up @@ -95,9 +97,10 @@ 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is required? seems a fix for a different thing

{
var diff = TimeProvider.Current.UtcNow - block_received_time;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likely block_received_time is not needed now.

// Include the consensus time into the consensus intervals.
var diff = TimeProvider.Current.UtcNow - onPrepareReceivedTime;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this methodology can trigger strange behaviors in a real scenario, after change views, delays and etc...

if (diff >= span)
span = TimeSpan.Zero;
else
Expand Down
Loading