Skip to content

Commit

Permalink
Fix missing passing scheme when init genesis and avoid referencing sa…
Browse files Browse the repository at this point in the history
…me object when passing parents in cosortium v1 (#608)

* cmd,eth: fix wrong compare logic when data dir is empty and moving checking error correctly

* docker: passing state.scheme when initing the genesis data

* rawdb: add missing freezer in collections

* 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.

---------

Co-authored-by: Francesco4203 <[email protected]>
  • Loading branch information
huyngopt1994 and Francesco4203 committed Oct 25, 2024
1 parent 14ecb1b commit e42b5b8
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 14 deletions.
2 changes: 1 addition & 1 deletion cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
10 changes: 7 additions & 3 deletions consensus/consortium/v1/consortium.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion core/rawdb/ancient_scheme.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
22 changes: 15 additions & 7 deletions docker/chainnode/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ params=""
syncmode="snap"
mine="true"
blsParams=""
state_scheme="hash"

set -e

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 \
Expand Down
5 changes: 3 additions & 2 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down

0 comments on commit e42b5b8

Please sign in to comment.