From 783d46f29ebc00a4b6b8222d485c8de60df92196 Mon Sep 17 00:00:00 2001 From: Daniel Liu Date: Thu, 20 Feb 2025 11:07:50 +0800 Subject: [PATCH 1/3] core/types: remove unused error variables --- core/types/transaction.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/core/types/transaction.go b/core/types/transaction.go index a9e3903881..e99519d5c7 100644 --- a/core/types/transaction.go +++ b/core/types/transaction.go @@ -39,11 +39,6 @@ var ( ErrTxTypeNotSupported = errors.New("transaction type not supported") ErrGasFeeCapTooLow = errors.New("fee cap less than base fee") errShortTypedTx = errors.New("typed transaction too short") - errInvalidYParity = errors.New("'yParity' field must be 0 or 1") - errVYParityMismatch = errors.New("'v' and 'yParity' fields do not match") - errVYParityMissing = errors.New("missing 'yParity' or 'v' field in transaction") - errNoSigner = errors.New("missing signing methods") - ErrFeeCapTooLow = errors.New("fee cap less than base fee") skipNonceDestinationAddress = map[common.Address]bool{ common.XDCXAddrBinary: true, From 4f8d11e11dcdef566c343ce3025acfee61e44ef4 Mon Sep 17 00:00:00 2001 From: Daniel Liu Date: Thu, 20 Feb 2025 11:25:55 +0800 Subject: [PATCH 2/3] core: fix BlockSigner tx cause debug API fail after EIP-1559 --- core/state_transition.go | 2 +- core/types/transaction.go | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/core/state_transition.go b/core/state_transition.go index 1bba04e2fa..3c829f7983 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -289,7 +289,7 @@ func (st *StateTransition) preCheck() error { } // This will panic if baseFee is nil, but basefee presence is verified // as part of header validation. - if (msg.To() == nil || *msg.To() != common.RandomizeSMCBinary) && st.gasFeeCap.Cmp(st.evm.Context.BaseFee) < 0 { + if !types.IsSpecialTx(msg.To()) && st.gasFeeCap.Cmp(st.evm.Context.BaseFee) < 0 { return fmt.Errorf("%w: address %v, maxFeePerGas: %s baseFee: %s", ErrFeeCapTooLow, msg.From().Hex(), st.gasFeeCap, st.evm.Context.BaseFee) } diff --git a/core/types/transaction.go b/core/types/transaction.go index e99519d5c7..273d33eb8b 100644 --- a/core/types/transaction.go +++ b/core/types/transaction.go @@ -482,11 +482,14 @@ func (tx *Transaction) TxCost(number *big.Int) *big.Int { return total } -func (tx *Transaction) IsSpecialTransaction() bool { - to := tx.To() +func IsSpecialTx(to *common.Address) bool { return to != nil && (*to == common.BlockSignersBinary || *to == common.RandomizeSMCBinary) } +func (tx *Transaction) IsSpecialTransaction() bool { + return IsSpecialTx(tx.To()) +} + func (tx *Transaction) IsTradingTransaction() bool { to := tx.To() return to != nil && *to == common.XDCXAddrBinary From b60396a233a10009aa2b0c0086ee36617be95558 Mon Sep 17 00:00:00 2001 From: Daniel Liu Date: Thu, 20 Feb 2025 12:48:17 +0800 Subject: [PATCH 3/3] core, internal/ethapi: improve function IsSpecialTransaction --- core/txpool/list.go | 2 +- core/txpool/txpool.go | 4 ++-- core/types/transaction.go | 2 +- internal/ethapi/api.go | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/core/txpool/list.go b/core/txpool/list.go index 70d2322f96..8b22abffea 100644 --- a/core/txpool/list.go +++ b/core/txpool/list.go @@ -281,7 +281,7 @@ func (l *list) Overlaps(tx *types.Transaction) bool { func (l *list) Add(tx *types.Transaction, priceBump uint64) (bool, *types.Transaction) { // If there's an older better transaction, abort old := l.txs.Get(tx.Nonce()) - if old != nil && old.IsSpecialTransaction() { + if old.IsSpecialTransaction() { return false, nil } if old != nil { diff --git a/core/txpool/txpool.go b/core/txpool/txpool.go index 50a916626e..f38f666334 100644 --- a/core/txpool/txpool.go +++ b/core/txpool/txpool.go @@ -700,7 +700,7 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error { return core.ErrInsufficientFunds } - if tx.To() == nil || (tx.To() != nil && !tx.IsSpecialTransaction()) { + if !tx.IsSpecialTransaction() { // Ensure the transaction has more gas than the basic tx fee. intrGas, err := core.IntrinsicGas(tx.Data(), tx.AccessList(), tx.To() == nil, true, pool.eip1559) if err != nil { @@ -950,7 +950,7 @@ func (pool *TxPool) promoteSpecialTx(addr common.Address, tx *types.Transaction, list := pool.pending[addr] old := list.txs.Get(tx.Nonce()) - if old != nil && old.IsSpecialTransaction() { + if old.IsSpecialTransaction() { return false, ErrDuplicateSpecialTransaction } // Otherwise discard any previous transaction and mark this diff --git a/core/types/transaction.go b/core/types/transaction.go index 273d33eb8b..369127c4c0 100644 --- a/core/types/transaction.go +++ b/core/types/transaction.go @@ -487,7 +487,7 @@ func IsSpecialTx(to *common.Address) bool { } func (tx *Transaction) IsSpecialTransaction() bool { - return IsSpecialTx(tx.To()) + return tx != nil && IsSpecialTx(tx.To()) } func (tx *Transaction) IsTradingTransaction() bool { diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index b306553f09..c3d77c6416 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -2294,7 +2294,7 @@ func (s *PublicTransactionPoolAPI) sign(addr common.Address, tx *types.Transacti // SubmitTransaction is a helper function that submits tx to txPool and logs a message. func SubmitTransaction(ctx context.Context, b Backend, tx *types.Transaction) (common.Hash, error) { - if tx.To() != nil && tx.IsSpecialTransaction() { + if tx.IsSpecialTransaction() { return common.Hash{}, errors.New("don't allow transaction sent to BlockSigners & RandomizeSMC smart contract via API") }