From 7fe5b73abb733b77a905cdfa16e858204967e329 Mon Sep 17 00:00:00 2001 From: Huy Ngo Date: Mon, 21 Oct 2024 13:23:01 +0700 Subject: [PATCH 1/4] cmd,eth: fix wrong compare logic when data dir is empty and moving checking error correctly --- cmd/utils/flags.go | 2 +- eth/backend.go | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 2e070815b..8f480b9c1 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -2441,7 +2441,7 @@ func ParseStateScheme(ctx *cli.Context, disk ethdb.Database) (string, error) { // If state scheme is specified, ensure it's compatible with // persistent state. scheme := ctx.String(StateSchemeFlag.Name) - if stored != "" || scheme == stored { + if stored == "" || scheme == stored { log.Info("State scheme set by user", "scheme", scheme) return scheme, nil } diff --git a/eth/backend.go b/eth/backend.go index 12cdafeb3..6345ad809 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -207,11 +207,12 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) { } ) eth.blockchain, err = core.NewBlockChain(chainDb, cacheConfig, config.Genesis, config.OverrideArrowGlacier, eth.engine, vmConfig, eth.shouldPreserve, &config.TransactionHistory) - chainConfig := eth.blockchain.Config() - genesisHash := eth.blockchain.Genesis().Hash() if err != nil { return nil, err } + chainConfig := eth.blockchain.Config() + genesisHash := eth.blockchain.Genesis().Hash() + if config.EnableMonitorDoubleSign { go eth.blockchain.StartDoubleSignMonitor() } From d7f7646c4728fc4c6874b7d9716412c47e6b8db7 Mon Sep 17 00:00:00 2001 From: Huy Ngo Date: Mon, 21 Oct 2024 13:27:18 +0700 Subject: [PATCH 2/4] docker: passing state.scheme when initing the genesis data --- docker/chainnode/entrypoint.sh | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/docker/chainnode/entrypoint.sh b/docker/chainnode/entrypoint.sh index b1825f88f..095cfdc37 100755 --- a/docker/chainnode/entrypoint.sh +++ b/docker/chainnode/entrypoint.sh @@ -29,6 +29,7 @@ params="" syncmode="snap" mine="true" blsParams="" +state_scheme="hash" set -e @@ -48,6 +49,11 @@ if [[ ! -z $WS_PORT ]]; then ws_port="$WS_PORT" fi +if [[ ! -z $STATE_SCHEME ]]; then + state_scheme="$STATE_SCHEME" +fi + + # networkid if [[ ! -z $NETWORK_ID ]]; then case $NETWORK_ID in @@ -78,15 +84,14 @@ fi # data dir if [[ ! -d $datadir/ronin ]]; then - echo "No blockchain data, creating genesis block." - ronin init $dbEngine --datadir $datadir $genesisPath 2> /dev/null + echo "No blockchain data, creating genesis block with $genesisPath, state_scheme $state_scheme ..." + ronin init $dbEngine --datadir $datadir --state.scheme $state_scheme $genesisPath $genesisPath elif [[ "$FORCE_INIT" = "true" && "$INIT_FORCE_OVERRIDE_CHAIN_CONFIG" = "true" ]]; then - echo "Forcing update chain config with force overriding chain config." - ronin init $dbEngine --overrideChainConfig --datadir $datadir $genesisPath 2> /dev/null + echo "Forcing update chain config with force overriding chain config with $genesisPath, state_scheme $state_scheme ..." + ronin init $dbEngine --overrideChainConfig --datadir $datadir --state.scheme $state_scheme $genesisPath elif [ "$FORCE_INIT" = "true" ]; then - echo "Forcing update chain config." - ronin init $dbEngine --datadir $datadir $genesisPath 2> /dev/null -fi + echo "Forcing update chain config with $genesisPath, state_scheme $state_scheme ..." + ronin init $dbEngine --datadir $datadir --state.scheme $state_scheme $genesisPath # password file if [[ ! -f $PASSWORD_FILE ]]; then @@ -333,6 +338,9 @@ if [[ "$BLS_SHOW_PRIVATE_KEY" = "true" ]]; then --finality.blswalletpath $BLS_PRIVATE_KEY_DIR \ --secret fi +echo "---------------------------------" +echo "Starting the Ronin Node" +echo "---------------------------------" exec ronin $params \ --syncmode $syncmode \ From d65d43ad08c9ed7547f567ec95303c501af8008c Mon Sep 17 00:00:00 2001 From: Huy Ngo Date: Thu, 24 Oct 2024 17:52:07 +0700 Subject: [PATCH 3/4] rawdb: add missing freezer in collections --- core/rawdb/ancient_scheme.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/rawdb/ancient_scheme.go b/core/rawdb/ancient_scheme.go index 2773d3611..0e6d4bea5 100644 --- a/core/rawdb/ancient_scheme.go +++ b/core/rawdb/ancient_scheme.go @@ -78,7 +78,7 @@ var ( ) // freezers the collections of all builtin freezers. -var freezers = []string{chainFreezerName} +var freezers = []string{chainFreezerName, stateFreezerName} // NewStateFreezer initializes the freezer for state history. func NewStateFreezer(ancientDir string, readOnly bool) (*ResettableFreezer, error) { From 2808b881d65e775355c877227c1088a1fd23324e Mon Sep 17 00:00:00 2001 From: Francesco4203 Date: Fri, 25 Oct 2024 13:50:44 +0700 Subject: [PATCH 4/4] v1/consortium: create a copy to keep parents content In snapshot function, the list parents is popped out gradually for getting its contents, so when calling apply, the parents list is empty. Simply create a copy at the beginning to fix it. This has been fixed in consortium v2. For a full sync scenario, however, the first blocks are still processed with consortium v1, which causes our node to panic. --- consensus/consortium/v1/consortium.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/consensus/consortium/v1/consortium.go b/consensus/consortium/v1/consortium.go index f20827585..dee4b9c32 100644 --- a/consensus/consortium/v1/consortium.go +++ b/consensus/consortium/v1/consortium.go @@ -308,9 +308,13 @@ func (c *Consortium) verifyCascadingFields(chain consensus.ChainHeaderReader, he func (c *Consortium) snapshot(chain consensus.ChainHeaderReader, number uint64, hash common.Hash, parents []*types.Header) (*Snapshot, error) { // Search for a snapshot in memory or on disk for checkpoints var ( - headers []*types.Header - snap *Snapshot + headers []*types.Header + snap *Snapshot + cpyParents = make([]*types.Header, len(parents)) ) + // We must copy parents before going to the loop because parents are modified. + // If not, the FindAncientHeader function can not find its block ancestor + copy(cpyParents, parents) for snap == nil { // If an in-memory snapshot was found, use that if s, ok := c.recents.Get(hash); ok { @@ -370,7 +374,7 @@ func (c *Consortium) snapshot(chain consensus.ChainHeaderReader, number uint64, for i := 0; i < len(headers)/2; i++ { headers[i], headers[len(headers)-1-i] = headers[len(headers)-1-i], headers[i] } - snap, err := snap.apply(chain, c, headers, parents) + snap, err := snap.apply(chain, c, headers, cpyParents) if err != nil { return nil, err }