mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-23 21:26:42 +00:00
fix(rollup sync service): remove syscall.Kill (#636)
* fix(rollup sync service): remove syscall.Kill * bump version
This commit is contained in:
parent
ee381b2451
commit
483949b87e
4 changed files with 31 additions and 18 deletions
|
|
@ -226,7 +226,7 @@ func New(stack *node.Node, config *ethconfig.Config, l1Client sync_service.EthCl
|
||||||
|
|
||||||
if config.EnableRollupVerify {
|
if config.EnableRollupVerify {
|
||||||
// initialize and start rollup event sync service
|
// initialize and start rollup event sync service
|
||||||
eth.rollupSyncService, err = rollup_sync_service.NewRollupSyncService(context.Background(), chainConfig, eth.chainDb, l1Client, eth.blockchain, stack.Config().L1DeploymentBlock)
|
eth.rollupSyncService, err = rollup_sync_service.NewRollupSyncService(context.Background(), chainConfig, eth.chainDb, l1Client, eth.blockchain, stack)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("cannot initialize rollup event sync service: %w", err)
|
return nil, fmt.Errorf("cannot initialize rollup event sync service: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ import (
|
||||||
const (
|
const (
|
||||||
VersionMajor = 5 // Major version component of the current release
|
VersionMajor = 5 // Major version component of the current release
|
||||||
VersionMinor = 1 // Minor version component of the current release
|
VersionMinor = 1 // Minor version component of the current release
|
||||||
VersionPatch = 16 // Patch version component of the current release
|
VersionPatch = 17 // Patch version component of the current release
|
||||||
VersionMeta = "mainnet" // Version metadata to append to the version string
|
VersionMeta = "mainnet" // Version metadata to append to the version string
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"syscall"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/scroll-tech/go-ethereum/accounts/abi"
|
"github.com/scroll-tech/go-ethereum/accounts/abi"
|
||||||
|
|
@ -16,6 +15,7 @@ import (
|
||||||
"github.com/scroll-tech/go-ethereum/core/types"
|
"github.com/scroll-tech/go-ethereum/core/types"
|
||||||
"github.com/scroll-tech/go-ethereum/ethdb"
|
"github.com/scroll-tech/go-ethereum/ethdb"
|
||||||
"github.com/scroll-tech/go-ethereum/log"
|
"github.com/scroll-tech/go-ethereum/log"
|
||||||
|
"github.com/scroll-tech/go-ethereum/node"
|
||||||
"github.com/scroll-tech/go-ethereum/params"
|
"github.com/scroll-tech/go-ethereum/params"
|
||||||
|
|
||||||
"github.com/scroll-tech/go-ethereum/rollup/rcfg"
|
"github.com/scroll-tech/go-ethereum/rollup/rcfg"
|
||||||
|
|
@ -54,9 +54,10 @@ type RollupSyncService struct {
|
||||||
l1RevertBatchEventSignature common.Hash
|
l1RevertBatchEventSignature common.Hash
|
||||||
l1FinalizeBatchEventSignature common.Hash
|
l1FinalizeBatchEventSignature common.Hash
|
||||||
bc *core.BlockChain
|
bc *core.BlockChain
|
||||||
|
stack *node.Node
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRollupSyncService(ctx context.Context, genesisConfig *params.ChainConfig, db ethdb.Database, l1Client sync_service.EthClient, bc *core.BlockChain, l1DeploymentBlock uint64) (*RollupSyncService, error) {
|
func NewRollupSyncService(ctx context.Context, genesisConfig *params.ChainConfig, db ethdb.Database, l1Client sync_service.EthClient, bc *core.BlockChain, stack *node.Node) (*RollupSyncService, error) {
|
||||||
// terminate if the caller does not provide an L1 client (e.g. in tests)
|
// terminate if the caller does not provide an L1 client (e.g. in tests)
|
||||||
if l1Client == nil || (reflect.ValueOf(l1Client).Kind() == reflect.Ptr && reflect.ValueOf(l1Client).IsNil()) {
|
if l1Client == nil || (reflect.ValueOf(l1Client).Kind() == reflect.Ptr && reflect.ValueOf(l1Client).IsNil()) {
|
||||||
log.Warn("No L1 client provided, L1 rollup sync service will not run")
|
log.Warn("No L1 client provided, L1 rollup sync service will not run")
|
||||||
|
|
@ -80,8 +81,8 @@ func NewRollupSyncService(ctx context.Context, genesisConfig *params.ChainConfig
|
||||||
// Initialize the latestProcessedBlock with the block just before the L1 deployment block.
|
// Initialize the latestProcessedBlock with the block just before the L1 deployment block.
|
||||||
// This serves as a default value when there's no L1 rollup events synced in the database.
|
// This serves as a default value when there's no L1 rollup events synced in the database.
|
||||||
var latestProcessedBlock uint64
|
var latestProcessedBlock uint64
|
||||||
if l1DeploymentBlock > 0 {
|
if stack.Config().L1DeploymentBlock > 0 {
|
||||||
latestProcessedBlock = l1DeploymentBlock - 1
|
latestProcessedBlock = stack.Config().L1DeploymentBlock - 1
|
||||||
}
|
}
|
||||||
|
|
||||||
block := rawdb.ReadRollupEventSyncedL1BlockNumber(db)
|
block := rawdb.ReadRollupEventSyncedL1BlockNumber(db)
|
||||||
|
|
@ -103,6 +104,7 @@ func NewRollupSyncService(ctx context.Context, genesisConfig *params.ChainConfig
|
||||||
l1RevertBatchEventSignature: scrollChainABI.Events["RevertBatch"].ID,
|
l1RevertBatchEventSignature: scrollChainABI.Events["RevertBatch"].ID,
|
||||||
l1FinalizeBatchEventSignature: scrollChainABI.Events["FinalizeBatch"].ID,
|
l1FinalizeBatchEventSignature: scrollChainABI.Events["FinalizeBatch"].ID,
|
||||||
bc: bc,
|
bc: bc,
|
||||||
|
stack: stack,
|
||||||
}
|
}
|
||||||
|
|
||||||
return &service, nil
|
return &service, nil
|
||||||
|
|
@ -223,7 +225,7 @@ func (s *RollupSyncService) parseAndUpdateRollupEventLogs(logs []types.Log, endB
|
||||||
return fmt.Errorf("failed to get local node info, batch index: %v, err: %w", batchIndex, err)
|
return fmt.Errorf("failed to get local node info, batch index: %v, err: %w", batchIndex, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
endBlock, finalizedBatchMeta, err := validateBatch(event, parentBatchMeta, chunks)
|
endBlock, finalizedBatchMeta, err := validateBatch(event, parentBatchMeta, chunks, s.stack)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("fatal: validateBatch failed: finalize event: %v, err: %w", event, err)
|
return fmt.Errorf("fatal: validateBatch failed: finalize event: %v, err: %w", event, err)
|
||||||
}
|
}
|
||||||
|
|
@ -375,7 +377,7 @@ func (s *RollupSyncService) decodeChunkBlockRanges(txData []byte) ([]*rawdb.Chun
|
||||||
// validateBatch verifies the consistency between the L1 contract and L2 node data.
|
// validateBatch verifies the consistency between the L1 contract and L2 node data.
|
||||||
// The function will terminate the node and exit if any consistency check fails.
|
// The function will terminate the node and exit if any consistency check fails.
|
||||||
// It returns the number of the end block, a finalized batch meta data, and an error if any.
|
// It returns the number of the end block, a finalized batch meta data, and an error if any.
|
||||||
func validateBatch(event *L1FinalizeBatchEvent, parentBatchMeta *rawdb.FinalizedBatchMeta, chunks []*Chunk) (uint64, *rawdb.FinalizedBatchMeta, error) {
|
func validateBatch(event *L1FinalizeBatchEvent, parentBatchMeta *rawdb.FinalizedBatchMeta, chunks []*Chunk, stack *node.Node) (uint64, *rawdb.FinalizedBatchMeta, error) {
|
||||||
if len(chunks) == 0 {
|
if len(chunks) == 0 {
|
||||||
return 0, nil, fmt.Errorf("invalid argument: length of chunks is 0, batch index: %v", event.BatchIndex.Uint64())
|
return 0, nil, fmt.Errorf("invalid argument: length of chunks is 0, batch index: %v", event.BatchIndex.Uint64())
|
||||||
}
|
}
|
||||||
|
|
@ -395,15 +397,15 @@ func validateBatch(event *L1FinalizeBatchEvent, parentBatchMeta *rawdb.Finalized
|
||||||
localStateRoot := endBlock.Header.Root
|
localStateRoot := endBlock.Header.Root
|
||||||
if localStateRoot != event.StateRoot {
|
if localStateRoot != event.StateRoot {
|
||||||
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())
|
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())
|
||||||
syscall.Kill(os.Getpid(), syscall.SIGTERM)
|
stack.Close()
|
||||||
return 0, nil, fmt.Errorf("state root mismatch")
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
localWithdrawRoot := endBlock.WithdrawRoot
|
localWithdrawRoot := endBlock.WithdrawRoot
|
||||||
if localWithdrawRoot != event.WithdrawRoot {
|
if localWithdrawRoot != event.WithdrawRoot {
|
||||||
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())
|
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())
|
||||||
syscall.Kill(os.Getpid(), syscall.SIGTERM)
|
stack.Close()
|
||||||
return 0, nil, fmt.Errorf("withdraw root mismatch")
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note: All params for NewBatchHeader are calculated locally based on the block data.
|
// Note: All params for NewBatchHeader are calculated locally based on the block data.
|
||||||
|
|
@ -422,8 +424,8 @@ func validateBatch(event *L1FinalizeBatchEvent, parentBatchMeta *rawdb.Finalized
|
||||||
log.Error("marshal chunks failed", "err", err)
|
log.Error("marshal chunks failed", "err", err)
|
||||||
}
|
}
|
||||||
log.Error("Chunks", "chunks", string(chunksJson))
|
log.Error("Chunks", "chunks", string(chunksJson))
|
||||||
syscall.Kill(os.Getpid(), syscall.SIGTERM)
|
stack.Close()
|
||||||
return 0, nil, fmt.Errorf("batch hash mismatch")
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
totalL1MessagePopped := parentBatchMeta.TotalL1MessagePopped
|
totalL1MessagePopped := parentBatchMeta.TotalL1MessagePopped
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ import (
|
||||||
"github.com/scroll-tech/go-ethereum/core/rawdb"
|
"github.com/scroll-tech/go-ethereum/core/rawdb"
|
||||||
"github.com/scroll-tech/go-ethereum/core/types"
|
"github.com/scroll-tech/go-ethereum/core/types"
|
||||||
"github.com/scroll-tech/go-ethereum/ethdb/memorydb"
|
"github.com/scroll-tech/go-ethereum/ethdb/memorydb"
|
||||||
|
"github.com/scroll-tech/go-ethereum/node"
|
||||||
"github.com/scroll-tech/go-ethereum/params"
|
"github.com/scroll-tech/go-ethereum/params"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -32,7 +33,12 @@ func TestRollupSyncServiceStartAndStop(t *testing.T) {
|
||||||
db := rawdb.NewDatabase(memorydb.New())
|
db := rawdb.NewDatabase(memorydb.New())
|
||||||
l1Client := &mockEthClient{}
|
l1Client := &mockEthClient{}
|
||||||
bc := &core.BlockChain{}
|
bc := &core.BlockChain{}
|
||||||
service, err := NewRollupSyncService(context.Background(), genesisConfig, db, l1Client, bc, 1)
|
stack, err := node.New(&node.DefaultConfig)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to new P2P node: %v", err)
|
||||||
|
}
|
||||||
|
defer stack.Close()
|
||||||
|
service, err := NewRollupSyncService(context.Background(), genesisConfig, db, l1Client, bc, stack)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to new rollup sync service: %v", err)
|
t.Fatalf("Failed to new rollup sync service: %v", err)
|
||||||
}
|
}
|
||||||
|
|
@ -112,7 +118,12 @@ func TestGetChunkRanges(t *testing.T) {
|
||||||
commitBatchRLP: rlpData,
|
commitBatchRLP: rlpData,
|
||||||
}
|
}
|
||||||
bc := &core.BlockChain{}
|
bc := &core.BlockChain{}
|
||||||
service, err := NewRollupSyncService(context.Background(), genesisConfig, db, l1Client, bc, 1)
|
stack, err := node.New(&node.DefaultConfig)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to new P2P node: %v", err)
|
||||||
|
}
|
||||||
|
defer stack.Close()
|
||||||
|
service, err := NewRollupSyncService(context.Background(), genesisConfig, db, l1Client, bc, stack)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to new rollup sync service: %v", err)
|
t.Fatalf("Failed to new rollup sync service: %v", err)
|
||||||
}
|
}
|
||||||
|
|
@ -169,7 +180,7 @@ func TestValidateBatch(t *testing.T) {
|
||||||
StateRoot: chunk3.Blocks[len(chunk3.Blocks)-1].Header.Root,
|
StateRoot: chunk3.Blocks[len(chunk3.Blocks)-1].Header.Root,
|
||||||
WithdrawRoot: chunk3.Blocks[len(chunk3.Blocks)-1].WithdrawRoot,
|
WithdrawRoot: chunk3.Blocks[len(chunk3.Blocks)-1].WithdrawRoot,
|
||||||
}
|
}
|
||||||
endBlock1, finalizedBatchMeta1, err := validateBatch(event1, parentBatchMeta1, []*Chunk{chunk1, chunk2, chunk3})
|
endBlock1, finalizedBatchMeta1, err := validateBatch(event1, parentBatchMeta1, []*Chunk{chunk1, chunk2, chunk3}, nil)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, uint64(13), endBlock1)
|
assert.Equal(t, uint64(13), endBlock1)
|
||||||
|
|
||||||
|
|
@ -193,7 +204,7 @@ func TestValidateBatch(t *testing.T) {
|
||||||
StateRoot: chunk4.Blocks[len(chunk4.Blocks)-1].Header.Root,
|
StateRoot: chunk4.Blocks[len(chunk4.Blocks)-1].Header.Root,
|
||||||
WithdrawRoot: chunk4.Blocks[len(chunk4.Blocks)-1].WithdrawRoot,
|
WithdrawRoot: chunk4.Blocks[len(chunk4.Blocks)-1].WithdrawRoot,
|
||||||
}
|
}
|
||||||
endBlock2, finalizedBatchMeta2, err := validateBatch(event2, parentBatchMeta2, []*Chunk{chunk4})
|
endBlock2, finalizedBatchMeta2, err := validateBatch(event2, parentBatchMeta2, []*Chunk{chunk4}, nil)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, uint64(17), endBlock2)
|
assert.Equal(t, uint64(17), endBlock2)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue