Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 276
fix: Make EVM Execution more robust#2327
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
2cc7066ca73d476820df1176074431bc0afc627cda7660edc8ef3ca07d7289d26358218c1d952e065dc1File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Uh oh!
There was an error while loading. Please reload this page.
Large diffs are not rendered by default.
Uh oh!
There was an error while loading. Please reload this page.
Large diffs are not rendered by default.
Uh oh!
There was an error while loading. Please reload this page.
Large diffs are not rendered by default.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -9,6 +9,7 @@ import ( | ||
| "math/big" | ||
| "net/http" | ||
| "strings" | ||
| "sync" | ||
| "time" | ||
| "github.com/ethereum/go-ethereum/beacon/engine" | ||
| @@ -40,6 +41,11 @@ type EngineClient struct { | ||
| genesisHash common.Hash // Hash of the genesis block | ||
| initialHeight uint64 | ||
| feeRecipient common.Address // Address to receive transaction fees | ||
| mu sync.Mutex // Mutex to protect concurrent access to block hashes | ||
| currentHeadBlockHash common.Hash // Store last non-finalized HeadBlockHash | ||
| currentSafeBlockHash common.Hash // Store last non-finalized SafeBlockHash | ||
| currentFinalizedBlockHash common.Hash // Store last finalized block hash | ||
| } | ||
| // NewEngineExecutionClient creates a new instance of EngineAPIExecutionClient | ||
| @@ -168,7 +174,8 @@ func (c *EngineClient) ExecuteTxs(ctx context.Context, txs [][]byte, blockHeight | ||
| } | ||
| err = c.ethClient.SendTransaction(context.Background(), ethTxs[i]) | ||
| if err != nil { | ||
| return nil, 0, fmt.Errorf("failed to send transaction: %w", err) | ||
| // Ignore the error if the transaction fails to be sent since transactions can be invalid and an invalid transaction sent by a client should not crash the node. | ||
| continue | ||
| } | ||
| } | ||
| @@ -264,13 +271,22 @@ func (c *EngineClient) ExecuteTxs(ctx context.Context, txs [][]byte, blockHeight | ||
| } | ||
| func (c *EngineClient) setFinal(ctx context.Context, blockHash common.Hash, isFinal bool) error { | ||
| args := engine.ForkchoiceStateV1{ | ||
| HeadBlockHash: blockHash, | ||
| SafeBlockHash: blockHash, | ||
| } | ||
| c.mu.Lock() | ||
| // Update block hashes based on finalization status | ||
| if isFinal { | ||
| args.FinalizedBlockHash = blockHash | ||
| c.currentFinalizedBlockHash = blockHash | ||
| } else { | ||
| c.currentHeadBlockHash = blockHash | ||
| c.currentSafeBlockHash = blockHash | ||
| } | ||
| // Construct forkchoice state | ||
| args := engine.ForkchoiceStateV1{ | ||
| HeadBlockHash: c.currentHeadBlockHash, | ||
| SafeBlockHash: c.currentSafeBlockHash, | ||
| FinalizedBlockHash: c.currentFinalizedBlockHash, | ||
| } | ||
Manav-Aggarwal marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| c.mu.Unlock() | ||
| var forkchoiceResult engine.ForkChoiceResponse | ||
| err := c.engineClient.CallContext(ctx, &forkchoiceResult, "engine_forkchoiceUpdatedV3", | ||
| @@ -311,6 +327,7 @@ func (c *EngineClient) getBlockInfo(ctx context.Context, height uint64) (common. | ||
| return header.Hash(), header.Root, header.GasLimit, header.Time, nil | ||
| } | ||
| // decodeSecret decodes a hex-encoded JWT secret string into a byte slice. | ||
| func decodeSecret(jwtSecret string) ([]byte, error) { | ||
| secret, err := hex.DecodeString(strings.TrimPrefix(jwtSecret, "0x")) | ||
| if err != nil { | ||
| @@ -319,6 +336,7 @@ func decodeSecret(jwtSecret string) ([]byte, error) { | ||
| return secret, nil | ||
| } | ||
| // getAuthToken creates a JWT token signed with the provided secret, valid for 1 hour. | ||
| func getAuthToken(jwtSecret []byte) (string, error) { | ||
| token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{ | ||
| "exp": time.Now().Add(time.Hour * 1).Unix(), // Expires in 1 hour | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.