Skip to content
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

chore(rpc-types): Preferred Type #375

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions crates/rpc-types/src/transaction/request.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use alloc::vec::Vec;
use alloy_consensus::{
Sealed, SignableTransaction, Signed, TxEip1559, TxEip4844, TypedTransaction,
Sealed, SignableTransaction, Signed, TxEip1559, TxEip4844, TxType, TypedTransaction,
};
use alloy_eips::eip7702::SignedAuthorization;
use alloy_network_primitives::TransactionBuilder7702;
use alloy_primitives::{Address, PrimitiveSignature as Signature, TxKind, U256};
use alloy_rpc_types_eth::{AccessList, TransactionInput, TransactionRequest};
use op_alloy_consensus::{OpTxEnvelope, OpTypedTransaction, TxDeposit};
use op_alloy_consensus::{OpTxEnvelope, OpTxType, OpTypedTransaction, TxDeposit};
use serde::{Deserialize, Serialize};

/// Builder for [`OpTypedTransaction`].
Expand Down Expand Up @@ -90,6 +90,29 @@ impl OpTransactionRequest {
self
}

/// Check this builder's preferred type, based on the fields that are set.
///
/// Types are preferred as follows:
/// - Deposit Transactions if `chain_id` is not set
/// - EIP-7702 if authorization_list is set
/// - EIP-4844 if sidecar or max_blob_fee_per_gas is set
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// - EIP-4844 if sidecar or max_blob_fee_per_gas is set

/// - EIP-2930 if access_list is set
/// - Legacy if gas_price is set and access_list is unset
/// - EIP-1559 in all other cases
Comment on lines +97 to +101
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// - EIP-7702 if authorization_list is set
/// - EIP-4844 if sidecar or max_blob_fee_per_gas is set
/// - EIP-2930 if access_list is set
/// - Legacy if gas_price is set and access_list is unset
/// - EIP-1559 in all other cases
/// - See [`TransactionRequest::preferred_type`].

I just delegate docs when I delegate a call, that way I know I don't create doc bugs in future

pub const fn preferred_type(&self) -> OpTxType {
if self.0.chain_id.is_none() {
return OpTxType::Deposit;
}
Comment on lines +103 to +105
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function is intended for clients sending txs, should we return deposit here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense if the chain_id is none that deposit is returned and the client should reject the tx?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively we remove this and just fall-through to the TransactionReceipt

match self.0.preferred_type() {
TxType::Legacy => OpTxType::Legacy,
TxType::Eip1559 => OpTxType::Eip1559,
TxType::Eip2930 => OpTxType::Eip2930,
// EIP-4844 transactions are not supported by Optimism.
TxType::Eip4844 => OpTxType::Eip1559,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add a debug log here as well

TxType::Eip7702 => OpTxType::Eip7702,
}
}

/// Builds [`OpTypedTransaction`] from this builder. See [`TransactionRequest::build_typed_tx`]
/// for more info.
///
Expand Down
Loading