Skip to content

Commit

Permalink
implement span batch support for 7702 txs
Browse files Browse the repository at this point in the history
  • Loading branch information
Rjected committed Aug 14, 2024
1 parent 3889a03 commit dcc0809
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
43 changes: 43 additions & 0 deletions op-node/rollup/derive/span_batch_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/rlp"
"github.com/holiman/uint256"
)

type spanBatchTxData interface {
Expand Down Expand Up @@ -45,6 +46,17 @@ type spanBatchDynamicFeeTxData struct {

func (txData *spanBatchDynamicFeeTxData) txType() byte { return types.DynamicFeeTxType }

type spanBatchSetCodeTxData struct {
Value *uint256.Int
GasTipCap *uint256.Int // a.k.a. maxPriorityFeePerGas
GasFeeCap *uint256.Int // a.k.a. maxFeePerGas
Data []byte
AccessList types.AccessList
AuthList types.AuthorizationList
}

func (txData *spanBatchSetCodeTxData) txType() byte { return types.SetCodeTxType }

// Type returns the transaction type.
func (tx *spanBatchTx) Type() uint8 {
return tx.inner.txType()
Expand Down Expand Up @@ -93,6 +105,13 @@ func (tx *spanBatchTx) decodeTyped(b []byte) (spanBatchTxData, error) {
return nil, fmt.Errorf("failed to decode spanBatchDynamicFeeTxData: %w", err)
}
return &inner, nil
case types.SetCodeTxType:
var inner spanBatchSetCodeTxData
err := rlp.DecodeBytes(b[1:], &inner)
if err != nil {
return nil, fmt.Errorf("failed to decode spanBatchSetCodeTxData: %w", err)
}
return &inner, nil
default:
return nil, types.ErrTxTypeNotSupported
}
Expand Down Expand Up @@ -168,6 +187,22 @@ func (tx *spanBatchTx) convertToFullTx(nonce, gas uint64, to *common.Address, ch
R: R,
S: S,
}
case types.SetCodeTxType:
batchTxInner := tx.inner.(*spanBatchSetCodeTxData)
inner = &types.SetCodeTx{
ChainID: uint256.MustFromBig(chainID),
Nonce: nonce,
GasTipCap: batchTxInner.GasTipCap,
GasFeeCap: batchTxInner.GasFeeCap,
Gas: gas,
To: to,
Value: batchTxInner.Value,
Data: batchTxInner.Data,
AccessList: batchTxInner.AccessList,
V: uint256.MustFromBig(V),
R: uint256.MustFromBig(R),
S: uint256.MustFromBig(S),
}
default:
return nil, fmt.Errorf("invalid tx type: %d", tx.Type())
}
Expand Down Expand Up @@ -199,6 +234,14 @@ func newSpanBatchTx(tx *types.Transaction) (*spanBatchTx, error) {
Data: tx.Data(),
AccessList: tx.AccessList(),
}
case types.SetCodeTxType:
inner = &spanBatchSetCodeTxData{
GasTipCap: uint256.MustFromBig(tx.GasTipCap()),
GasFeeCap: uint256.MustFromBig(tx.GasFeeCap()),
Value: uint256.MustFromBig(tx.Value()),
Data: tx.Data(),
AccessList: tx.AccessList(),
}
default:
return nil, fmt.Errorf("invalid tx type: %d", tx.Type())
}
Expand Down
4 changes: 4 additions & 0 deletions op-node/rollup/derive/span_batch_txs.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ func (btx *spanBatchTxs) recoverV(chainID *big.Int) error {
v = bit
case types.DynamicFeeTxType:
v = bit
case types.SetCodeTxType:
v = bit
default:
return fmt.Errorf("invalid tx type: %d", txType)
}
Expand Down Expand Up @@ -386,6 +388,8 @@ func convertVToYParity(v uint64, txType int) (uint, error) {
yParityBit = uint(v)
case types.DynamicFeeTxType:
yParityBit = uint(v)
case types.SetCodeTxType:
yParityBit = uint(v)
default:
return 0, fmt.Errorf("invalid tx type: %d", txType)
}
Expand Down

0 comments on commit dcc0809

Please sign in to comment.