@@ -157,8 +157,8 @@ type CacheConfig struct {
157
157
}
158
158
159
159
// arbitrum: exposing CacheConfig.triedbConfig to be used by Nitro when initializing arbos in database
160
- func (c * CacheConfig ) TriedbConfig (isVerkle bool ) * triedb.Config {
161
- return c .triedbConfig (isVerkle )
160
+ func (c * CacheConfig ) TriedbConfig () * triedb.Config {
161
+ return c .triedbConfig (false )
162
162
}
163
163
164
164
// triedbConfig derives the configures for trie database.
@@ -773,14 +773,14 @@ func (bc *BlockChain) rewindHashHead(head *types.Header, root common.Hash, rewin
773
773
}
774
774
775
775
// rewindPathHead implements the logic of rewindHead in the context of path scheme.
776
- func (bc * BlockChain ) rewindPathHead (head * types.Header , root common.Hash , rewindLimit uint64 ) (* types.Header , uint64 , bool ) {
776
+ func (bc * BlockChain ) rewindPathHead (head * types.Header , root common.Hash ) (* types.Header , uint64 ) {
777
777
var (
778
778
pivot = rawdb .ReadLastPivotNumber (bc .db ) // Associated block number of pivot block
779
779
rootNumber uint64 // Associated block number of requested root
780
780
781
- // RootFound represents whether the requested root is already
781
+ // BeyondRoot represents whether the requested root is already
782
782
// crossed. The flag value is set to true if the root is empty.
783
- rootFound = root == common.Hash {}
783
+ beyondRoot = root == common.Hash {}
784
784
785
785
// noState represents if the target state requested for search
786
786
// is unavailable and impossible to be recovered.
@@ -789,10 +789,6 @@ func (bc *BlockChain) rewindPathHead(head *types.Header, root common.Hash, rewin
789
789
start = time .Now () // Timestamp the rewinding is restarted
790
790
logged = time .Now () // Timestamp last progress log was printed
791
791
)
792
-
793
- lastFullBlock := uint64 (0 )
794
- lastFullBlockHash := common.Hash {}
795
- gasRolledBack := uint64 (0 )
796
792
// Rewind the head block tag until an available state is found.
797
793
for {
798
794
logger := log .Trace
@@ -802,64 +798,43 @@ func (bc *BlockChain) rewindPathHead(head *types.Header, root common.Hash, rewin
802
798
}
803
799
logger ("Block state missing, rewinding further" , "number" , head .Number , "hash" , head .Hash (), "elapsed" , common .PrettyDuration (time .Since (start )))
804
800
805
- if rewindLimit > 0 && lastFullBlock != 0 {
806
- // Arbitrum: track the amount of gas rolled back and stop the rollback early if necessary
807
- gasUsedInBlock := head .GasUsed
808
- if bc .chainConfig .IsArbitrum () {
809
- receipts := bc .GetReceiptsByHash (head .Hash ())
810
- for _ , receipt := range receipts {
811
- gasUsedInBlock -= receipt .GasUsedForL1
812
- }
813
- }
814
- gasRolledBack += gasUsedInBlock
815
- if gasRolledBack >= rewindLimit {
816
- rootNumber = lastFullBlock
817
- head = bc .GetHeader (lastFullBlockHash , lastFullBlock )
818
- log .Debug ("Rewound to block with state but not snapshot" , "number" , head .Number .Uint64 (), "hash" , head .Hash ())
819
- break
820
- }
821
- }
822
801
// If a root threshold was requested but not yet crossed, check
823
- if ! rootFound && head .Root == root {
824
- rootFound , rootNumber = true , head .Number .Uint64 ()
802
+ if ! beyondRoot && head .Root == root {
803
+ beyondRoot , rootNumber = true , head .Number .Uint64 ()
825
804
}
826
805
// If the root threshold hasn't been crossed but the available
827
806
// state is reached, quickly determine if the target state is
828
807
// possible to be reached or not.
829
- if ! rootFound && noState && bc .HasState (head .Root ) {
830
- rootFound = true
808
+ if ! beyondRoot && noState && bc .HasState (head .Root ) {
809
+ beyondRoot = true
831
810
log .Info ("Disable the search for unattainable state" , "root" , root )
832
811
}
833
812
// Check if the associated state is available or recoverable if
834
813
// the requested root has already been crossed.
835
- if rootFound && (bc .HasState (head .Root ) || bc .stateRecoverable (head .Root )) {
814
+ if beyondRoot && (bc .HasState (head .Root ) || bc .stateRecoverable (head .Root )) {
836
815
break
837
816
}
838
- if (bc .HasState (head .Root ) || bc .stateRecoverable (head .Root )) && lastFullBlock == 0 {
839
- lastFullBlock = head .Number .Uint64 ()
840
- lastFullBlockHash = head .Hash ()
841
- }
842
817
// If pivot block is reached, return the genesis block as the
843
818
// new chain head. Theoretically there must be a persistent
844
819
// state before or at the pivot block, prevent endless rewinding
845
820
// towards the genesis just in case.
846
821
if pivot != nil && * pivot >= head .Number .Uint64 () {
847
822
log .Info ("Pivot block reached, resetting to genesis" , "number" , head .Number , "hash" , head .Hash ())
848
- return bc .genesisBlock .Header (), rootNumber , rootFound
823
+ return bc .genesisBlock .Header (), rootNumber
849
824
}
850
825
// If the chain is gapped in the middle, return the genesis
851
826
// block as the new chain head
852
827
parent := bc .GetHeader (head .ParentHash , head .Number .Uint64 ()- 1 ) // Keep rewinding
853
828
if parent == nil {
854
829
log .Error ("Missing block in the middle, resetting to genesis" , "number" , head .Number .Uint64 ()- 1 , "hash" , head .ParentHash )
855
- return bc .genesisBlock .Header (), rootNumber , rootFound
830
+ return bc .genesisBlock .Header (), rootNumber
856
831
}
857
832
head = parent
858
833
859
834
// If the genesis block is reached, stop searching.
860
835
if head .Number .Uint64 () == 0 {
861
836
log .Info ("Genesis block reached" , "number" , head .Number , "hash" , head .Hash ())
862
- return head , rootNumber , rootFound
837
+ return head , rootNumber
863
838
}
864
839
}
865
840
// Recover if the target state if it's not available yet.
@@ -869,7 +844,7 @@ func (bc *BlockChain) rewindPathHead(head *types.Header, root common.Hash, rewin
869
844
}
870
845
}
871
846
log .Info ("Rewound to block with state" , "number" , head .Number , "hash" , head .Hash ())
872
- return head , rootNumber , rootFound
847
+ return head , rootNumber
873
848
}
874
849
875
850
// rewindHead searches the available states in the database and returns the associated
@@ -882,7 +857,8 @@ func (bc *BlockChain) rewindPathHead(head *types.Header, root common.Hash, rewin
882
857
// and the whole snapshot should be auto-generated in case of head mismatch.
883
858
func (bc * BlockChain ) rewindHead (head * types.Header , root common.Hash , rewindLimit uint64 ) (* types.Header , uint64 , bool ) {
884
859
if bc .triedb .Scheme () == rawdb .PathScheme {
885
- return bc .rewindPathHead (head , root , rewindLimit )
860
+ head , rootNumber := bc .rewindPathHead (head , root )
861
+ return head , rootNumber , head .Number .Uint64 () != 0
886
862
}
887
863
return bc .rewindHashHead (head , root , rewindLimit )
888
864
}
0 commit comments