Skip to content

Commit d386df5

Browse files
authored
fix: make evm_execution more robust (#2942)
<!-- Please read and fill out this form before submitting your PR. Please make sure you have reviewed our contributors guide before submitting your first PR. NOTE: PR titles should follow semantic commits: https://www.conventionalcommits.org/en/v1.0.0/ --> ## Overview <!-- Please provide an explanation of the PR, including the appropriate context, background, goal, and rationale. If there is an issue with this information, please provide a tl;dr and link the issue. Ex: Closes #<issue number> --> ### Summary Prevents fork explosions where multiple EL blocks are created for the same app block height by adding three layers of protection: 1. **Idempotency check** - Before building, checks if EL already has a block at the requested height with matching timestamp and reuses it 2. **Fixed safe/finalized semantics** - `setFinal(isFinal=false)` no longer incorrectly advances safe block; safe now lags head by `SafeBlockLag` (2 blocks) ### Changes - Added `executeMu sync.Mutex` to serialize `ExecuteTxs` and `ResumePayload` calls - Added idempotency check at start of `ExecuteTxs` using height + timestamp matching - Fixed forkchoice args to use tracked `currentSafeBlockHash`/`currentFinalizedBlockHash` instead of `prevBlockHash` - Added `SafeBlockLag` constant (2 blocks) for automatic safe block advancement - Added new APIs: `SetSafe()`, `SetSafeByHeight()`, `SetFinalized()`, `ResumePayload()` - Refactored common RPC logic into `doForkchoiceUpdate()
1 parent d4a2da9 commit d386df5

File tree

22 files changed

+1065
-275
lines changed

22 files changed

+1065
-275
lines changed

apps/evm/cmd/run.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,23 @@ var RunCmd = &cobra.Command{
4343
Aliases: []string{"node", "run"},
4444
Short: "Run the evolve node with EVM execution client",
4545
RunE: func(cmd *cobra.Command, args []string) error {
46-
executor, err := createExecutionClient(cmd)
46+
nodeConfig, err := rollcmd.ParseConfig(cmd)
4747
if err != nil {
4848
return err
4949
}
5050

51-
nodeConfig, err := rollcmd.ParseConfig(cmd)
51+
logger := rollcmd.SetupLogger(nodeConfig.Log)
52+
53+
// Create datastore first - needed by execution client for ExecMeta tracking
54+
datastore, err := store.NewDefaultKVStore(nodeConfig.RootDir, nodeConfig.DBPath, evmDbName)
5255
if err != nil {
5356
return err
5457
}
5558

56-
logger := rollcmd.SetupLogger(nodeConfig.Log)
59+
executor, err := createExecutionClient(cmd, datastore)
60+
if err != nil {
61+
return err
62+
}
5763

5864
blobClient, err := blobrpc.NewClient(context.Background(), nodeConfig.DA.Address, nodeConfig.DA.AuthToken, "")
5965
if err != nil {
@@ -72,11 +78,6 @@ var RunCmd = &cobra.Command{
7278

7379
logger.Info().Str("headerNamespace", headerNamespace.HexString()).Str("dataNamespace", dataNamespace.HexString()).Msg("namespaces")
7480

75-
datastore, err := store.NewDefaultKVStore(nodeConfig.RootDir, nodeConfig.DBPath, evmDbName)
76-
if err != nil {
77-
return err
78-
}
79-
8081
genesisPath := filepath.Join(filepath.Dir(nodeConfig.ConfigPath()), "genesis.json")
8182
genesis, err := genesispkg.LoadGenesis(genesisPath)
8283
if err != nil {
@@ -200,7 +201,7 @@ func createSequencer(
200201
return sequencer, nil
201202
}
202203

203-
func createExecutionClient(cmd *cobra.Command) (execution.Executor, error) {
204+
func createExecutionClient(cmd *cobra.Command, db datastore.Batching) (execution.Executor, error) {
204205
// Read execution client parameters from flags
205206
ethURL, err := cmd.Flags().GetString(evm.FlagEvmEthURL)
206207
if err != nil {
@@ -245,7 +246,7 @@ func createExecutionClient(cmd *cobra.Command) (execution.Executor, error) {
245246
genesisHash := common.HexToHash(genesisHashStr)
246247
feeRecipient := common.HexToAddress(feeRecipientStr)
247248

248-
return evm.NewEngineExecutionClient(ethURL, engineURL, jwtSecret, genesisHash, feeRecipient)
249+
return evm.NewEngineExecutionClient(ethURL, engineURL, jwtSecret, genesisHash, feeRecipient, db)
249250
}
250251

251252
// addFlags adds flags related to the EVM execution client

buf.gen.evm.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
version: v2
2+
3+
plugins:
4+
- remote: buf.build/protocolbuffers/go
5+
out: execution/evm/types/pb
6+
opt: paths=source_relative
7+
- remote: buf.build/connectrpc/go
8+
out: execution/evm/types/pb
9+
opt: paths=source_relative
10+
inputs:
11+
- directory: proto

buf.gen.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
version: v2
2-
clean: true
32

43
plugins:
54
- remote: buf.build/protocolbuffers/go

0 commit comments

Comments
 (0)