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

[consortium-v1] Get list validators from genesis instead of statedb for snapsync. #624

Conversation

huyngopt1994
Copy link
Collaborator

@huyngopt1994 huyngopt1994 commented Oct 31, 2024

Related to recent PR merged to path-base implementing #614

State sync overwrites the persistent state, and this action can disrupt states that reference the current persistent state. The appropriate solution in such a situation is to mark the entire trie database as unusable, which prevents any subsequent state reads, and raises a layer stale error if the read operation is done by the prev-created stale state. The trie database will remain in this state until the state sync process is completed, and a usable persistent state is assembled.

In the coming enhancements related to avoid disruption genesis data in the snap sync with path schem enable. In the Ronin implementing, we have some functions for getting Validators from StateDB during snap sync which violate this approach.

	// set SCValidators function before initiating new miner to prevent miner starts without SCValidators
	if chainConfig.Consortium != nil {
		c := eth.engine.(*consortium.Consortium)
		stack.RegisterAPIs(c.APIs(eth.blockchain))
		c.SetGetSCValidatorsFn(func() ([]common.Address, error) {
			stateDb, err := eth.blockchain.State()
			if err != nil {
				log.Crit("Cannot get state of blockchain", "err", err)
				return nil, err
			}
			return state.GetSCValidators(stateDb), nil
		})

	if mode == SnapSync {
		if !d.snapSync {
			// Snap sync will directly modify the persistent state, making the entire
			// trie database unusable until the state is fully synced. To prevent any
			// subsequent state reads, explicitly disable the trie database and state
			// syncer is responsible to address and correct any state missing.
			if d.blockchain.TrieDB().Scheme() == rawdb.PathScheme {
				if err := d.blockchain.TrieDB().Disable(); err != nil {
					return err
				}
			}

@huyngopt1994 huyngopt1994 changed the base branch from master to path-base-implementing October 31, 2024 10:25
@huyngopt1994 huyngopt1994 force-pushed the getlistValidatorsfromGenesis-for-snapsync branch from 060c64e to 249be04 Compare October 31, 2024 10:29
consensus/consortium/v1/consortium.go Outdated Show resolved Hide resolved
consensus/consortium/v1/consortium.go Outdated Show resolved Hide resolved
consensus/consortium/v1/consortium.go Outdated Show resolved Hide resolved
@huyngopt1994 huyngopt1994 force-pushed the getlistValidatorsfromGenesis-for-snapsync branch 3 times, most recently from 9371dbb to dea1363 Compare November 1, 2024 08:28
@minh-bq
Copy link
Contributor

minh-bq commented Nov 1, 2024

nit: In the commit message, can we have commit title + newline + commit description? Right now we have commit title + commit description without newline in between.

…tium.

In snap sync, we will disable accessing/mark stale to triedb when enabling path scheme for protecting the persistent storing, so the data of validators only used for checking in some first blocks which we can return hardcore list from genesis data for following the flow of snap-sync  from go-eth team.
@huyngopt1994 huyngopt1994 force-pushed the getlistValidatorsfromGenesis-for-snapsync branch from dea1363 to a86158d Compare November 1, 2024 09:03
@huyngopt1994 huyngopt1994 merged commit b3f452a into path-base-implementing Nov 1, 2024
1 check passed
huyngopt1994 added a commit that referenced this pull request Nov 21, 2024
…tium. (#624)

In snap sync, we will disable accessing/mark stale to triedb when enabling path scheme for protecting the persistent storing, so the data of validators only used for checking in some first blocks which we can return hardcore list from genesis data for following the flow of snap-sync  from go-eth team.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants