Skip to content

Commit

Permalink
More straggling testinprod/op-erigon alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
jyellick committed Feb 28, 2024
1 parent 12eac48 commit 09fc443
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 68 deletions.
2 changes: 1 addition & 1 deletion core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
)
Expand Down
14 changes: 0 additions & 14 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
14 changes: 14 additions & 0 deletions params/superchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
47 changes: 25 additions & 22 deletions turbo/adapter/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
21 changes: 9 additions & 12 deletions turbo/adapter/ethapi/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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),
Expand All @@ -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)
Expand All @@ -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) {
Expand Down Expand Up @@ -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),
Expand Down
27 changes: 13 additions & 14 deletions turbo/engineapi/engine_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
12 changes: 8 additions & 4 deletions turbo/engineapi/engine_types/jsonrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 }
Expand Down

0 comments on commit 09fc443

Please sign in to comment.