Repository navigation
fix: make evm_execution more robust #2942
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
f2a5390
make evm_execution more robust
tac0turtle fd2d51e
consolidate
tac0turtle 377793c
check
tac0turtle 11325f3
simplify
tac0turtle 70b42a6
more checks
tac0turtle 349c052
remove unneeded mutex
tac0turtle c74e7f5
revert changes
tac0turtle bbefeba
fix build
tac0turtle ecec4e7
remove nil checks and store setter
tac0turtle 182e768
Merge branch 'main' into marko/execution_refactor
tac0turtle 1672e25
feat: add FinalizedBlockLag constant and update setFinalWithHeight logic
tac0turtle e9ba0f9
move proto + go mod tidy
julienrbrt 03335c4
Merge branch 'main' into marko/execution_refactor
julienrbrt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
revert changes
- Loading branch information
commit c74e7f58d50e09286517d16b179ecee34c5be5f9
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
tac0turtle marked this conversation as resolved.
Resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,11 +18,11 @@ import ( | |
| "github.com/ethereum/go-ethereum/core/types" | ||
| "github.com/ethereum/go-ethereum/ethclient" | ||
| "github.com/ethereum/go-ethereum/rpc" | ||
| ds "github.com/ipfs/go-datastore" | ||
| "github.com/golang-jwt/jwt/v5" | ||
| "github.com/rs/zerolog" | ||
|
|
||
| "github.com/evstack/ev-node/core/execution" | ||
| "github.com/evstack/ev-node/pkg/store" | ||
| ) | ||
|
|
||
| const ( | ||
|
|
@@ -137,7 +137,7 @@ type EngineClient struct { | |
|
|
||
| // store provides persistence for ExecMeta to enable idempotent execution | ||
| // and crash recovery. Optional - if nil, ExecMeta tracking is disabled. | ||
| store store.Store | ||
| store *EVMStore | ||
|
|
||
| mu sync.Mutex // Mutex to protect concurrent access to block hashes | ||
| currentHeadBlockHash common.Hash // Store last non-finalized HeadBlockHash | ||
|
|
@@ -150,15 +150,16 @@ type EngineClient struct { | |
| } | ||
|
|
||
| // NewEngineExecutionClient creates a new instance of EngineAPIExecutionClient. | ||
| // The store parameter is optional - if provided, ExecMeta tracking is enabled | ||
| // for idempotent execution and crash recovery. | ||
| // The db parameter is required for ExecMeta tracking which enables idempotent | ||
| // execution and crash recovery. The db is wrapped with a prefix to isolate | ||
| // EVM execution data from other ev-node data. | ||
| func NewEngineExecutionClient( | ||
| ethURL, | ||
| engineURL string, | ||
| jwtSecret string, | ||
| genesisHash common.Hash, | ||
| feeRecipient common.Address, | ||
| evStore store.Store, | ||
| db ds.Batching, | ||
| ) (*EngineClient, error) { | ||
| ethClient, err := ethclient.Dial(ethURL) | ||
| if err != nil { | ||
|
|
@@ -191,7 +192,7 @@ func NewEngineExecutionClient( | |
| ethClient: ethClient, | ||
| genesisHash: genesisHash, | ||
| feeRecipient: feeRecipient, | ||
| store: evStore, | ||
| store: NewEVMStore(db), | ||
| currentHeadBlockHash: genesisHash, | ||
| currentSafeBlockHash: genesisHash, | ||
| currentFinalizedBlockHash: genesisHash, | ||
|
|
@@ -205,13 +206,6 @@ func (c *EngineClient) SetLogger(l zerolog.Logger) { | |
| c.logger = l | ||
| } | ||
|
|
||
| // SetStore allows callers to attach a store for ExecMeta tracking. | ||
| // This enables idempotent execution and crash recovery features. | ||
| // Must be called before ExecuteTxs if ExecMeta tracking is desired. | ||
| func (c *EngineClient) SetStore(s store.Store) { | ||
| c.store = s | ||
| } | ||
|
|
||
| // InitChain initializes the blockchain with the given genesis parameters | ||
| func (c *EngineClient) InitChain(ctx context.Context, genesisTime time.Time, initialHeight uint64, chainID string) ([]byte, uint64, error) { | ||
| if initialHeight != 1 { | ||
|
|
@@ -396,7 +390,7 @@ func (c *EngineClient) ExecuteTxs(ctx context.Context, txs [][]byte, blockHeight | |
| // Save ExecMeta with payloadID for crash recovery (Stage="started") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's remove this nil check and assume store is always set. it is in the constructor. |
||
| // This allows resuming the payload build if we crash before completing | ||
| if c.store != nil { | ||
| c.saveExecMeta(ctx, blockHeight, timestamp.Unix(), newPayloadID[:], nil, nil, txs, store.ExecStageStarted) | ||
| c.saveExecMeta(ctx, blockHeight, timestamp.Unix(), newPayloadID[:], nil, nil, txs, ExecStageStarted) | ||
| } | ||
|
|
||
| // 4. Process the payload (get, submit, finalize) | ||
|
|
@@ -628,7 +622,7 @@ func (c *EngineClient) checkIdempotency(ctx context.Context, height uint64, time | |
| execMeta, err := c.store.GetExecMeta(ctx, height) | ||
| if err == nil && execMeta != nil { | ||
| // If we already have a promoted block at this height, return the stored StateRoot | ||
| if execMeta.Stage == store.ExecStagePromoted && len(execMeta.StateRoot) > 0 { | ||
| if execMeta.Stage == ExecStagePromoted && len(execMeta.StateRoot) > 0 { | ||
| c.logger.Info(). | ||
| Uint64("height", height). | ||
| Str("stage", execMeta.Stage). | ||
|
|
@@ -637,7 +631,7 @@ func (c *EngineClient) checkIdempotency(ctx context.Context, height uint64, time | |
| } | ||
|
|
||
| // If we have a started execution with a payloadID, return it to resume | ||
| if execMeta.Stage == store.ExecStageStarted && len(execMeta.PayloadID) == 8 { | ||
| if execMeta.Stage == ExecStageStarted && len(execMeta.PayloadID) == 8 { | ||
| c.logger.Info(). | ||
| Uint64("height", height). | ||
| Str("stage", execMeta.Stage). | ||
|
|
@@ -669,7 +663,7 @@ func (c *EngineClient) checkIdempotency(ctx context.Context, height uint64, time | |
|
|
||
| // Update ExecMeta to promoted if store is configured | ||
| if c.store != nil { | ||
| c.saveExecMeta(ctx, height, timestamp.Unix(), nil, existingBlockHash[:], existingStateRoot.Bytes(), txs, store.ExecStagePromoted) | ||
| c.saveExecMeta(ctx, height, timestamp.Unix(), nil, existingBlockHash[:], existingStateRoot.Bytes(), txs, ExecStagePromoted) | ||
| } | ||
|
|
||
| return existingStateRoot.Bytes(), nil, true, nil | ||
|
|
@@ -779,7 +773,7 @@ func (c *EngineClient) processPayload(ctx context.Context, payloadID engine.Payl | |
|
|
||
| // 4. Save ExecMeta (Promoted) | ||
| if c.store != nil { | ||
| c.saveExecMeta(ctx, blockHeight, blockTimestamp, payloadID[:], blockHash[:], payloadResult.ExecutionPayload.StateRoot.Bytes(), txs, store.ExecStagePromoted) | ||
| c.saveExecMeta(ctx, blockHeight, blockTimestamp, payloadID[:], blockHash[:], payloadResult.ExecutionPayload.StateRoot.Bytes(), txs, ExecStagePromoted) | ||
| } | ||
|
|
||
| return payloadResult.ExecutionPayload.StateRoot.Bytes(), payloadResult.ExecutionPayload.GasUsed, nil | ||
|
|
@@ -806,7 +800,7 @@ func (c *EngineClient) saveExecMeta(ctx context.Context, height uint64, timestam | |
| return | ||
| } | ||
|
|
||
| execMeta := &store.ExecMeta{ | ||
| execMeta := &ExecMeta{ | ||
| Height: height, | ||
| Timestamp: timestamp, | ||
| PayloadID: payloadID, | ||
|
|
@@ -825,22 +819,11 @@ func (c *EngineClient) saveExecMeta(ctx context.Context, height uint64, timestam | |
| execMeta.TxHash = h.Sum(nil) | ||
| } | ||
|
|
||
| batch, err := c.store.NewBatch(ctx) | ||
| if err != nil { | ||
| c.logger.Warn().Err(err).Uint64("height", height).Msg("saveExecMeta: failed to create batch") | ||
| return | ||
| } | ||
|
|
||
| if err := batch.SaveExecMeta(execMeta); err != nil { | ||
| if err := c.store.SaveExecMeta(ctx, execMeta); err != nil { | ||
| c.logger.Warn().Err(err).Uint64("height", height).Msg("saveExecMeta: failed to save exec meta") | ||
| return | ||
| } | ||
|
|
||
| if err := batch.Commit(); err != nil { | ||
| c.logger.Warn().Err(err).Uint64("height", height).Msg("saveExecMeta: failed to commit batch") | ||
| return | ||
| } | ||
|
|
||
| c.logger.Debug(). | ||
| Uint64("height", height). | ||
| Str("stage", stage). | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.