@@ -102,8 +102,7 @@ type StateDB struct {
102102 // Per-transaction access list
103103 accessList * accessList
104104
105- // Stateless locations for this block
106- stateless map [common.Hash ]common.Hash
105+ witness * types.AccessWitness
107106
108107 // Journal of state modifications. This is the backbone of
109108 // Snapshot and RevertToSnapshot.
@@ -149,6 +148,7 @@ func New(root common.Hash, db Database, snaps *snapshot.Tree) (*StateDB, error)
149148 journal : newJournal (),
150149 accessList : newAccessList (),
151150 hasher : crypto .NewKeccakState (),
151+ witness : types .NewAccessWitness (),
152152 }
153153 if sdb .snaps == nil && tr .IsVerkle () {
154154 sdb .snaps , err = snapshot .New (db .TrieDB ().DiskDB (), db .TrieDB (), 1 , root , false , true , false , true )
@@ -166,6 +166,14 @@ func New(root common.Hash, db Database, snaps *snapshot.Tree) (*StateDB, error)
166166 return sdb , nil
167167}
168168
169+ func (s * StateDB ) Witness () * types.AccessWitness {
170+ return s .witness
171+ }
172+
173+ func (s * StateDB ) SetWitness (aw * types.AccessWitness ) {
174+ s .witness = aw
175+ }
176+
169177// StartPrefetcher initializes a new trie prefetcher to pull in nodes from the
170178// state trie concurrently while the state is mutated so that when we reach the
171179// commit phase, most of the needed data is already hot.
@@ -423,12 +431,6 @@ func (s *StateDB) SetCode(addr common.Address, code []byte) {
423431 }
424432}
425433
426- // SetStateless sets the vales recovered from the execution of a stateless
427- // block.
428- func (s * StateDB ) SetStateless (leaves map [common.Hash ]common.Hash ) {
429- s .stateless = leaves
430- }
431-
432434func (s * StateDB ) SetState (addr common.Address , key , value common.Hash ) {
433435 stateObject := s .GetOrNewStateObject (addr )
434436 if stateObject != nil {
@@ -470,46 +472,6 @@ func (s *StateDB) Suicide(addr common.Address) bool {
470472// Setting, updating & deleting state object methods.
471473//
472474
473- func (s * StateDB ) updateStatelessStateObject (obj * stateObject ) {
474- addr := obj .Address ()
475-
476- var (
477- ok bool
478- n common.Hash
479- v common.Hash
480- b common.Hash
481- cs common.Hash
482- ch common.Hash
483- )
484-
485- versionKey := common .BytesToHash (trieUtils .GetTreeKeyVersion (addr [:]))
486- if v , ok = s .stateless [versionKey ]; ok {
487- nonceKey := common .BytesToHash (trieUtils .GetTreeKeyNonce (addr [:]))
488- if n , ok = s .stateless [nonceKey ]; ok {
489- balanceKey := common .BytesToHash (trieUtils .GetTreeKeyBalance (addr [:]))
490- if b , ok = s .stateless [balanceKey ]; ok {
491- codeHashKey := common .BytesToHash (trieUtils .GetTreeKeyCodeKeccak (addr [:]))
492- if _ , ok = s .stateless [codeHashKey ]; ok {
493- v [0 ] = byte (0 )
494- binary .BigEndian .PutUint64 (n [:], obj .data .Nonce )
495- copy (ch [:], obj .data .CodeHash [:])
496- copy (b [:], obj .data .Balance .Bytes ())
497- binary .BigEndian .PutUint64 (cs [:], uint64 (len (obj .code )))
498-
499- // TODO(@gballet) stateless tree update
500- // i.e. perform a "delta" update on all
501- // commitments. go-verkle currently has
502- // no support for these.
503- }
504- }
505- }
506- }
507-
508- if ! ok {
509- s .setError (fmt .Errorf ("updateStatelessStateObject (%x) missing" , addr [:]))
510- }
511- }
512-
513475// updateStateObject writes the given object to the trie.
514476func (s * StateDB ) updateStateObject (obj * stateObject ) {
515477 // Track the amount of time wasted on updating the account from the trie
@@ -519,12 +481,6 @@ func (s *StateDB) updateStateObject(obj *stateObject) {
519481 // Encode the account and update the account trie
520482 addr := obj .Address ()
521483
522- // bypass the snapshot and writing to tree if in stateless mode
523- if s .stateless != nil {
524- s .updateStatelessStateObject (obj )
525- return
526- }
527-
528484 if err := s .trie .TryUpdateAccount (addr [:], & obj .data ); err != nil {
529485 s .setError (fmt .Errorf ("updateStateObject (%x) error: %w" , addr [:], err ))
530486 }
@@ -534,6 +490,16 @@ func (s *StateDB) updateStateObject(obj *stateObject) {
534490 if err := s .trie .TryUpdate (trieUtils .GetTreeKeyCodeSize (addr [:]), cs ); err != nil {
535491 s .setError (fmt .Errorf ("updateStateObject (%x) error: %w" , addr [:], err ))
536492 }
493+
494+ if obj .dirtyCode {
495+ if chunks , err := trie .ChunkifyCode (addr , obj .code ); err == nil {
496+ for i := range chunks {
497+ s .trie .TryUpdate (trieUtils .GetTreeKeyCodeChunk (addr [:], uint256 .NewInt (uint64 (i ))), chunks [i ][:])
498+ }
499+ } else {
500+ s .setError (err )
501+ }
502+ }
537503 }
538504
539505 // If state snapshotting is active, cache the data til commit. Note, this
@@ -545,21 +511,12 @@ func (s *StateDB) updateStateObject(obj *stateObject) {
545511 }
546512}
547513
548- func (s * StateDB ) deleteStatelessStateObject (obj * stateObject ) {
549- // unsupported
550- panic ("not currently supported" )
551- }
552-
553514// deleteStateObject removes the given object from the state trie.
554515func (s * StateDB ) deleteStateObject (obj * stateObject ) {
555516 // Track the amount of time wasted on deleting the account from the trie
556517 if metrics .EnabledExpensive {
557518 defer func (start time.Time ) { s .AccountUpdates += time .Since (start ) }(time .Now ())
558519 }
559- if s .stateless != nil {
560- s .deleteStatelessStateObject (obj )
561- return
562- }
563520
564521 // Delete the account from the trie
565522 if ! s .trie .IsVerkle () {
@@ -586,48 +543,6 @@ func (s *StateDB) getStateObject(addr common.Address) *stateObject {
586543 return nil
587544}
588545
589- func (s * StateDB ) getStatelessDeletedStateObject (addr common.Address ) * stateObject {
590- // Check that it is present in the witness, if running
591- // in stateless execution mode.
592- chunk := trieUtils .GetTreeKeyNonce (addr [:])
593- nb , ok := s .stateless [common .BytesToHash (chunk )]
594- if ! ok {
595- log .Error ("Failed to decode state object" , "addr" , addr )
596- s .setError (fmt .Errorf ("could not find nonce chunk in proof: %x" , chunk ))
597- // TODO(gballet) remove after debug, and check the issue is found
598- panic ("inivalid chunk" )
599- return nil
600- }
601- chunk = trieUtils .GetTreeKeyBalance (addr [:])
602- bb , ok := s .stateless [common .BytesToHash (chunk )]
603- if ! ok {
604- log .Error ("Failed to decode state object" , "addr" , addr )
605- s .setError (fmt .Errorf ("could not find balance chunk in proof: %x" , chunk ))
606- // TODO(gballet) remove after debug, and check the issue is found
607- panic ("inivalid chunk" )
608- return nil
609- }
610- chunk = trieUtils .GetTreeKeyCodeKeccak (addr [:])
611- cb , ok := s .stateless [common .BytesToHash (chunk )]
612- if ! ok {
613- // Assume that this is an externally-owned account, and that
614- // the code has not been accessed.
615- // TODO(gballet) write this down, just like deletions, so
616- // that an error can be triggered if trying to access the
617- // account code.
618- copy (cb [:], emptyCodeHash )
619- }
620- data := & types.StateAccount {
621- Nonce : binary .BigEndian .Uint64 (nb [:8 ]),
622- Balance : big .NewInt (0 ).SetBytes (bb [:]),
623- CodeHash : cb [:],
624- }
625- // Insert into the live set
626- obj := newObject (s , addr , * data )
627- s .setStateObject (obj )
628- return obj
629- }
630-
631546// getDeletedStateObject is similar to getStateObject, but instead of returning
632547// nil for a deleted state object, it returns the actual object with the deleted
633548// flag set. This is needed by the state journal to revert to the correct s-
@@ -642,10 +557,6 @@ func (s *StateDB) getDeletedStateObject(addr common.Address) *stateObject {
642557 data * types.StateAccount
643558 err error
644559 )
645- // if executing statelessly, bypass the snapshot and the db.
646- if s .stateless != nil {
647- return s .getStatelessDeletedStateObject (addr )
648- }
649560 if s .snap != nil {
650561 if metrics .EnabledExpensive {
651562 defer func (start time.Time ) { s .SnapshotAccountReads += time .Since (start ) }(time .Now ())
@@ -802,6 +713,7 @@ func (s *StateDB) Copy() *StateDB {
802713 preimages : make (map [common.Hash ][]byte , len (s .preimages )),
803714 journal : newJournal (),
804715 hasher : crypto .NewKeccakState (),
716+ witness : s .witness .Copy (),
805717 }
806718 // Copy the dirty states, logs, and preimages
807719 for addr := range s .journal .dirties {
@@ -852,13 +764,6 @@ func (s *StateDB) Copy() *StateDB {
852764 // to not blow up if we ever decide copy it in the middle of a transaction
853765 state .accessList = s .accessList .Copy ()
854766
855- if s .stateless != nil {
856- state .stateless = make (map [common.Hash ]common.Hash , len (s .stateless ))
857- for addr , value := range s .stateless {
858- state .stateless [addr ] = value
859- }
860- }
861-
862767 // If there's a prefetcher running, make an inactive copy of it that can
863768 // only access data but does not actively preload (since the user will not
864769 // know that they need to explicitly terminate an active copy).
@@ -1088,8 +993,8 @@ func (s *StateDB) Commit(deleteEmptyObjects bool) (common.Hash, error) {
1088993 if obj .code != nil && obj .dirtyCode {
1089994 if s .trie .IsVerkle () {
1090995 if chunks , err := trie .ChunkifyCode (addr , obj .code ); err == nil {
1091- for i , chunk := range chunks {
1092- s .trie .TryUpdate (trieUtils .GetTreeKeyCodeChunk (addr [:], uint256 .NewInt (uint64 (i ))), chunk [:])
996+ for i := range chunks {
997+ s .trie .TryUpdate (trieUtils .GetTreeKeyCodeChunk (addr [:], uint256 .NewInt (uint64 (i ))), chunks [ i ] [:])
1093998 }
1094999 } else {
10951000 s .setError (err )
0 commit comments