Skip to content

3s consensus - With consensus time included into consensus intervals. #3622

Closed
Jim8y wants to merge 85 commits intoneo-project:masterfrom
Jim8y:3s-consensus
Closed

3s consensus - With consensus time included into consensus intervals. #3622
Jim8y wants to merge 85 commits intoneo-project:masterfrom
Jim8y:3s-consensus

Conversation

@Jim8y
Copy link
Contributor

@Jim8y Jim8y commented Dec 12, 2024

Description

Credits of this pr belong to @AnnaShaleva. Changes included into this PR:

  1. Move MSPerBlock protocol configuration to native Policy contract.
  2. Take into account PrepareRequest receival time during dBFT timer reset (close [Consensus] Include the consensus time into block interval. #3627).

Type of change

  • Enhancement.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@Jim8y Jim8y marked this pull request as draft December 12, 2024 15:01
Comment on lines -98 to +104
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;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the major change to this pr

Copy link
Member

Choose a reason for hiding this comment

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

This should be in another PR and not here, if that is the case.

And for your notice, as I said in our meetings, this configuration has been tested in the past.

I think that you need more experimental tests before publishing things to quick and even writing new standards (that are not even necessary).
I am not saying that the change is terrible, @Jim8y, but there are some consequences, I think that you did not analyse the entire scenario before pushing this and creating standards with it.

I will surely be against this change here in this PR for a series of reasons.
Try this in a decentralized scenario or inserting delays (you can deal with that on docker) or create on AWS/AZURE in different locations.

Copy link
Member

Choose a reason for hiding this comment

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

this configuration has been tested in the past.

Lots have changed in code since then. Would that affect anything like this? if so, we have to run these tests again to ensure its trueful.

Copy link
Contributor Author

@Jim8y Jim8y Feb 12, 2025

Choose a reason for hiding this comment

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

This should be in another PR and not here, if that is the case.

And for your notice, as I said in our meetings, this configuration has been tested in the past.

I think that you need more experimental tests before publishing things to quick and even writing new standards (that are not even necessary). I am not saying that the change is terrible, @Jim8y, but there are some consequences, I think that you did not analyse the entire scenario before pushing this and creating standards with it.

I will surely be against this change here in this PR for a series of reasons. Try this in a decentralized scenario or inserting delays (you can deal with that on docker) or create on AWS/AZURE in different locations.

We have setup a real testnet to carry out stress test and stability test for weeks. The network works fine and no issue. As you said should be in another pr thing, all changes in this pr now is for the service of and only serve the 3-seconds consensus, it is meaningless to add any of the prs and test any of the prs that only contain part of the changes in this pr. Casue non of the code in this pr means a thing without rest part.

We encourage small prs for the intention of easier review and test, its not like everything must be as small as possible.
If there is no review issue and no real logic problem, we should not split a complete and already tested pr.

Copy link
Member

Choose a reason for hiding this comment

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

Lots have changed in code since then. Would that affect anything like this? if so, we have to run these tests again to ensure its trueful.

You are right @cschuchardt88 , I was also saying that in my last message. Let's see

@Jim8y Jim8y marked this pull request as ready for review February 10, 2025 06:33
}

[ContractMethod(CpuFee = 1 << 15, RequiredCallFlags = CallFlags.ReadStates | CallFlags.WriteStates)]
public BigInteger GetGasPerBlock(ApplicationEngine engine, DataCache snapshot)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@shargon @roman-khimov please check this, i am try to update the gasperblock without really update it casue it should be a council thing.

Copy link
Member

Choose a reason for hiding this comment

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

You can change the arguments without hardfork, because both arguments are native ones

Copy link
Member

Choose a reason for hiding this comment

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

But we should not write into storages here... should be done by council

Copy link
Member

Choose a reason for hiding this comment

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

Maybe CN can detect when this is made by council and start the new time?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi shargon, i think my latest commit has addressed your concern:

  1. reuse existing GetGasPerBlock
  2. avoid write to the store but directly calculate a value
  3. ensures the council can still update the gasperblock, and the new value can be used immediately.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

UT updated accordingly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I intentially have two return currentgasperblolck to make the logic more clear as they are different situations. Code can be optimized if the logic passes review if necessary.

Copy link
Contributor

Choose a reason for hiding this comment

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

The ContractMethod cannot have ApplicationEngine and DataCache parameters at the same time.

Copy link
Contributor

@roman-khimov roman-khimov left a comment

Choose a reason for hiding this comment

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

  1. Most of the changes in this PR are just not needed at all (the only relevant is timer shift in fact).
  2. No hardfork is needed to change the block time in the current structure. It's just a matter of restarting consensus nodes with appropriate configuration.
  3. No native contract changes are required to change the GAS per block value. It's just a matter of sending a committee transaction. This one is really serious, btw, we do have a governance model and your changes just break it.
  4. Give 2 and 3 we can just schedule 3s block time to some post-Echidna date, create and send a transaction, restart CNs. This won't and can't be perfectly aligned, true, but I doubt it's a problem in practice. Changing governance assumptions behind the scenes is much bigger problem.
  5. But this still doesn't answer the time lock problem we can have with mainnet.

@Jim8y
Copy link
Contributor Author

Jim8y commented Apr 10, 2025

@Jim8y Conflicts, I need more tests..

@shargon, it looks like I'm the maintainer of this PR now, so conflicts are fixed, please take a look one more time. I'll add a unit test for Policy changes later. @vncoelho, we also need your review.

This is in the C# code and is of course a c# implementation documentation and is not an NEP. The NEP that i want to have on 3s is under the proposal repo. If the name is misleading

@Jim8y, regarding this NEP: it's not only about the name is misleading, it's more about the fact that content of this file diverges from the current implementation. Since you haven't pushed any fixes, I removed this file from the current PR in order not to delay 3-s consensus changes. Later, when you have time, you may create a separate PR to update the documentation part, and we'll review it.

Let me remove the document first, then add another version after the release of v3.8, looks like you already did, great.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
@AnnaShaleva
Copy link
Member

I'll add a unit test

Added.

@AnnaShaleva AnnaShaleva requested a review from shargon April 10, 2025 09:50
No functional changes, just remove useless changes and adjust
documentation.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
@vncoelho
Copy link
Member

@Jim8y Conflicts, I need more tests..

@shargon, it looks like I'm the maintainer of this PR now, so conflicts are fixed, please take a look one more time. I'll add a unit test for Policy changes later. @vncoelho, we also need your review.

This is in the C# code and is of course a c# implementation documentation and is not an NEP. The NEP that i want to have on 3s is under the proposal repo. If the name is misleading

@Jim8y, regarding this NEP: it's not only about the name is misleading, it's more about the fact that content of this file diverges from the current implementation. Since you haven't pushed any fixes, I removed this file from the current PR in order not to delay 3-s consensus changes. Later, when you have time, you may create a separate PR to update the documentation part, and we'll review it.

Sure, give me until tomorrow

@shargon
Copy link
Member

shargon commented Apr 10, 2025

https://github.com/neo-project/neo/pull/3622/files#r2037019862 (conversion is collapsed)

@AnnaShaleva AnnaShaleva requested a review from vncoelho April 10, 2025 11:40
vncoelho
vncoelho previously approved these changes Apr 10, 2025
/// For code that needs the block generation time based on blockchain state,
/// use NeoSystemExtensions.GetBlockGenTime extension method instead.
/// </summary>
public uint MillisecondsPerBlock { get; init; }
Copy link
Member

Choose a reason for hiding this comment

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

We can use obsolete to avoid the use, only in the new method

Copy link
Member

Choose a reason for hiding this comment

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

But this value is actually not obsolete, it's still used until Echidna is enabled. And it's used to initialize Policy at Echidna height, so this value will never be removed from the node's configuration.

