@@ -21,17 +21,12 @@ import (
2121 "github.com/ethereum/go-ethereum/node"
2222 "github.com/ethereum/go-ethereum/rpc"
2323
24- "github.com/offchainlabs/nitro/arbnode/dataposter/storage"
25- "github.com/offchainlabs/nitro/arbnode/db/read"
26- "github.com/offchainlabs/nitro/arbnode/mel"
27- "github.com/offchainlabs/nitro/arbutil"
2824 "github.com/offchainlabs/nitro/bold/protocol"
2925 "github.com/offchainlabs/nitro/cmd/chaininfo"
3026 "github.com/offchainlabs/nitro/cmd/conf"
3127 "github.com/offchainlabs/nitro/execution/gethexec"
3228 "github.com/offchainlabs/nitro/solgen/go/bridgegen"
3329 "github.com/offchainlabs/nitro/solgen/go/rollupgen"
34- "github.com/offchainlabs/nitro/staker"
3530 "github.com/offchainlabs/nitro/staker/bold"
3631 legacystaker "github.com/offchainlabs/nitro/staker/legacy"
3732 multiprotocolstaker "github.com/offchainlabs/nitro/staker/multi_protocol"
@@ -94,16 +89,6 @@ func findImportantRoots(ctx context.Context, executionDB ethdb.Database, stack *
9489 if chainConfig == nil {
9590 return nil , errors .New ("database doesn't have a chain config (was this node initialized?)" )
9691 }
97- consensusDB , err := stack .OpenDatabaseWithOptions ("arbitrumdata" , node.DatabaseOptions {MetricsNamespace : "arbitrumdata/" , ReadOnly : true , PebbleExtraOptions : persistentConfig .Pebble .ExtraOptions ("arbitrumdata" ), NoFreezer : true })
98- if err != nil {
99- return nil , err
100- }
101- defer func () {
102- err := consensusDB .Close ()
103- if err != nil {
104- log .Warn ("failed to close arbitrum database after finding pruning targets" , "err" , err )
105- }
106- }()
10792 roots := importantRoots {
10893 executionDB : executionDB ,
10994 }
@@ -113,7 +98,7 @@ func findImportantRoots(ctx context.Context, executionDB ethdb.Database, stack *
11398 if genesisHeader == nil {
11499 return nil , errors .New ("missing L2 genesis block header" )
115100 }
116- err = roots .addHeader (genesisHeader , false )
101+ err : = roots .addHeader (genesisHeader , false )
117102 if err != nil {
118103 return nil , err
119104 }
@@ -139,24 +124,25 @@ func findImportantRoots(ctx context.Context, executionDB ethdb.Database, stack *
139124 log .Warn ("missing latest confirmed block" , "hash" , confirmedHash )
140125 }
141126
142- validatorDB := rawdb .NewTable (consensusDB , storage .BlockValidatorPrefix )
143- lastValidated , err := staker .ReadLastValidatedInfo (validatorDB )
127+ data , err := executionDB .Get (gethexec .ValidatedBlockHashKey )
144128 if err != nil {
145129 return nil , err
146130 }
147- if lastValidated != nil {
131+ lastValidatedBlockHash := common .BytesToHash (data )
132+
133+ if lastValidatedBlockHash != (common.Hash {}) {
148134 var lastValidatedHeader * types.Header
149- headerNum , found := rawdb .ReadHeaderNumber (executionDB , lastValidated . GlobalState . BlockHash )
135+ headerNum , found := rawdb .ReadHeaderNumber (executionDB , lastValidatedBlockHash )
150136 if found {
151- lastValidatedHeader = rawdb .ReadHeader (executionDB , lastValidated . GlobalState . BlockHash , headerNum )
137+ lastValidatedHeader = rawdb .ReadHeader (executionDB , lastValidatedBlockHash , headerNum )
152138 }
153139 if lastValidatedHeader != nil {
154140 err = roots .addHeader (lastValidatedHeader , false )
155141 if err != nil {
156142 return nil , err
157143 }
158144 } else {
159- log .Warn ("missing latest validated block" , "hash" , lastValidated . GlobalState . BlockHash )
145+ log .Warn ("missing latest validated block" , "hash" , lastValidatedBlockHash )
160146 }
161147 }
162148 } else if initConfig .Prune == "full" || initConfig .Prune == "minimal" {
@@ -179,56 +165,21 @@ func findImportantRoots(ctx context.Context, executionDB ethdb.Database, stack *
179165 return nil , fmt .Errorf ("unknown pruning mode: \" %v\" " , initConfig .Prune )
180166 }
181167 if initConfig .Prune != "minimal" && l1Client != nil {
182- // in pruning modes other then "minimal", find the latest finalized block and add it as a pruning target
183- l1Block , err := l1Client .BlockByNumber (ctx , big .NewInt (int64 (rpc .FinalizedBlockNumber )))
184- if err != nil {
185- return nil , fmt .Errorf ("failed to get finalized block: %w" , err )
168+ // in pruning modes other than "minimal", get the latest finalized block and add it as a pruning target
169+ finalizedBlockHash := rawdb .ReadFinalizedBlockHash (executionDB )
170+ finalizedBlockNumber , ok := rawdb .ReadHeaderNumber (executionDB , finalizedBlockHash )
171+ if ! ok {
172+ return nil , errors .New ("Number of finalized block is missing" )
186173 }
187- l1BlockNum := l1Block . NumberU64 ()
188- var batch uint64
189- if melEnabled {
190- batch , err = read . MELSequencerBatchCount ( consensusDB )
174+
175+ l2Header := rawdb . ReadHeader ( executionDB , finalizedBlockHash , finalizedBlockNumber )
176+ if l2Header == nil {
177+ log . Warn ( "latest finalized L2 block is unknown" , "blockNum" , finalizedBlockNumber )
191178 } else {
192- batch , err = read .SequencerBatchCount (consensusDB )
193- }
194- if err != nil {
195- return nil , err
196- }
197- for {
198- if ctx .Err () != nil {
199- return nil , ctx .Err ()
200- }
201- if batch == 0 {
202- // No batch has been finalized
203- break
204- }
205- batch -= 1
206- var meta mel.BatchMetadata
207- if melEnabled {
208- meta , err = read .MELBatchMetadata (consensusDB , batch )
209- } else {
210- meta , err = read .BatchMetadata (consensusDB , batch )
211- }
179+ err = roots .addHeader (l2Header , false )
212180 if err != nil {
213181 return nil , err
214182 }
215- if meta .ParentChainBlock <= l1BlockNum {
216- // #nosec G115
217- signedBlockNum := int64 (arbutil .MessageIndexToBlockNumber (meta .MessageCount , genesisNum )) - 1
218- // #nosec G115
219- blockNum := uint64 (signedBlockNum )
220- l2Hash := rawdb .ReadCanonicalHash (executionDB , blockNum )
221- l2Header := rawdb .ReadHeader (executionDB , l2Hash , blockNum )
222- if l2Header == nil {
223- log .Warn ("latest finalized L2 block is unknown" , "blockNum" , signedBlockNum )
224- break
225- }
226- err = roots .addHeader (l2Header , false )
227- if err != nil {
228- return nil , err
229- }
230- break
231- }
232183 }
233184 }
234185 roots .roots = append (roots .roots , common.Hash {}) // the latest snapshot
0 commit comments