@@ -102,8 +102,7 @@ type StateDB struct {
102
102
// Per-transaction access list
103
103
accessList * accessList
104
104
105
- // Stateless locations for this block
106
- stateless map [common.Hash ]common.Hash
105
+ witness * types.AccessWitness
107
106
108
107
// Journal of state modifications. This is the backbone of
109
108
// Snapshot and RevertToSnapshot.
@@ -149,6 +148,7 @@ func New(root common.Hash, db Database, snaps *snapshot.Tree) (*StateDB, error)
149
148
journal : newJournal (),
150
149
accessList : newAccessList (),
151
150
hasher : crypto .NewKeccakState (),
151
+ witness : types .NewAccessWitness (),
152
152
}
153
153
if sdb .snaps == nil && tr .IsVerkle () {
154
154
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)
166
166
return sdb , nil
167
167
}
168
168
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
+
169
177
// StartPrefetcher initializes a new trie prefetcher to pull in nodes from the
170
178
// state trie concurrently while the state is mutated so that when we reach the
171
179
// commit phase, most of the needed data is already hot.
@@ -423,12 +431,6 @@ func (s *StateDB) SetCode(addr common.Address, code []byte) {
423
431
}
424
432
}
425
433
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
-
432
434
func (s * StateDB ) SetState (addr common.Address , key , value common.Hash ) {
433
435
stateObject := s .GetOrNewStateObject (addr )
434
436
if stateObject != nil {
@@ -470,46 +472,6 @@ func (s *StateDB) Suicide(addr common.Address) bool {
470
472
// Setting, updating & deleting state object methods.
471
473
//
472
474
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
-
513
475
// updateStateObject writes the given object to the trie.
514
476
func (s * StateDB ) updateStateObject (obj * stateObject ) {
515
477
// Track the amount of time wasted on updating the account from the trie
@@ -519,12 +481,6 @@ func (s *StateDB) updateStateObject(obj *stateObject) {
519
481
// Encode the account and update the account trie
520
482
addr := obj .Address ()
521
483
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
-
528
484
if err := s .trie .TryUpdateAccount (addr [:], & obj .data ); err != nil {
529
485
s .setError (fmt .Errorf ("updateStateObject (%x) error: %w" , addr [:], err ))
530
486
}
@@ -534,6 +490,16 @@ func (s *StateDB) updateStateObject(obj *stateObject) {
534
490
if err := s .trie .TryUpdate (trieUtils .GetTreeKeyCodeSize (addr [:]), cs ); err != nil {
535
491
s .setError (fmt .Errorf ("updateStateObject (%x) error: %w" , addr [:], err ))
536
492
}
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
+ }
537
503
}
538
504
539
505
// If state snapshotting is active, cache the data til commit. Note, this
@@ -545,21 +511,12 @@ func (s *StateDB) updateStateObject(obj *stateObject) {
545
511
}
546
512
}
547
513
548
- func (s * StateDB ) deleteStatelessStateObject (obj * stateObject ) {
549
- // unsupported
550
- panic ("not currently supported" )
551
- }
552
-
553
514
// deleteStateObject removes the given object from the state trie.
554
515
func (s * StateDB ) deleteStateObject (obj * stateObject ) {
555
516
// Track the amount of time wasted on deleting the account from the trie
556
517
if metrics .EnabledExpensive {
557
518
defer func (start time.Time ) { s .AccountUpdates += time .Since (start ) }(time .Now ())
558
519
}
559
- if s .stateless != nil {
560
- s .deleteStatelessStateObject (obj )
561
- return
562
- }
563
520
564
521
// Delete the account from the trie
565
522
if ! s .trie .IsVerkle () {
@@ -586,48 +543,6 @@ func (s *StateDB) getStateObject(addr common.Address) *stateObject {
586
543
return nil
587
544
}
588
545
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
-
631
546
// getDeletedStateObject is similar to getStateObject, but instead of returning
632
547
// nil for a deleted state object, it returns the actual object with the deleted
633
548
// 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 {
642
557
data * types.StateAccount
643
558
err error
644
559
)
645
- // if executing statelessly, bypass the snapshot and the db.
646
- if s .stateless != nil {
647
- return s .getStatelessDeletedStateObject (addr )
648
- }
649
560
if s .snap != nil {
650
561
if metrics .EnabledExpensive {
651
562
defer func (start time.Time ) { s .SnapshotAccountReads += time .Since (start ) }(time .Now ())
@@ -802,6 +713,7 @@ func (s *StateDB) Copy() *StateDB {
802
713
preimages : make (map [common.Hash ][]byte , len (s .preimages )),
803
714
journal : newJournal (),
804
715
hasher : crypto .NewKeccakState (),
716
+ witness : s .witness .Copy (),
805
717
}
806
718
// Copy the dirty states, logs, and preimages
807
719
for addr := range s .journal .dirties {
@@ -852,13 +764,6 @@ func (s *StateDB) Copy() *StateDB {
852
764
// to not blow up if we ever decide copy it in the middle of a transaction
853
765
state .accessList = s .accessList .Copy ()
854
766
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
-
862
767
// If there's a prefetcher running, make an inactive copy of it that can
863
768
// only access data but does not actively preload (since the user will not
864
769
// know that they need to explicitly terminate an active copy).
@@ -1088,8 +993,8 @@ func (s *StateDB) Commit(deleteEmptyObjects bool) (common.Hash, error) {
1088
993
if obj .code != nil && obj .dirtyCode {
1089
994
if s .trie .IsVerkle () {
1090
995
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 ] [:])
1093
998
}
1094
999
} else {
1095
1000
s .setError (err )
0 commit comments