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

Decrease the block time threshold (3x) #1233

Merged
merged 18 commits into from
Nov 21, 2019
Merged
Show file tree
Hide file tree
Changes from 13 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
8 changes: 7 additions & 1 deletion neo.UnitTests/Consensus/UT_Consensus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

namespace Neo.UnitTests.Consensus
{

[TestClass]
public class ConsensusTests : TestKit
{
Expand All @@ -36,6 +35,13 @@ public void Cleanup()
Shutdown();
}

[TestMethod, NotReRunnable]
public void TestPrepareRequestThreshold()
{
var service = new ConsensusService(null, null, null);
Assert.AreEqual(8 * Blockchain.TimePerBlock.TotalMilliseconds, service.PrepareRequestThreshold.TotalMilliseconds);
}

[TestMethod]
public void ConsensusService_Primary_Sends_PrepareRequest_After_OnStart()
{
Expand Down
3 changes: 2 additions & 1 deletion neo/Consensus/ConsensusService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ internal class Timer { public uint Height; public byte ViewNumber; }
private ICancelable timer_token;
private DateTime block_received_time;
private bool started = false;
public readonly TimeSpan PrepareRequestThreshold = TimeSpan.FromMilliseconds(8 * Blockchain.TimePerBlock.TotalMilliseconds);
shargon marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// This will record the information from last scheduled timer
Expand Down Expand Up @@ -405,7 +406,7 @@ private void OnPrepareRequestReceived(ConsensusPayload payload, PrepareRequest m
if (context.RequestSentOrReceived || context.NotAcceptingPayloadsDueToViewChanging) return;
if (payload.ValidatorIndex != context.Block.ConsensusData.PrimaryIndex || message.ViewNumber != context.ViewNumber) return;
Log($"{nameof(OnPrepareRequestReceived)}: height={payload.BlockIndex} view={message.ViewNumber} index={payload.ValidatorIndex} tx={message.TransactionHashes.Length}");
if (message.Timestamp <= context.PrevHeader.Timestamp || message.Timestamp > TimeProvider.Current.UtcNow.AddMinutes(10).ToTimestampMS())
if (message.Timestamp <= context.PrevHeader.Timestamp || message.Timestamp > TimeProvider.Current.UtcNow.Add(PrepareRequestThreshold).ToTimestampMS())
{
Log($"Timestamp incorrect: {message.Timestamp}", LogLevel.Warning);
return;
Expand Down