From 09fc443feeba0e4cf6a753bae71284a8d13e6c53 Mon Sep 17 00:00:00 2001 From: Jason Yellick Date: Tue, 27 Feb 2024 22:02:42 -0500 Subject: [PATCH] More straggling testinprod/op-erigon alignment --- core/state_transition.go | 2 +- eth/backend.go | 2 +- params/config.go | 14 -------- params/superchain.go | 14 ++++++++ turbo/adapter/ethapi/api.go | 47 +++++++++++++------------ turbo/adapter/ethapi/api_test.go | 21 +++++------ turbo/engineapi/engine_server.go | 27 +++++++------- turbo/engineapi/engine_types/jsonrpc.go | 12 ++++--- 8 files changed, 71 insertions(+), 68 deletions(-) diff --git a/core/state_transition.go b/core/state_transition.go index bf87aef234b..12f1528a3c4 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -572,7 +572,7 @@ func (st *StateTransition) innerTransitionDb(refunds bool, gasBailout bool) (*Ex } // Check that we are post bedrock to be able to create pseudo pre-bedrock blocks (these are pre-bedrock, but don't follow l2 geth rules) - if rules.IsBedrock { + if rules.IsOptimismBedrock { st.state.AddBalance(params.OptimismBaseFeeRecipient, new(uint256.Int).Mul(uint256.NewInt(st.gasUsed()), st.evm.Context.BaseFee)) if st.evm.Context.L1CostFunc == nil { // Erigon EVM context is used in many unexpected/hacky ways, let's panic if it's misconfigured panic("missing L1 cost func in block context, please configure l1 cost when using optimism config to run EVM") diff --git a/eth/backend.go b/eth/backend.go index 16833c8b274..67c1c5a0b46 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -619,7 +619,6 @@ func New(ctx context.Context, stack *node.Node, config *ethconfig.Config, logger } backend.historicalRPCService = client } - config.TxPool.Optimism = config.Genesis.Config.IsOptimism() config.TxPool.NoGossip = config.DisableTxPoolGossip var miningRPC txpool_proto.MiningServer stateDiffClient := direct.NewStateDiffClientDirect(kvRPC) @@ -631,6 +630,7 @@ func New(ctx context.Context, stack *node.Node, config *ethconfig.Config, logger backend.newTxs = make(chan types2.Announcements, 1024) //defer close(newTxs) + config.TxPool.Optimism = chainConfig.Optimism != nil backend.txPoolDB, backend.txPool, backend.txPoolFetch, backend.txPoolSend, backend.txPoolGrpcServer, err = txpooluitl.AllComponents( ctx, config.TxPool, kvcache.NewDummy(), backend.newTxs, backend.chainDB, backend.sentriesClient.Sentries(), stateDiffClient, misc.Eip1559FeeCalculator, logger, ) diff --git a/params/config.go b/params/config.go index da5cec36b19..5699aada5d7 100644 --- a/params/config.go +++ b/params/config.go @@ -85,20 +85,6 @@ var ( ChiadoGenesisStateRoot = libcommon.HexToHash("0x9ec3eaf4e6188dfbdd6ade76eaa88289b57c63c9a2cde8d35291d5a29e143d31") ) -const ( - OPMainnetChainID = 10 - OPGoerliChainID = 420 - OPSepoliaChainID = 11155420 - BaseMainnetChainID = 8453 - BaseGoerliChainID = 84531 - baseSepoliaChainID = 84532 - baseGoerliDevnetChainID = 11763071 - pgnSepoliaChainID = 58008 - devnetChainID = 997 - chaosnetChainID = 888 - BobaSepoliaChainID = 28882 -) - var ( // MainnetChainConfig is the chain parameters to run a node on the main network. MainnetChainConfig = readChainSpec("chainspecs/mainnet.json") diff --git a/params/superchain.go b/params/superchain.go index ffd09acae10..39b192fe0ff 100644 --- a/params/superchain.go +++ b/params/superchain.go @@ -11,6 +11,20 @@ import ( "github.com/ledgerwatch/erigon-lib/common" ) +const ( + OPMainnetChainID = 10 + OPGoerliChainID = 420 + OPSepoliaChainID = 11155420 + BaseMainnetChainID = 8453 + BaseGoerliChainID = 84531 + baseSepoliaChainID = 84532 + baseGoerliDevnetChainID = 11763071 + pgnSepoliaChainID = 58008 + devnetChainID = 997 + chaosnetChainID = 888 + BobaSepoliaChainID = 28882 +) + // OP Stack chain config var ( // March 17, 2023 @ 7:00:00 pm UTC diff --git a/turbo/adapter/ethapi/api.go b/turbo/adapter/ethapi/api.go index 0935e80c547..d40b0c2e795 100644 --- a/turbo/adapter/ethapi/api.go +++ b/turbo/adapter/ethapi/api.go @@ -408,20 +408,21 @@ type RPCTransaction struct { Hash libcommon.Hash `json:"hash"` Input hexutility.Bytes `json:"input"` Nonce hexutil.Uint64 `json:"nonce"` - To *libcommon.Address `json:"to"` + To *libcommon.Address `json:"to,omitempty"` TransactionIndex *hexutil.Uint64 `json:"transactionIndex"` Value *hexutil.Big `json:"value"` Type hexutil.Uint64 `json:"type"` Accesses *types2.AccessList `json:"accessList,omitempty"` ChainID *hexutil.Big `json:"chainId,omitempty"` - V *hexutil.Big `json:"v"` - R *hexutil.Big `json:"r"` - S *hexutil.Big `json:"s"` - SourceHash *libcommon.Hash `json:"sourceHash,omitempty"` - Mint *hexutil.Big `json:"mint,omitempty"` - IsSystemTx bool `json:"isSystemTx,omitempty"` + V *hexutil.Big `json:"v,omitempty"` + R *hexutil.Big `json:"r,omitempty"` + S *hexutil.Big `json:"s,omitempty"` BlobVersionedHashes []libcommon.Hash `json:"blobVersionedHashes,omitempty"` + // deposit-tx only + SourceHash *libcommon.Hash `json:"sourceHash,omitempty"` + Mint *hexutil.Big `json:"mint,omitempty"` + IsSystemTx *bool `json:"isSystemTx,omitempty"` // deposit-tx post-Canyon only DepositReceiptVersion *hexutil.Uint64 `json:"depositReceiptVersion,omitempty"` } @@ -476,23 +477,13 @@ func newRPCTransaction(tx types.Transaction, blockHash libcommon.Hash, blockNumb result.Accesses = &t.AccessList // if the transaction has been mined, compute the effective gas price result.GasPrice = computeGasPrice(tx, blockHash, baseFee) - case *types.BlobTx: - chainId.Set(t.ChainID) - result.ChainID = (*hexutil.Big)(chainId.ToBig()) - result.Tip = (*hexutil.Big)(t.Tip.ToBig()) - result.FeeCap = (*hexutil.Big)(t.FeeCap.ToBig()) - result.V = (*hexutil.Big)(t.V.ToBig()) - result.R = (*hexutil.Big)(t.R.ToBig()) - result.S = (*hexutil.Big)(t.S.ToBig()) - result.Accesses = &t.AccessList - // if the transaction has been mined, compute the effective gas price - result.GasPrice = computeGasPrice(tx, blockHash, baseFee) - result.MaxFeePerBlobGas = (*hexutil.Big)(t.MaxFeePerBlobGas.ToBig()) - result.BlobVersionedHashes = t.GetBlobHashes() case *types.DepositTx: + if t.Mint != nil { + result.Mint = (*hexutil.Big)(t.Mint.ToBig()) + } result.SourceHash = &t.SourceHash if t.IsSystemTransaction { - result.IsSystemTx = t.IsSystemTransaction + result.IsSystemTx = &t.IsSystemTransaction } if receipt != nil && receipt.DepositNonce != nil { result.Nonce = hexutil.Uint64(*receipt.DepositNonce) @@ -501,12 +492,24 @@ func newRPCTransaction(tx types.Transaction, blockHash libcommon.Hash, blockNumb *result.DepositReceiptVersion = hexutil.Uint64(*receipt.DepositReceiptVersion) } } - result.Mint = (*hexutil.Big)(t.Mint.ToBig()) result.GasPrice = (*hexutil.Big)(libcommon.Big0) // must contain v, r, s values for backwards compatibility. result.V = (*hexutil.Big)(libcommon.Big0) result.R = (*hexutil.Big)(libcommon.Big0) result.S = (*hexutil.Big)(libcommon.Big0) + case *types.BlobTx: + chainId.Set(t.ChainID) + result.ChainID = (*hexutil.Big)(chainId.ToBig()) + result.Tip = (*hexutil.Big)(t.Tip.ToBig()) + result.FeeCap = (*hexutil.Big)(t.FeeCap.ToBig()) + result.V = (*hexutil.Big)(t.V.ToBig()) + result.R = (*hexutil.Big)(t.R.ToBig()) + result.S = (*hexutil.Big)(t.S.ToBig()) + result.Accesses = &t.AccessList + // if the transaction has been mined, compute the effective gas price + result.GasPrice = computeGasPrice(tx, blockHash, baseFee) + result.MaxFeePerBlobGas = (*hexutil.Big)(t.MaxFeePerBlobGas.ToBig()) + result.BlobVersionedHashes = t.GetBlobHashes() } signer := types.LatestSignerForChainID(chainId.ToBig()) var err error diff --git a/turbo/adapter/ethapi/api_test.go b/turbo/adapter/ethapi/api_test.go index 7a5685c2b85..918cbe4acb5 100644 --- a/turbo/adapter/ethapi/api_test.go +++ b/turbo/adapter/ethapi/api_test.go @@ -20,7 +20,7 @@ func TestNewRPCTransactionDepositTx(t *testing.T) { Mint: uint256.NewInt(34), Value: uint256.NewInt(1337), } - nonce := uint64(12) + nonce := uint64(7) depositNonce := &nonce receipt := &types.Receipt{DepositNonce: depositNonce} got := newRPCTransaction(tx, libcommon.Hash{}, uint64(12), uint64(1), big.NewInt(0), receipt) @@ -31,16 +31,15 @@ func TestNewRPCTransactionDepositTx(t *testing.T) { require.Equal(t, got.S, (*hexutil.Big)(big.NewInt(0)), "newRPCTransaction().S = %v, want 0x0", got.S) // Should include deposit tx specific fields - require.Equal(t, got.SourceHash, &tx.SourceHash, "newRPCTransaction().SourceHash = %v, want %v", got.SourceHash, tx.SourceHash) - require.Equal(t, got.IsSystemTx, tx.IsSystemTransaction, "newRPCTransaction().IsSystemTx = %v, want %v", got.IsSystemTx, tx.IsSystemTransaction) + require.Equal(t, *got.SourceHash, tx.SourceHash, "newRPCTransaction().SourceHash = %v, want %v", got.SourceHash, tx.SourceHash) + require.Equal(t, *got.IsSystemTx, tx.IsSystemTransaction, "newRPCTransaction().IsSystemTransaction = %v, want %v", got.IsSystemTx, tx.IsSystemTransaction) require.Equal(t, got.Mint, (*hexutil.Big)(tx.Mint.ToBig()), "newRPCTransaction().Mint = %v, want %v", got.Mint, tx.Mint.ToBig()) - require.Equal(t, got.Nonce, (hexutil.Uint64)(nonce), "newRPCTransaction().Mint = %v, want %v", got.Nonce, nonce) + require.Equal(t, got.Nonce, (hexutil.Uint64)(nonce), "newRPCTransaction().Nonce = %v, want %v", got.Nonce, nonce) } func TestNewRPCTransactionDepositTxWithVersion(t *testing.T) { tx := &types.DepositTx{ - SourceHash: libcommon.Hash{1}, - From: libcommon.Address{1}, + SourceHash: libcommon.HexToHash("0x1234"), IsSystemTransaction: true, Mint: uint256.NewInt(34), Value: uint256.NewInt(1337), @@ -59,8 +58,8 @@ func TestNewRPCTransactionDepositTxWithVersion(t *testing.T) { require.Equal(t, got.S, (*hexutil.Big)(big.NewInt(0)), "newRPCTransaction().S = %v, want 0x0", got.S) // Should include versioned deposit tx specific fields - require.Equal(t, got.SourceHash, &tx.SourceHash, "newRPCTransaction().SourceHash = %v, want %v", got.SourceHash, tx.SourceHash) - require.Equal(t, got.IsSystemTx, tx.IsSystemTransaction, "newRPCTransaction().IsSystemTx = %v, want %v", got.IsSystemTx, tx.IsSystemTransaction) + require.Equal(t, *got.SourceHash, tx.SourceHash, "newRPCTransaction().SourceHash = %v, want %v", got.SourceHash, tx.SourceHash) + require.Equal(t, *got.IsSystemTx, tx.IsSystemTransaction, "newRPCTransaction().IsSystemTx = %v, want %v", got.IsSystemTx, tx.IsSystemTransaction) require.Equal(t, got.Mint, (*hexutil.Big)(tx.Mint.ToBig()), "newRPCTransaction().Mint = %v, want %v", got.Mint, tx.Mint.ToBig()) require.Equal(t, got.Nonce, (hexutil.Uint64)(nonce), "newRPCTransaction().Nonce = %v, want %v", got.Nonce, nonce) require.Equal(t, *got.DepositReceiptVersion, (hexutil.Uint64(version)), "newRPCTransaction().DepositReceiptVersion = %v, want %v", *got.DepositReceiptVersion, version) @@ -77,12 +76,11 @@ func TestNewRPCTransactionDepositTxWithVersion(t *testing.T) { func TestNewRPCTransactionOmitIsSystemTxFalse(t *testing.T) { tx := &types.DepositTx{ IsSystemTransaction: false, - From: libcommon.Address{1}, Value: uint256.NewInt(1337), } got := newRPCTransaction(tx, libcommon.Hash{}, uint64(12), uint64(1), big.NewInt(0), nil) - require.False(t, got.IsSystemTx, "should omit IsSystemTx when false") + require.Nil(t, got.IsSystemTx, "should omit IsSystemTx when false") } func TestUnmarshalRpcDepositTx(t *testing.T) { @@ -156,8 +154,7 @@ func TestUnmarshalRpcDepositTx(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { tx := &types.DepositTx{ - SourceHash: libcommon.Hash{1}, - From: libcommon.Address{1}, + SourceHash: libcommon.HexToHash("0x1234"), IsSystemTransaction: true, Mint: uint256.NewInt(34), Value: uint256.NewInt(1337), diff --git a/turbo/engineapi/engine_server.go b/turbo/engineapi/engine_server.go index 97db165c853..8fde4da74d9 100644 --- a/turbo/engineapi/engine_server.go +++ b/turbo/engineapi/engine_server.go @@ -493,20 +493,19 @@ func (s *EngineServer) forkchoiceUpdated(ctx context.Context, forkchoiceState *e headHeader := s.chainRW.GetHeaderByHash(forkchoiceState.HeadHash) - if headHeader.Hash() != forkchoiceState.HeadHash { - // Optimism deviates slightly and allows arbitrary depth re-orgs. - if s.config.Optimism == nil { - // Per Item 2 of https://github.com/ethereum/execution-apis/blob/v1.0.0-alpha.9/src/engine/specification.md#specification-1: - // Client software MAY skip an update of the forkchoice state and - // MUST NOT begin a payload build process if forkchoiceState.headBlockHash doesn't reference a leaf of the block tree. - // That is, the block referenced by forkchoiceState.headBlockHash is neither the head of the canonical chain nor a block at the tip of any other chain. - // In the case of such an event, client software MUST return - // {payloadStatus: {status: VALID, latestValidHash: forkchoiceState.headBlockHash, validationError: null}, payloadId: null}. - - s.logger.Warn("Skipping payload building because forkchoiceState.headBlockHash is not the head of the canonical chain", - "forkChoice.HeadBlockHash", forkchoiceState.HeadHash, "headHeader.Hash", headHeader.Hash()) - return &engine_types.ForkChoiceUpdatedResponse{PayloadStatus: status}, nil - } + if headHeader.Hash() != forkchoiceState.HeadHash && s.config.Optimism == nil { + // Per Item 2 of https://github.com/ethereum/execution-apis/blob/v1.0.0-alpha.9/src/engine/specification.md#specification-1: + // Client software MAY skip an update of the forkchoice state and + // MUST NOT begin a payload build process if forkchoiceState.headBlockHash doesn't reference a leaf of the block tree. + // That is, the block referenced by forkchoiceState.headBlockHash is neither the head of the canonical chain nor a block at the tip of any other chain. + // In the case of such an event, client software MUST return + // {payloadStatus: {status: VALID, latestValidHash: forkchoiceState.headBlockHash, validationError: null}, payloadId: null}. + // We skip this check in the Optimism case as Optimism allows arbitrary + // depth re-orgs + + s.logger.Warn("Skipping payload building because forkchoiceState.headBlockHash is not the head of the canonical chain", + "forkChoice.HeadBlockHash", forkchoiceState.HeadHash, "headHeader.Hash", headHeader.Hash()) + return &engine_types.ForkChoiceUpdatedResponse{PayloadStatus: status}, nil } log.Debug("Continuing EngineForkChoiceUpdated", "headNumber", headHeader.Number, "headHash", headHeader.Hash(), "numDeposits", len(payloadAttributes.Transactions)) diff --git a/turbo/engineapi/engine_types/jsonrpc.go b/turbo/engineapi/engine_types/jsonrpc.go index e8248ef0f7f..3032eaeb104 100644 --- a/turbo/engineapi/engine_types/jsonrpc.go +++ b/turbo/engineapi/engine_types/jsonrpc.go @@ -50,9 +50,11 @@ type PayloadAttributes struct { SuggestedFeeRecipient common.Address `json:"suggestedFeeRecipient" gencodec:"required"` Withdrawals []*types.Withdrawal `json:"withdrawals"` ParentBeaconBlockRoot *common.Hash `json:"parentBeaconBlockRoot"` - GasLimit *hexutil.Uint64 `json:"gasLimit,omitempty"` - Transactions []hexutility.Bytes `json:"transactions,omitempty"` - NoTxPool bool `json:"noTxPool,omitempty"` + + // optimism + Transactions []hexutility.Bytes `json:"transactions,omitempty"` + NoTxPool bool `json:"noTxPool,omitempty"` + GasLimit *hexutil.Uint64 `json:"gasLimit,omitempty"` } // TransitionConfiguration represents the correct configurations of the CL and the EL @@ -90,8 +92,10 @@ type GetPayloadResponse struct { ExecutionPayload *ExecutionPayload `json:"executionPayload" gencodec:"required"` BlockValue *hexutil.Big `json:"blockValue"` BlobsBundle *BlobsBundleV1 `json:"blobsBundle"` - ParentBeaconBlockRoot *common.Hash `json:"parentBeaconBlockRoot"` ShouldOverrideBuilder bool `json:"shouldOverrideBuilder"` + + // OP-Stack: Ecotone specific fields + ParentBeaconBlockRoot *common.Hash `json:"parentBeaconBlockRoot"` } type StringifiedError struct{ err error }