Skip to content

Commit

Permalink
Remove support for legacy transaction types & consolidate signers
Browse files Browse the repository at this point in the history
This patch consolidates all the various Ethereum transaction types into one
transaction type equivalent to the latest London TX type (i.e. dynamic fee
type). Related logic is also updated accordingly (e.g. basefee is no longer
optional).
  • Loading branch information
wizeguyy committed Jan 25, 2023
1 parent 76d0238 commit d6fc21c
Show file tree
Hide file tree
Showing 11 changed files with 112 additions and 812 deletions.
6 changes: 1 addition & 5 deletions core/tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,11 +570,7 @@ func (pool *TxPool) local() map[common.Address]types.Transactions {
// rules and adheres to some heuristic limits of the local node (price and size).
func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
// Accept only legacy transactions until EIP-2718/2930 activates.
if !pool.eip2718 && tx.Type() != types.LegacyTxType {
return ErrTxTypeNotSupported
}
// Reject dynamic fee transactions until EIP-1559 activates.
if !pool.eip1559 && tx.Type() == types.DynamicFeeTxType {
if !pool.eip2718 {
return ErrTxTypeNotSupported
}
// Reject transactions over defined size to prevent DOS attacks
Expand Down
116 changes: 0 additions & 116 deletions core/types/access_list_tx.go

This file was deleted.

34 changes: 17 additions & 17 deletions core/types/dynamic_fee_tx.go → core/types/internal_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/dominant-strategies/go-quai/common"
)

type DynamicFeeTx struct {
type InternalTx struct {
ChainID *big.Int
Nonce uint64
GasTipCap *big.Int
Expand All @@ -40,8 +40,8 @@ type DynamicFeeTx struct {
}

// copy creates a deep copy of the transaction data and initializes all fields.
func (tx *DynamicFeeTx) copy() TxData {
cpy := &DynamicFeeTx{
func (tx *InternalTx) copy() TxData {
cpy := &InternalTx{
Nonce: tx.Nonce,
To: tx.To, // TODO: copy pointed-to address
Data: common.CopyBytes(tx.Data),
Expand Down Expand Up @@ -82,23 +82,23 @@ func (tx *DynamicFeeTx) copy() TxData {
}

// accessors for innerTx.
func (tx *DynamicFeeTx) txType() byte { return DynamicFeeTxType }
func (tx *DynamicFeeTx) chainID() *big.Int { return tx.ChainID }
func (tx *DynamicFeeTx) protected() bool { return true }
func (tx *DynamicFeeTx) accessList() AccessList { return tx.AccessList }
func (tx *DynamicFeeTx) data() []byte { return tx.Data }
func (tx *DynamicFeeTx) gas() uint64 { return tx.Gas }
func (tx *DynamicFeeTx) gasFeeCap() *big.Int { return tx.GasFeeCap }
func (tx *DynamicFeeTx) gasTipCap() *big.Int { return tx.GasTipCap }
func (tx *DynamicFeeTx) gasPrice() *big.Int { return tx.GasFeeCap }
func (tx *DynamicFeeTx) value() *big.Int { return tx.Value }
func (tx *DynamicFeeTx) nonce() uint64 { return tx.Nonce }
func (tx *DynamicFeeTx) to() *common.Address { return tx.To }
func (tx *InternalTx) txType() byte { return InternalTxType }
func (tx *InternalTx) chainID() *big.Int { return tx.ChainID }
func (tx *InternalTx) protected() bool { return true }
func (tx *InternalTx) accessList() AccessList { return tx.AccessList }
func (tx *InternalTx) data() []byte { return tx.Data }
func (tx *InternalTx) gas() uint64 { return tx.Gas }
func (tx *InternalTx) gasFeeCap() *big.Int { return tx.GasFeeCap }
func (tx *InternalTx) gasTipCap() *big.Int { return tx.GasTipCap }
func (tx *InternalTx) gasPrice() *big.Int { return tx.GasFeeCap }
func (tx *InternalTx) value() *big.Int { return tx.Value }
func (tx *InternalTx) nonce() uint64 { return tx.Nonce }
func (tx *InternalTx) to() *common.Address { return tx.To }

func (tx *DynamicFeeTx) rawSignatureValues() (v, r, s *big.Int) {
func (tx *InternalTx) rawSignatureValues() (v, r, s *big.Int) {
return tx.V, tx.R, tx.S
}

func (tx *DynamicFeeTx) setSignatureValues(chainID, v, r, s *big.Int) {
func (tx *InternalTx) setSignatureValues(chainID, v, r, s *big.Int) {
tx.ChainID, tx.V, tx.R, tx.S = chainID, v, r, s
}
112 changes: 0 additions & 112 deletions core/types/legacy_tx.go

This file was deleted.

24 changes: 4 additions & 20 deletions core/types/receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ type v3StoredReceiptRLP struct {
// Deprecated: create receipts using a struct literal instead.
func NewReceipt(root []byte, failed bool, cumulativeGasUsed uint64) *Receipt {
r := &Receipt{
Type: LegacyTxType,
Type: InternalTxType,
PostState: common.CopyBytes(root),
CumulativeGasUsed: cumulativeGasUsed,
}
Expand All @@ -138,9 +138,6 @@ func NewReceipt(root []byte, failed bool, cumulativeGasUsed uint64) *Receipt {
// into an RLP stream. If no post state is present, byzantium fork is assumed.
func (r *Receipt) EncodeRLP(w io.Writer) error {
data := &receiptRLP{r.statusEncoding(), r.CumulativeGasUsed, r.Bloom, r.Logs}
if r.Type == LegacyTxType {
return rlp.Encode(w, data)
}
buf := encodeBufferPool.Get().(*bytes.Buffer)
defer encodeBufferPool.Put(buf)
buf.Reset()
Expand All @@ -158,14 +155,6 @@ func (r *Receipt) DecodeRLP(s *rlp.Stream) error {
switch {
case err != nil:
return err
case kind == rlp.List:
// It's a legacy receipt.
var dec receiptRLP
if err := s.Decode(&dec); err != nil {
return err
}
r.Type = LegacyTxType
return r.setFromRLP(dec)
case kind == rlp.String:
// It's an EIP-2718 typed tx receipt.
b, err := s.Bytes()
Expand All @@ -176,7 +165,7 @@ func (r *Receipt) DecodeRLP(s *rlp.Stream) error {
return errEmptyTypedReceipt
}
r.Type = b[0]
if r.Type == AccessListTxType || r.Type == DynamicFeeTxType {
if r.Type == InternalTxType {
var dec receiptRLP
if err := rlp.DecodeBytes(b[1:], &dec); err != nil {
return err
Expand Down Expand Up @@ -337,13 +326,8 @@ func (rs Receipts) EncodeIndex(i int, w *bytes.Buffer) {
r := rs[i]
data := &receiptRLP{r.statusEncoding(), r.CumulativeGasUsed, r.Bloom, r.Logs}
switch r.Type {
case LegacyTxType:
rlp.Encode(w, data)
case AccessListTxType:
w.WriteByte(AccessListTxType)
rlp.Encode(w, data)
case DynamicFeeTxType:
w.WriteByte(DynamicFeeTxType)
case InternalTxType:
w.WriteByte(InternalTxType)
rlp.Encode(w, data)
default:
// For unsupported types, write nothing. Since this is for
Expand Down
Loading

0 comments on commit d6fc21c

Please sign in to comment.