6
6
"fmt"
7
7
"os"
8
8
"reflect"
9
- "syscall"
10
9
"time"
11
10
12
11
"github.com/ethereum/go-ethereum/accounts/abi"
@@ -16,8 +15,8 @@ import (
16
15
"github.com/ethereum/go-ethereum/core/types"
17
16
"github.com/ethereum/go-ethereum/ethdb"
18
17
"github.com/ethereum/go-ethereum/log"
18
+ "github.com/ethereum/go-ethereum/node"
19
19
"github.com/ethereum/go-ethereum/params"
20
-
21
20
"github.com/ethereum/go-ethereum/rollup/rcfg"
22
21
"github.com/ethereum/go-ethereum/rollup/sync_service"
23
22
"github.com/ethereum/go-ethereum/rollup/withdrawtrie"
@@ -54,9 +53,10 @@ type RollupSyncService struct {
54
53
l1RevertBatchEventSignature common.Hash
55
54
l1FinalizeBatchEventSignature common.Hash
56
55
bc * core.BlockChain
56
+ stack * node.Node
57
57
}
58
58
59
- func NewRollupSyncService (ctx context.Context , genesisConfig * params.ChainConfig , db ethdb.Database , l1Client sync_service.EthClient , bc * core.BlockChain , l1DeploymentBlock uint64 ) (* RollupSyncService , error ) {
59
+ func NewRollupSyncService (ctx context.Context , genesisConfig * params.ChainConfig , db ethdb.Database , l1Client sync_service.EthClient , bc * core.BlockChain , stack * node. Node ) (* RollupSyncService , error ) {
60
60
// terminate if the caller does not provide an L1 client (e.g. in tests)
61
61
if l1Client == nil || (reflect .ValueOf (l1Client ).Kind () == reflect .Ptr && reflect .ValueOf (l1Client ).IsNil ()) {
62
62
log .Warn ("No L1 client provided, L1 rollup sync service will not run" )
@@ -80,8 +80,8 @@ func NewRollupSyncService(ctx context.Context, genesisConfig *params.ChainConfig
80
80
// Initialize the latestProcessedBlock with the block just before the L1 deployment block.
81
81
// This serves as a default value when there's no L1 rollup events synced in the database.
82
82
var latestProcessedBlock uint64
83
- if l1DeploymentBlock > 0 {
84
- latestProcessedBlock = l1DeploymentBlock - 1
83
+ if stack . Config (). L1DeploymentBlock > 0 {
84
+ latestProcessedBlock = stack . Config (). L1DeploymentBlock - 1
85
85
}
86
86
87
87
block := rawdb .ReadRollupEventSyncedL1BlockNumber (db )
@@ -103,6 +103,7 @@ func NewRollupSyncService(ctx context.Context, genesisConfig *params.ChainConfig
103
103
l1RevertBatchEventSignature : scrollChainABI .Events ["RevertBatch" ].ID ,
104
104
l1FinalizeBatchEventSignature : scrollChainABI .Events ["FinalizeBatch" ].ID ,
105
105
bc : bc ,
106
+ stack : stack ,
106
107
}
107
108
108
109
return & service , nil
@@ -223,7 +224,7 @@ func (s *RollupSyncService) parseAndUpdateRollupEventLogs(logs []types.Log, endB
223
224
return fmt .Errorf ("failed to get local node info, batch index: %v, err: %w" , batchIndex , err )
224
225
}
225
226
226
- endBlock , finalizedBatchMeta , err := validateBatch (event , parentBatchMeta , chunks )
227
+ endBlock , finalizedBatchMeta , err := validateBatch (event , parentBatchMeta , chunks , s . stack )
227
228
if err != nil {
228
229
return fmt .Errorf ("fatal: validateBatch failed: finalize event: %v, err: %w" , event , err )
229
230
}
@@ -375,7 +376,7 @@ func (s *RollupSyncService) decodeChunkBlockRanges(txData []byte) ([]*rawdb.Chun
375
376
// validateBatch verifies the consistency between the L1 contract and L2 node data.
376
377
// The function will terminate the node and exit if any consistency check fails.
377
378
// It returns the number of the end block, a finalized batch meta data, and an error if any.
378
- func validateBatch (event * L1FinalizeBatchEvent , parentBatchMeta * rawdb.FinalizedBatchMeta , chunks []* Chunk ) (uint64 , * rawdb.FinalizedBatchMeta , error ) {
379
+ func validateBatch (event * L1FinalizeBatchEvent , parentBatchMeta * rawdb.FinalizedBatchMeta , chunks []* Chunk , stack * node. Node ) (uint64 , * rawdb.FinalizedBatchMeta , error ) {
379
380
if len (chunks ) == 0 {
380
381
return 0 , nil , fmt .Errorf ("invalid argument: length of chunks is 0, batch index: %v" , event .BatchIndex .Uint64 ())
381
382
}
@@ -395,15 +396,15 @@ func validateBatch(event *L1FinalizeBatchEvent, parentBatchMeta *rawdb.Finalized
395
396
localStateRoot := endBlock .Header .Root
396
397
if localStateRoot != event .StateRoot {
397
398
log .Error ("State root mismatch" , "batch index" , event .BatchIndex .Uint64 (), "start block" , startBlock .Header .Number .Uint64 (), "end block" , endBlock .Header .Number .Uint64 (), "parent batch hash" , parentBatchMeta .BatchHash .Hex (), "l1 finalized state root" , event .StateRoot .Hex (), "l2 state root" , localStateRoot .Hex ())
398
- syscall . Kill ( os . Getpid (), syscall . SIGTERM )
399
- return 0 , nil , fmt . Errorf ( "state root mismatch" )
399
+ stack . Close ( )
400
+ os . Exit ( 1 )
400
401
}
401
402
402
403
localWithdrawRoot := endBlock .WithdrawRoot
403
404
if localWithdrawRoot != event .WithdrawRoot {
404
405
log .Error ("Withdraw root mismatch" , "batch index" , event .BatchIndex .Uint64 (), "start block" , startBlock .Header .Number .Uint64 (), "end block" , endBlock .Header .Number .Uint64 (), "parent batch hash" , parentBatchMeta .BatchHash .Hex (), "l1 finalized withdraw root" , event .WithdrawRoot .Hex (), "l2 withdraw root" , localWithdrawRoot .Hex ())
405
- syscall . Kill ( os . Getpid (), syscall . SIGTERM )
406
- return 0 , nil , fmt . Errorf ( "withdraw root mismatch" )
406
+ stack . Close ( )
407
+ os . Exit ( 1 )
407
408
}
408
409
409
410
// Note: All params for NewBatchHeader are calculated locally based on the block data.
@@ -422,8 +423,8 @@ func validateBatch(event *L1FinalizeBatchEvent, parentBatchMeta *rawdb.Finalized
422
423
log .Error ("marshal chunks failed" , "err" , err )
423
424
}
424
425
log .Error ("Chunks" , "chunks" , string (chunksJson ))
425
- syscall . Kill ( os . Getpid (), syscall . SIGTERM )
426
- return 0 , nil , fmt . Errorf ( "batch hash mismatch" )
426
+ stack . Close ( )
427
+ os . Exit ( 1 )
427
428
}
428
429
429
430
totalL1MessagePopped := parentBatchMeta .TotalL1MessagePopped
0 commit comments