forked from ethereum/go-ethereum
-
Notifications
You must be signed in to change notification settings - Fork 13
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
fix: a branch that can verge at genesis or post genesis #314
Merged
gballet
merged 1 commit into
refactor-transition-post-genesis
from
verge-at-genesis-or-not
Nov 30, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,6 +126,7 @@ func (ga *GenesisAlloc) deriveHash(cfg *params.ChainConfig, timestamp uint64) (c | |
// all the derived states will be discarded to not pollute disk. | ||
db := state.NewDatabase(rawdb.NewMemoryDatabase()) | ||
if cfg.IsPrague(big.NewInt(int64(0)), timestamp) { | ||
db.StartVerkleTransition(common.Hash{}, common.Hash{}, cfg, ×tamp, common.Hash{}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. force verkle start so that |
||
db.EndVerkleTransition() | ||
} | ||
statedb, err := state.New(types.EmptyRootHash, db, nil) | ||
|
@@ -146,15 +147,17 @@ func (ga *GenesisAlloc) deriveHash(cfg *params.ChainConfig, timestamp uint64) (c | |
// flush is very similar with deriveHash, but the main difference is | ||
// all the generated states will be persisted into the given database. | ||
// Also, the genesis state specification will be flushed as well. | ||
func (ga *GenesisAlloc) flush(db ethdb.Database, triedb *trie.Database, blockhash common.Hash, cfg *params.ChainConfig) error { | ||
statedb, err := state.New(types.EmptyRootHash, state.NewDatabaseWithNodeDB(db, triedb), nil) | ||
if err != nil { | ||
return err | ||
func (ga *GenesisAlloc) flush(db ethdb.Database, triedb *trie.Database, blockhash common.Hash, cfg *params.ChainConfig, timestamp *uint64) error { | ||
database := state.NewDatabaseWithNodeDB(db, triedb) | ||
// End the verkle conversion at genesis if the fork block is 0 | ||
if timestamp != nil && cfg.IsPrague(big.NewInt(int64(0)), *timestamp) { | ||
database.StartVerkleTransition(common.Hash{}, common.Hash{}, cfg, timestamp, common.Hash{}) | ||
database.EndVerkleTransition() | ||
} | ||
|
||
// End the verkle conversion at genesis if the fork block is 0 | ||
if triedb.IsVerkle() { | ||
statedb.Database().EndVerkleTransition() | ||
statedb, err := state.New(types.EmptyRootHash, database, nil) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for addr, account := range *ga { | ||
|
@@ -221,7 +224,7 @@ func CommitGenesisState(db ethdb.Database, triedb *trie.Database, blockhash comm | |
return errors.New("not found") | ||
} | ||
} | ||
return alloc.flush(db, triedb, blockhash, config) | ||
return alloc.flush(db, triedb, blockhash, config, nil) | ||
} | ||
|
||
// GenesisAccount is an account in the state of the genesis block. | ||
|
@@ -456,6 +459,12 @@ func (g *Genesis) configOrDefault(ghash common.Hash) *params.ChainConfig { | |
} | ||
} | ||
|
||
// IsVerkle indicates whether the state is already stored in a verkle | ||
// tree at genesis time. | ||
func (g *Genesis) IsVerkle() bool { | ||
return g.Config.IsPrague(new(big.Int).SetUint64(g.Number), g.Timestamp) | ||
} | ||
|
||
// ToBlock returns the genesis block according to genesis specification. | ||
func (g *Genesis) ToBlock() *types.Block { | ||
root, err := g.Alloc.deriveHash(g.Config, g.Timestamp) | ||
|
@@ -530,7 +539,7 @@ func (g *Genesis) Commit(db ethdb.Database, triedb *trie.Database) (*types.Block | |
// All the checks has passed, flush the states derived from the genesis | ||
// specification as well as the specification itself into the provided | ||
// database. | ||
if err := g.Alloc.flush(db, triedb, block.Hash(), g.Config); err != nil { | ||
if err := g.Alloc.flush(db, triedb, block.Hash(), g.Config, &g.Timestamp); err != nil { | ||
return nil, err | ||
} | ||
rawdb.WriteTd(db, block.Hash(), block.NumberU64(), block.Difficulty()) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be modified to load
ended
andstarted
from the db, as well as all theCurrent*
fields.