public uint GetMSPerBlock(IReadOnlyStore snapshot)
{
// this should not be null since this method is only available after the HF_Echidna
snapshot.TryGet(_blockGenTime, out var item);
Copy link
Member

Choose a reason for hiding this comment

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

If ! throw an exception instead of get null exception should be good for debug

Copy link
Member

Choose a reason for hiding this comment

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

We should just use simple index expression here, like for any other Policy getter method. Will fix.

Copy link
Member

Choose a reason for hiding this comment

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

Fixed.

{
block_received_index = context.Block.Index;
block_received_time = TimeProvider.Current.UtcNow;
Block block = context.CreateBlock();
Copy link
Member

Choose a reason for hiding this comment

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

What's happend with this variable?

Copy link
Member

Choose a reason for hiding this comment

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

It's removed because it's not used after we implement #3622 (comment).

TimeSpan span = neoSystem.Settings.TimePerBlock;
if (block_received_index + 1 == context.Block.Index)
TimeSpan span = context.BlockGenTime;
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.

Extra condition?

Copy link
Member

Choose a reason for hiding this comment

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

I did not notice that! Good eyes @shargon.

I will dismiss my approval until this is clarified.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, extra condition, because @Jim8y wants to include #3637 into this PR. So this PR contains not only MSPerBlock Policy extension, but also dBFT improvement (#3627), that's why I asked review from @vncoelho.

Copy link
Member

Choose a reason for hiding this comment

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

If you wish, I can split this PR into two PRs to decouple Policy update from dBFT timer logic change. That was my original intention in #3622 (comment).

Copy link
Member

@AnnaShaleva AnnaShaleva Apr 11, 2025

Choose a reason for hiding this comment

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

OK, I see #3622 (comment), let's use two separate PRs. I'll create them soon.

Copy link
Member

@vncoelho vncoelho Apr 11, 2025

Choose a reason for hiding this comment

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

@AnnaShaleva, in fact I knew about the change in how to process block time.

Initially I was against changing it here directly because it is off course not the focus of this PR, but @Jim8y insisted and said @superboyiii was testing on testnet for long time.
So, we did also our experiments with this PR and the behaviours were quite good, we introduced adversaries delays, blocked communication and etc...The results were better than before.

But, when I say better than before, I mean the overall neo-core itself, not the change separately.
In this sense, I still believe it should be merged in another PR, let's say a minor patch after release. That is my opinion.

Copy link
Member

Choose a reason for hiding this comment

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

Indeed I double checked here again this line.

I was just confused...aheuaheuahea

In fact, in the past, when we studied this exactly modification that @Jim8y is pushing forward, we did not add this line.
This line is important and makes the difference for avoiding some problems on the node relative time in the new rule. It was a good catch by @Jim8y .

For me this PR can be merged.

Copy link
Member

Choose a reason for hiding this comment

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

On the other hand, fell free to split the PR and merge in two different commits, that also seems to be a better way to proceed.

Copy link
Member

@AnnaShaleva AnnaShaleva Apr 11, 2025

Choose a reason for hiding this comment

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

Let's use #3895, it's more clean and contains a single logical change, it's easier to review for everyone. So @vncoelho, @cschuchardt88 if you agree with this PR then please approve also #3895.

cschuchardt88
cschuchardt88 previously approved these changes Apr 11, 2025
@AnnaShaleva AnnaShaleva dismissed stale reviews from cschuchardt88 and vncoelho April 11, 2025 10:21

Changes were made.

Copy link
Member

@cschuchardt88 cschuchardt88 left a comment

Choose a reason for hiding this comment

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

LGTM

@AnnaShaleva
Copy link
Member

As agreed in #3622 (comment), this PR will be replaced by two PRs to split the logic: native Policy update (#3895) and dBFT timer adjustment (will create it after the merge of #3895).

cschuchardt88 added a commit to cschuchardt88/neo that referenced this pull request Jun 8, 2025
…ect#3861)

* Native: move MaxValidUntilBlockIncrement to native Policy

The problem is described in
nspcc-dev/neo-go#3841. In short words,
the chain's state is dependent on MaxValidUntilBlockIncrement setting,
whereas this setting depends on the block time. Since block generation
time is a part of native Policy (neo-project#3622), MaxValidUntilBlockIncrement
should follow, we need the same value to be applied at all CNs
simultaneously.

Port nspcc-dev/neo-go#3849.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>

* Extensions: improve formatting

No functional changes.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>

* Native: set maximum constraint for MaxValidUntilBlockIncrement

It's set to be a day of 1-second blocks, that should be enough, ref.
neo-project#3861 (comment).

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>

---------

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
Co-authored-by: Shargon <shargon@gmail.com>
Co-authored-by: Will <201105916+Wi1l-B0t@users.noreply.github.com>
Co-authored-by: Christopher Schuchardt <cschuchardt88@gmail.com>
Co-authored-by: Jimmy <jinghui@wayne.edu>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Consensus] Include the consensus time into block interval.