@@ -934,6 +934,17 @@ func (s *StateDB) GetRefund() uint64 {
934
934
return s .refund
935
935
}
936
936
937
+ // GetRefund returns the current value of the refund counter.
938
+ func (s * StateDB ) WaitPipeVerification () error {
939
+ // We need wait for the parent trie to commit
940
+ if s .snap != nil {
941
+ if valid := s .snap .WaitAndGetVerifyRes (); ! valid {
942
+ return fmt .Errorf ("verification on parent snap failed" )
943
+ }
944
+ }
945
+ return nil
946
+ }
947
+
937
948
// Finalise finalises the state by removing the s destructed objects and clears
938
949
// the journal as well as the refunds. Finalise, however, will not push any updates
939
950
// into the tries just yet. Only IntermediateRoot or Commit will do that.
@@ -986,21 +997,18 @@ func (s *StateDB) Finalise(deleteEmptyObjects bool) {
986
997
// IntermediateRoot computes the current root hash of the state trie.
987
998
// It is called in between transactions to get the root hash that
988
999
// goes into transaction receipts.
989
- func (s * StateDB ) IntermediateRoot (deleteEmptyObjects bool ) ( common.Hash , error ) {
1000
+ func (s * StateDB ) IntermediateRoot (deleteEmptyObjects bool ) common.Hash {
990
1001
if s .lightProcessed {
991
1002
s .StopPrefetcher ()
992
- return s .trie .Hash (), nil
1003
+ return s .trie .Hash ()
993
1004
}
994
1005
// Finalise all the dirty storage states and write them into the tries
995
1006
s .Finalise (deleteEmptyObjects )
996
- err := s .AccountsIntermediateRoot ()
997
- if err != nil {
998
- return common.Hash {}, err
999
- }
1000
- return s .StateIntermediateRoot (), nil
1007
+ s .AccountsIntermediateRoot ()
1008
+ return s .StateIntermediateRoot ()
1001
1009
}
1002
1010
1003
- func (s * StateDB ) AccountsIntermediateRoot () error {
1011
+ func (s * StateDB ) AccountsIntermediateRoot () {
1004
1012
tasks := make (chan func ())
1005
1013
finishCh := make (chan struct {})
1006
1014
defer close (finishCh )
@@ -1018,12 +1026,6 @@ func (s *StateDB) AccountsIntermediateRoot() error {
1018
1026
}()
1019
1027
}
1020
1028
1021
- // We need wait for the parent trie to commit
1022
- if s .snap != nil {
1023
- if valid := s .snap .WaitAndGetVerifyRes (); ! valid {
1024
- return fmt .Errorf ("verification on parent snap failed" )
1025
- }
1026
- }
1027
1029
// Although naively it makes sense to retrieve the account trie and then do
1028
1030
// the contract storage and account updates sequentially, that short circuits
1029
1031
// the account prefetcher. Instead, let's process all the storage updates
@@ -1055,7 +1057,6 @@ func (s *StateDB) AccountsIntermediateRoot() error {
1055
1057
}
1056
1058
}
1057
1059
wg .Wait ()
1058
- return nil
1059
1060
}
1060
1061
1061
1062
func (s * StateDB ) StateIntermediateRoot () common.Hash {
@@ -1260,7 +1261,7 @@ func (s *StateDB) LightCommit() (common.Hash, *types.DiffLayer, error) {
1260
1261
}
1261
1262
1262
1263
// Commit writes the state to the underlying in-memory trie database.
1263
- func (s * StateDB ) Commit (deleteEmptyObjects bool , failPostCommitFunc func (), postCommitFuncs ... func () error ) (common.Hash , * types.DiffLayer , error ) {
1264
+ func (s * StateDB ) Commit (failPostCommitFunc func (), postCommitFuncs ... func () error ) (common.Hash , * types.DiffLayer , error ) {
1264
1265
if s .dbErr != nil {
1265
1266
return common.Hash {}, nil , fmt .Errorf ("commit aborted due to earlier error: %v" , s .dbErr )
1266
1267
}
@@ -1290,13 +1291,6 @@ func (s *StateDB) Commit(deleteEmptyObjects bool, failPostCommitFunc func(), pos
1290
1291
snapUpdated = make (chan struct {})
1291
1292
}
1292
1293
1293
- s .Finalise (deleteEmptyObjects )
1294
- err := s .AccountsIntermediateRoot ()
1295
-
1296
- if err != nil {
1297
- return common.Hash {}, nil , err
1298
- }
1299
-
1300
1294
commmitTrie := func () error {
1301
1295
commitErr := func () error {
1302
1296
if s .stateRoot = s .StateIntermediateRoot (); s .fullProcessed && s .expectedRoot != s .stateRoot {
@@ -1448,9 +1442,11 @@ func (s *StateDB) Commit(deleteEmptyObjects bool, failPostCommitFunc func(), pos
1448
1442
// - head layer is paired with HEAD state
1449
1443
// - head-1 layer is paired with HEAD-1 state
1450
1444
// - head-(n-1) layer(bottom-most diff layer) is paired with HEAD-(n-1)state
1451
- if err := s .snaps .Cap (s .expectedRoot , s .snaps .CapLimit ()); err != nil {
1452
- log .Warn ("Failed to cap snapshot tree" , "root" , s .expectedRoot , "layers" , s .snaps .CapLimit (), "err" , err )
1453
- }
1445
+ go func () {
1446
+ if err := s .snaps .Cap (s .expectedRoot , s .snaps .CapLimit ()); err != nil {
1447
+ log .Warn ("Failed to cap snapshot tree" , "root" , s .expectedRoot , "layers" , s .snaps .CapLimit (), "err" , err )
1448
+ }
1449
+ }()
1454
1450
}
1455
1451
}
1456
1452
return nil
0 commit comments