@@ -116,9 +116,11 @@ func ReadGenesis(db ethdb.Database) (*Genesis, error) {
116116 genesis .BaseFee = genesisHeader .BaseFee
117117 genesis .ExcessBlobGas = genesisHeader .ExcessBlobGas
118118 genesis .BlobGasUsed = genesisHeader .BlobGasUsed
119- if genesis .Alloc == nil {
120- h := genesisHeader .Hash ()
119+ // A nil or empty alloc, with a non-matching state-root in the block header, intents to override the state-root.
120+ if genesis .Alloc == nil || (len (genesis .Alloc ) == 0 && genesisHeader .Root != types .EmptyRootHash ) {
121+ h := genesisHeader .Root // the genesis block is encoded as RLP in the DB and will contain the state-root
121122 genesis .StateHash = & h
123+ genesis .Alloc = nil
122124 }
123125
124126 return & genesis , nil
@@ -567,12 +569,23 @@ func (g *Genesis) Commit(db ethdb.Database, triedb *triedb.Database) (*types.Blo
567569 if config .Clique != nil && len (g .ExtraData ) < 32 + crypto .SignatureLength {
568570 return nil , errors .New ("can't start clique chain without signers" )
569571 }
570- // flush the data to disk and compute the state root
571- root , err := flushAlloc (& g .Alloc , triedb )
572- if err != nil {
573- return nil , err
572+ var stateHash common.Hash
573+ if len (g .Alloc ) == 0 {
574+ if g .StateHash == nil {
575+ log .Warn ("Empty genesis alloc, and no 'stateHash' override was set" )
576+ stateHash = types .EmptyRootHash // default to the hash of the empty state. Some unit-tests rely on this.
577+ } else {
578+ stateHash = * g .StateHash
579+ }
580+ } else {
581+ // flush the data to disk and compute the state root
582+ root , err := flushAlloc (& g .Alloc , triedb )
583+ if err != nil {
584+ return nil , err
585+ }
586+ stateHash = root
574587 }
575- block := g .toBlockWithRoot (root )
588+ block := g .toBlockWithRoot (stateHash )
576589
577590 // Marshal the genesis state specification and persist.
578591 blob , err := json .Marshal (g .Alloc )
0 commit comments