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] optimize the resync process #3540

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
8 changes: 8 additions & 0 deletions src/Neo.CLI/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@
"seed3.neo.org:10333",
"seed4.neo.org:10333",
"seed5.neo.org:10333"
],
"CheckPoint": [
"0x7339b8a32e6ff7e8affbbb7a7be62d95f09c7a9426f2bea582d910f2228fded0",
"0xbcb5d0b779c80b0339266cceaf33aebe9d6eb20e8d0cfcc8c8a5d3718d1247ea",
"0x153bc34532f29cd729a9015cf5b69950f9577787789f5f1bc26c4647273426fc",
"0xcad42b6bcbcbff165f862df442280c07f73ad263bd28b6fd60722a8ae7a9318b",
"0xa56a4bf59a7cec3df965c77d943a2c74a94b8117598fea6b35004f394c918e32",
"0x0e23f98c7e9eb2bac066f759009d06daf61c82ede43ae8d9d80e49bd7bdf9b57"
]
}
}
8 changes: 8 additions & 0 deletions src/Neo.CLI/config.mainnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@
"seed3.neo.org:10333",
"seed4.neo.org:10333",
"seed5.neo.org:10333"
],
"CheckPoint": [
"0x7339b8a32e6ff7e8affbbb7a7be62d95f09c7a9426f2bea582d910f2228fded0",
"0xbcb5d0b779c80b0339266cceaf33aebe9d6eb20e8d0cfcc8c8a5d3718d1247ea",
"0x153bc34532f29cd729a9015cf5b69950f9577787789f5f1bc26c4647273426fc",
"0xcad42b6bcbcbff165f862df442280c07f73ad263bd28b6fd60722a8ae7a9318b",
"0xa56a4bf59a7cec3df965c77d943a2c74a94b8117598fea6b35004f394c918e32",
"0x0e23f98c7e9eb2bac066f759009d06daf61c82ede43ae8d9d80e49bd7bdf9b57"
]
}
}
24 changes: 22 additions & 2 deletions src/Neo/Ledger/Blockchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using Neo.SmartContract;
using Neo.SmartContract.Native;
using Neo.VM;
using Neo.Wallets;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
Expand Down Expand Up @@ -160,8 +161,26 @@ private void OnImport(IEnumerable<Block> blocks, bool verify)
if (block.Index <= currentHeight) continue;
if (block.Index != currentHeight + 1)
throw new InvalidOperationException();
if (verify && !block.Verify(system.Settings, system.StoreView))
throw new InvalidOperationException();

if (verify)
{
const int CheckpointInterval = 1_000_000;
var maxCheckpoint = system.Settings.CheckPoint.Count * CheckpointInterval;
if (block.Index % CheckpointInterval == 0 && block.Index >= CheckpointInterval && block.Index <= maxCheckpoint)
{
var checkpointIndex = (int)(block.Index / CheckpointInterval - 1);
if (system.Settings.CheckPoint[checkpointIndex] != block.Hash.ToString())
{
throw new InvalidOperationException("Invalid block hash for checkpoint.");
}
}

if (!block.Verify(system.Settings, system.StoreView))
{
throw new InvalidOperationException("Block verification failed.");
}
}

Persist(block);
++currentHeight;
}
Expand Down Expand Up @@ -475,6 +494,7 @@ private void Persist(Block block)
}
InvokeCommitted(system, block);
system.MemPool.UpdatePoolForBlockPersisted(block, system.StoreView);

extensibleWitnessWhiteList = null;
block_cache.Remove(block.PrevHash);
Context.System.EventStream.Publish(new PersistCompleted { Block = block });
Expand Down
8 changes: 6 additions & 2 deletions src/Neo/ProtocolSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ public record ProtocolSettings
/// </summary>
public IReadOnlyList<ECPoint> StandbyValidators => _standbyValidators ??= StandbyCommittee.Take(ValidatorsCount).ToArray();

public List<string> CheckPoint { get; private init; }

/// <summary>
/// The default protocol settings for NEO MainNet.
/// </summary>
Expand All @@ -118,7 +120,8 @@ public record ProtocolSettings
MemoryPoolMaxTransactions = 50_000,
MaxTraceableBlocks = 2_102_400,
InitialGasDistribution = 52_000_000_00000000,
Hardforks = EnsureOmmitedHardforks(new Dictionary<Hardfork, uint>()).ToImmutableDictionary()
Hardforks = EnsureOmmitedHardforks(new Dictionary<Hardfork, uint>()).ToImmutableDictionary(),
CheckPoint = []
};

public static ProtocolSettings Custom { get; set; }
Expand Down Expand Up @@ -163,7 +166,8 @@ public static ProtocolSettings Load(IConfigurationSection section)
InitialGasDistribution = section.GetValue("InitialGasDistribution", Default.InitialGasDistribution),
Hardforks = section.GetSection("Hardforks").Exists()
? EnsureOmmitedHardforks(section.GetSection("Hardforks").GetChildren().ToDictionary(p => Enum.Parse<Hardfork>(p.Key, true), p => uint.Parse(p.Value))).ToImmutableDictionary()
: Default.Hardforks
: Default.Hardforks,
CheckPoint = section.GetSection("CheckPoint").GetChildren().Select(p => p.Value).ToList()
Copy link
Member

Choose a reason for hiding this comment

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

You could make a class for this json to be bind on

};
return Custom;
}
Expand Down
Loading