Skip to content

Commit f9a9592

Browse files
colinlyguo0xmountaintop
authored andcommitted
fix(rollup sync service): remove syscall.Kill (#636)
* fix(rollup sync service): remove syscall.Kill * bump version
1 parent 02b9229 commit f9a9592

File tree

3 files changed

+30
-18
lines changed

3 files changed

+30
-18
lines changed

eth/backend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ func New(stack *node.Node, config *ethconfig.Config, l1Client sync_service.EthCl
248248
eth.syncService.Start()
249249
if config.EnableRollupVerify {
250250
// initialize and start rollup event sync service
251-
eth.rollupSyncService, err = rollup_sync_service.NewRollupSyncService(context.Background(), chainConfig, eth.chainDb, l1Client, eth.blockchain, stack.Config().L1DeploymentBlock)
251+
eth.rollupSyncService, err = rollup_sync_service.NewRollupSyncService(context.Background(), chainConfig, eth.chainDb, l1Client, eth.blockchain, stack)
252252
if err != nil {
253253
return nil, fmt.Errorf("cannot initialize rollup event sync service: %w", err)
254254
}

rollup/rollup_sync_service/rollup_sync_service.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"fmt"
77
"os"
88
"reflect"
9-
"syscall"
109
"time"
1110

1211
"github.com/ethereum/go-ethereum/accounts/abi"
@@ -16,8 +15,8 @@ import (
1615
"github.com/ethereum/go-ethereum/core/types"
1716
"github.com/ethereum/go-ethereum/ethdb"
1817
"github.com/ethereum/go-ethereum/log"
18+
"github.com/ethereum/go-ethereum/node"
1919
"github.com/ethereum/go-ethereum/params"
20-
2120
"github.com/ethereum/go-ethereum/rollup/rcfg"
2221
"github.com/ethereum/go-ethereum/rollup/sync_service"
2322
"github.com/ethereum/go-ethereum/rollup/withdrawtrie"
@@ -54,9 +53,10 @@ type RollupSyncService struct {
5453
l1RevertBatchEventSignature common.Hash
5554
l1FinalizeBatchEventSignature common.Hash
5655
bc *core.BlockChain
56+
stack *node.Node
5757
}
5858

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) {
6060
// terminate if the caller does not provide an L1 client (e.g. in tests)
6161
if l1Client == nil || (reflect.ValueOf(l1Client).Kind() == reflect.Ptr && reflect.ValueOf(l1Client).IsNil()) {
6262
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
8080
// Initialize the latestProcessedBlock with the block just before the L1 deployment block.
8181
// This serves as a default value when there's no L1 rollup events synced in the database.
8282
var latestProcessedBlock uint64
83-
if l1DeploymentBlock > 0 {
84-
latestProcessedBlock = l1DeploymentBlock - 1
83+
if stack.Config().L1DeploymentBlock > 0 {
84+
latestProcessedBlock = stack.Config().L1DeploymentBlock - 1
8585
}
8686

8787
block := rawdb.ReadRollupEventSyncedL1BlockNumber(db)
@@ -103,6 +103,7 @@ func NewRollupSyncService(ctx context.Context, genesisConfig *params.ChainConfig
103103
l1RevertBatchEventSignature: scrollChainABI.Events["RevertBatch"].ID,
104104
l1FinalizeBatchEventSignature: scrollChainABI.Events["FinalizeBatch"].ID,
105105
bc: bc,
106+
stack: stack,
106107
}
107108

108109
return &service, nil
@@ -223,7 +224,7 @@ func (s *RollupSyncService) parseAndUpdateRollupEventLogs(logs []types.Log, endB
223224
return fmt.Errorf("failed to get local node info, batch index: %v, err: %w", batchIndex, err)
224225
}
225226

226-
endBlock, finalizedBatchMeta, err := validateBatch(event, parentBatchMeta, chunks)
227+
endBlock, finalizedBatchMeta, err := validateBatch(event, parentBatchMeta, chunks, s.stack)
227228
if err != nil {
228229
return fmt.Errorf("fatal: validateBatch failed: finalize event: %v, err: %w", event, err)
229230
}
@@ -375,7 +376,7 @@ func (s *RollupSyncService) decodeChunkBlockRanges(txData []byte) ([]*rawdb.Chun
375376
// validateBatch verifies the consistency between the L1 contract and L2 node data.
376377
// The function will terminate the node and exit if any consistency check fails.
377378
// 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) {
379380
if len(chunks) == 0 {
380381
return 0, nil, fmt.Errorf("invalid argument: length of chunks is 0, batch index: %v", event.BatchIndex.Uint64())
381382
}
@@ -395,15 +396,15 @@ func validateBatch(event *L1FinalizeBatchEvent, parentBatchMeta *rawdb.Finalized
395396
localStateRoot := endBlock.Header.Root
396397
if localStateRoot != event.StateRoot {
397398
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)
400401
}
401402

402403
localWithdrawRoot := endBlock.WithdrawRoot
403404
if localWithdrawRoot != event.WithdrawRoot {
404405
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)
407408
}
408409

409410
// Note: All params for NewBatchHeader are calculated locally based on the block data.
@@ -422,8 +423,8 @@ func validateBatch(event *L1FinalizeBatchEvent, parentBatchMeta *rawdb.Finalized
422423
log.Error("marshal chunks failed", "err", err)
423424
}
424425
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)
427428
}
428429

429430
totalL1MessagePopped := parentBatchMeta.TotalL1MessagePopped

rollup/rollup_sync_service/rollup_sync_service_test.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/ethereum/go-ethereum/core/rawdb"
1818
"github.com/ethereum/go-ethereum/core/types"
1919
"github.com/ethereum/go-ethereum/ethdb/memorydb"
20+
"github.com/ethereum/go-ethereum/node"
2021
"github.com/ethereum/go-ethereum/params"
2122
)
2223

@@ -32,7 +33,12 @@ func TestRollupSyncServiceStartAndStop(t *testing.T) {
3233
db := rawdb.NewDatabase(memorydb.New())
3334
l1Client := &mockEthClient{}
3435
bc := &core.BlockChain{}
35-
service, err := NewRollupSyncService(context.Background(), genesisConfig, db, l1Client, bc, 1)
36+
stack, err := node.New(&node.DefaultConfig)
37+
if err != nil {
38+
t.Fatalf("Failed to new P2P node: %v", err)
39+
}
40+
defer stack.Close()
41+
service, err := NewRollupSyncService(context.Background(), genesisConfig, db, l1Client, bc, stack)
3642
if err != nil {
3743
t.Fatalf("Failed to new rollup sync service: %v", err)
3844
}
@@ -112,7 +118,12 @@ func TestGetChunkRanges(t *testing.T) {
112118
commitBatchRLP: rlpData,
113119
}
114120
bc := &core.BlockChain{}
115-
service, err := NewRollupSyncService(context.Background(), genesisConfig, db, l1Client, bc, 1)
121+
stack, err := node.New(&node.DefaultConfig)
122+
if err != nil {
123+
t.Fatalf("Failed to new P2P node: %v", err)
124+
}
125+
defer stack.Close()
126+
service, err := NewRollupSyncService(context.Background(), genesisConfig, db, l1Client, bc, stack)
116127
if err != nil {
117128
t.Fatalf("Failed to new rollup sync service: %v", err)
118129
}
@@ -169,7 +180,7 @@ func TestValidateBatch(t *testing.T) {
169180
StateRoot: chunk3.Blocks[len(chunk3.Blocks)-1].Header.Root,
170181
WithdrawRoot: chunk3.Blocks[len(chunk3.Blocks)-1].WithdrawRoot,
171182
}
172-
endBlock1, finalizedBatchMeta1, err := validateBatch(event1, parentBatchMeta1, []*Chunk{chunk1, chunk2, chunk3})
183+
endBlock1, finalizedBatchMeta1, err := validateBatch(event1, parentBatchMeta1, []*Chunk{chunk1, chunk2, chunk3}, nil)
173184
assert.NoError(t, err)
174185
assert.Equal(t, uint64(13), endBlock1)
175186

@@ -193,7 +204,7 @@ func TestValidateBatch(t *testing.T) {
193204
StateRoot: chunk4.Blocks[len(chunk4.Blocks)-1].Header.Root,
194205
WithdrawRoot: chunk4.Blocks[len(chunk4.Blocks)-1].WithdrawRoot,
195206
}
196-
endBlock2, finalizedBatchMeta2, err := validateBatch(event2, parentBatchMeta2, []*Chunk{chunk4})
207+
endBlock2, finalizedBatchMeta2, err := validateBatch(event2, parentBatchMeta2, []*Chunk{chunk4}, nil)
197208
assert.NoError(t, err)
198209
assert.Equal(t, uint64(17), endBlock2)
199210

0 commit comments

Comments
 (0)