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 block time to 3s #3612

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open

Decrease block time to 3s #3612

wants to merge 12 commits into from

Conversation

vncoelho
Copy link
Member

@vncoelho vncoelho commented Dec 5, 2024

Following a recent request by TC and discussed by Core Devs, here we reduce block time to 3s.
Main modifications:

  1. Modify config files to 3000ms
  2. Modify MaxTransactionsPerBlock to avoid too much load in short time (optional but suggested)
  3. Modify Extend By Factor to improve good behavior bonus avoiding ChangeViews on high latency (optional but suggested)
  4. Modify GAS generation according to the new proposed block time

Positive aspects:

  • This block time of 3s is surely aligned with a NEO standards and what we can provide publicly. However, there will be more storage use, which happens in order to update unclaimed GAS (that happens every block, which could be improved in the future).

Negative aspects:

  • GAS Inflation can be reduced because of an increase on standard deviation on block time, consequently, reducing rewards of CNs, Committee and NEO holders.

@vncoelho
Copy link
Member Author

vncoelho commented Dec 5, 2024

Devcontainer is not working properly, I need it to run tests and adjust public void TestEconomicParameter().

Perhaps we need a Hard Fork at

                engine.SnapshotCache.Add(CreateStorageKey(Prefix_GasPerBlock).AddBigEndian(0u), new StorageItem(5 * GAS.Factor));
                // TODO - Add hardfork otherwise storage will be different
                // After HARD FORK

can you add this HF @shargon ?

"MillisecondsPerBlock": 15000,
"MaxTransactionsPerBlock": 512,
"MillisecondsPerBlock": 3000,
"MaxTransactionsPerBlock": 256,
Copy link
Contributor

Choose a reason for hiding this comment

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

MaxTransactionsPerBlock can be kept as is.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it need to be changed, I think that this comment here contradicts your comment below. I did not understand. You said to cut even more aggressively.

Copy link
Member

Choose a reason for hiding this comment

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

We need to reduce MaxTraceableBlocks, not MaxTransactionsPerBlock.

Copy link
Contributor

Choose a reason for hiding this comment

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

all can be reduced, each block wont be able to process that amount of transactions.

Copy link
Contributor

Choose a reason for hiding this comment

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

C# node can handle several thousands of simple NEP-17 transfers per second. It's all about MaxBlockSystemFee (#3552), not MaxTransactionsPerBlock.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think that for a first release these proposed values are good.
They can be increased easily, the opposite is more complicated in my opnion.
So, I think we should just move forward.

src/Neo.CLI/config.fs.mainnet.json Outdated Show resolved Hide resolved
src/Neo.CLI/config.json Outdated Show resolved Hide resolved
@@ -113,8 +113,8 @@ public record ProtocolSettings
StandbyCommittee = Array.Empty<ECPoint>(),
ValidatorsCount = 0,
SeedList = Array.Empty<string>(),
MillisecondsPerBlock = 15000,
MaxTransactionsPerBlock = 512,
MillisecondsPerBlock = 3000,
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure we need to change defaults.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it is better, @roman-khimov , because it may, in the future, reflect in some of our tests that use default. Better to keep consistent.

Copy link
Member

Choose a reason for hiding this comment

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

Because we will change testnet only before, it's better to avoid default changes

@@ -69,7 +69,7 @@ public record ProtocolSettings
/// <summary>
/// The maximum increment of the <see cref="Transaction.ValidUntilBlock"/> field.
/// </summary>
public uint MaxValidUntilBlockIncrement => 86400000 / MillisecondsPerBlock;
public uint MaxValidUntilBlockIncrement => 86400000 / MillisecondsPerBlock; //TODO keep the same??
Copy link
Contributor

Choose a reason for hiding this comment

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

This one is configurable per-network, so I'd rather leave the default as is and configure particular networks.

Copy link
Member Author

Choose a reason for hiding this comment

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

ok

"MillisecondsPerBlock": 15000,
"MaxTransactionsPerBlock": 5000,
"MillisecondsPerBlock": 3000,
"MaxTransactionsPerBlock": 256,
"MemoryPoolMaxTransactions": 50000,
"MaxTraceableBlocks": 2102400,
Copy link
Contributor

Choose a reason for hiding this comment

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

Notice that it'd be ~73 days instead of current year. But I'd rather cut it down even more aggressively (see FS network settings).

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree, let's say 64 or 128?

Copy link
Contributor

Choose a reason for hiding this comment

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

Opinions are welcome, your values remind me of E-letter chain. Nothing bad about that, but historic data (#2026) suggests our contracts are more used to somewhat longer history available. NeoFS networks use 17280 (3 days of 15s blocks).

@@ -188,6 +188,9 @@ internal override ContractTask InitializeAsync(ApplicationEngine engine, Hardfor
engine.SnapshotCache.Add(CreateStorageKey(Prefix_Committee), new StorageItem(cachedCommittee));
engine.SnapshotCache.Add(CreateStorageKey(Prefix_VotersCount), new StorageItem(System.Array.Empty<byte>()));
engine.SnapshotCache.Add(CreateStorageKey(Prefix_GasPerBlock).AddBigEndian(0u), new StorageItem(5 * GAS.Factor));
// TODO - Add hardfork otherwise storage will be different
// After HARD FORK
engine.SnapshotCache.Add(CreateStorageKey(Prefix_GasPerBlock).AddBigEndian(0u), new StorageItem(5 * GAS.Factor));
Copy link
Contributor

Choose a reason for hiding this comment

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

This also should be kept as is, it's a default and it affects block 0 state changes. And practically this doesn't matter, there is some default, it can be tuned for a particular network. Like people regularly run 1s networks with 5 GASPerBlock networks for tests and it's not an issue.

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe we need a hard fork for new default, but maybe not needed and can be kept simple as you said.

// around 2*15/M=30.0/5 ~ 40% block time (for M=5)
ExtendTimerByFactor(2);
// around 4*3/M=12.0/5 ~ 80% block time (for M=5)
ExtendTimerByFactor(4);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a tricky one. In our tests we have not changed any of these parameters and they look scalable by their nature, if we use lower block times we expect lower waiting times in general as well. So I'd not change them unless we have some real proven need to.

Copy link
Member Author

@vncoelho vncoelho Dec 6, 2024

Choose a reason for hiding this comment

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

This is needed, I have many tests on that for NeoCompiler.
I had also run in the past with server spread along globe.
I suggest these new parameters.
But if you guys do not want to change we can try with original. But this is my recommended for now.

Copy link
Member Author

@vncoelho vncoelho Dec 6, 2024

Choose a reason for hiding this comment

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

@roman-khimov, you are right that this method is really tricky....I remember exactly why we created that....And that is really tricky...aheuaheua Luckly we had this idea during the creation of dBFT 2.0, otherwise (other changes would be necessary)......

@@ -27,7 +27,7 @@ namespace Neo.Plugins.StateService.Verification
{
class VerificationContext
{
private const uint MaxValidUntilBlockIncrement = 100;
private const uint MaxValidUntilBlockIncrement = 100; // Change to 500!??
Copy link
Contributor

Choose a reason for hiding this comment

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

Whoa. Unexpected one. It's totally different from the "regular" MVUBI, but 500 here would let more ExtensiblePayloads with signatures float around the network, I doubt the intention here was to have it related to time.

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 related it with the timeblock

Copy link
Member Author

Choose a reason for hiding this comment

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

I think you guys should decide, that is why I left as comment.

docs/config.json.md Outdated Show resolved Hide resolved
Co-authored-by: Christopher Schuchardt <[email protected]>
@@ -193,7 +193,10 @@ internal override ContractTask InitializeAsync(ApplicationEngine engine, Hardfor
engine.SnapshotCache.Add(CreateStorageKey(Prefix_Committee), new StorageItem(cachedCommittee));
engine.SnapshotCache.Add(_votersCount, new StorageItem(System.Array.Empty<byte>()));
engine.SnapshotCache.Add(CreateStorageKey(Prefix_GasPerBlock).AddBigEndian(0u), new StorageItem(5 * GAS.Factor));
Copy link
Member Author

Choose a reason for hiding this comment

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

ping @shargon

Copy link
Member Author

Choose a reason for hiding this comment

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

I think that maybe it should be enabled with 1 instead of 5 after certain height.
So the hardfork will be triggered by modification the SnapshotCache withnew StorageItem(5 * GAS.Factor);

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 moved to config.json?

Copy link
Contributor

Choose a reason for hiding this comment

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

We can't change it without affecting post-genesis state. And I see zero reason to do this, mainnet/testnet don't care, this will be adjusted by the committee, private networks are fine with whatever default and they can also adjust it if needed.

@Jim8y
Copy link
Contributor

Jim8y commented Dec 11, 2024

@vncoelho the base of this pr should be #3454

@Jim8y
Copy link
Contributor

Jim8y commented Dec 12, 2024

Statistics on the mainnet delay:

100ms Slots:
0-100 ms: 8.68%
100-200 ms: 8.07%
200-300 ms: 4.81%
300-400 ms: 3.34%
400-500 ms: 5.39%
500-600 ms: 6.39%
600-700 ms: 5.44%
700-800 ms: 4.43%
800-900 ms: 4.01%
900-1000 ms: 3.69%
1000-1100 ms: 4.67%
1100-1200 ms: 2.97%
1200-1300 ms: 2.14%
1300-1400 ms: 1.72%
1400-1500 ms: 1.18%
1500-1600 ms: 1.52%
1600-1700 ms: 1.86%
1700-1800 ms: 2.04%
1800-1900 ms: 2.26%
1900-2000 ms: 2.48%
2000-2100 ms: 4.58%
2100-2200 ms: 2.45%
2200-2300 ms: 1.46%
2300-2400 ms: 1.09%
2400-2500 ms: 0.67%
2500-2600 ms: 0.95%
2600-2700 ms: 0.99%
2700-2800 ms: 1.01%
2800-2900 ms: 1.08%
2900-3000 ms: 1.17%
3000-3100 ms: 2.40%
3100-3200 ms: 0.92%
3200-3300 ms: 0.48%
3300-3400 ms: 0.33%
3400-3500 ms: 0.17%
3500-3600 ms: 0.28%
3600-3700 ms: 0.22%
3700-3800 ms: 0.21%
3800-3900 ms: 0.22%
3900-4000 ms: 0.23%
4000-4100 ms: 0.51%
4100-4200 ms: 0.14%
4200-4300 ms: 0.07%
4300-4400 ms: 0.06%
4400-4500 ms: 0.03%
4500-4600 ms: 0.05%
4600-4700 ms: 0.04%
4700-4800 ms: 0.04%
4800-4900 ms: 0.04%
4900-5000 ms: 0.04%
5000-5100 ms: 0.08%

500ms Slots:
0-500 ms: 30.29%
500-1000 ms: 23.95%
1000-1500 ms: 12.69%
1500-2000 ms: 10.17%
2000-2500 ms: 10.26%
2500-3000 ms: 5.20%
3000-3500 ms: 4.31%
3500-4000 ms: 1.15%
4000-4500 ms: 0.81%
4500-5000 ms: 0.20%
5000-5500 ms: 0.14%

1000ms Slots:
0-1000 ms: 54.24%
1000-2000 ms: 22.86%
2000-3000 ms: 15.46%
3000-4000 ms: 5.47%
4000-5000 ms: 1.02%
5000-6000 ms: 0.22%

src/Neo.CLI/config.json Outdated Show resolved Hide resolved
// around 2*15/M=30.0/5 ~ 40% block time (for M=5)
ExtendTimerByFactor(2);
// around 4*3/M=12.0/5 ~ 80% block time (for M=5)
ExtendTimerByFactor(4);
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 computed according the configured time per block

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.

6 participants