From 4d8aafde3da43d2779e75385d432eaab5ee94269 Mon Sep 17 00:00:00 2001 From: Daniel Liu Date: Wed, 22 Oct 2025 17:15:28 +0800 Subject: [PATCH] core, miner: fix inconsistent tx blacklist enforcement, close XFN-98 --- core/state_processor.go | 4 ++-- core/txpool/txpool.go | 23 +++++++++++++---------- miner/worker.go | 6 ++---- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/core/state_processor.go b/core/state_processor.go index 03d531a2b62b..6156db3240fe 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -94,7 +94,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, tra // Iterate over and process the individual transactions for i, tx := range block.Transactions() { // check black-list txs after hf - if (block.Number().Uint64() >= common.BlackListHFNumber) && !common.IsTestnet { + if block.Number().Uint64() >= common.BlackListHFNumber { // check if sender is in black list if common.IsInBlacklist(tx.From()) { return nil, nil, 0, fmt.Errorf("block contains transaction with sender in black-list: %v", tx.From().Hex()) @@ -187,7 +187,7 @@ func (p *StateProcessor) ProcessBlockNoValidator(cBlock *CalculatedBlock, stated receipts = make([]*types.Receipt, block.Transactions().Len()) for i, tx := range block.Transactions() { // check black-list txs after hf - if (block.Number().Uint64() >= common.BlackListHFNumber) && !common.IsTestnet { + if block.Number().Uint64() >= common.BlackListHFNumber { // check if sender is in black list if common.IsInBlacklist(tx.From()) { return nil, nil, 0, fmt.Errorf("block contains transaction with sender in black-list: %v", tx.From().Hex()) diff --git a/core/txpool/txpool.go b/core/txpool/txpool.go index 7928882ac1a5..b24bbc8d8e1f 100644 --- a/core/txpool/txpool.go +++ b/core/txpool/txpool.go @@ -630,13 +630,20 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error { if uint64(tx.Size()) > txMaxSize { return ErrOversizedData } - // check if sender is in black list - if common.IsInBlacklist(tx.From()) { - return fmt.Errorf("reject transaction with sender in black-list: %v", tx.From().Hex()) + // Get current block number + var number *big.Int = nil + if pool.chain.CurrentHeader() != nil { + number = pool.chain.CurrentHeader().Number } - // check if receiver is in black list - if common.IsInBlacklist(tx.To()) { - return fmt.Errorf("reject transaction with receiver in black-list: %v", tx.To().Hex()) + if number == nil || number.Uint64() >= common.BlackListHFNumber { + // check if sender is in black list + if common.IsInBlacklist(tx.From()) { + return fmt.Errorf("reject transaction with sender in black-list: %v", tx.From().Hex()) + } + // check if receiver is in black list + if common.IsInBlacklist(tx.To()) { + return fmt.Errorf("reject transaction with receiver in black-list: %v", tx.To().Hex()) + } } // Transactions can't be negative. This may never happen using RLP decoded // transactions but may occur if you create a transaction using the RPC. @@ -691,10 +698,6 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error { // cost == V + GP * GL balance := pool.currentState.GetBalance(from) cost := tx.Cost() - var number *big.Int = nil - if pool.chain.CurrentHeader() != nil { - number = pool.chain.CurrentHeader().Number - } minGasPrice := common.GetMinGasPrice(number) feeCapacity := big.NewInt(0) diff --git a/miner/worker.go b/miner/worker.go index 13fa1c5b0ce1..a5b7ca041311 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -889,8 +889,7 @@ func (w *Work) commitTransactions(mux *event.TypeMux, balanceFee map[common.Addr // first priority for special Txs for _, tx := range specialTxs { to := tx.To() - //HF number for black-list - if (w.header.Number.Uint64() >= common.BlackListHFNumber) && !common.IsTestnet { + if w.header.Number.Uint64() >= common.BlackListHFNumber { from := tx.From() // check if sender is in black list if common.IsInBlacklist(from) { @@ -1001,9 +1000,8 @@ func (w *Work) commitTransactions(mux *event.TypeMux, balanceFee map[common.Addr break } - //HF number for black-list to := tx.To() - if (w.header.Number.Uint64() >= common.BlackListHFNumber) && !common.IsTestnet { + if w.header.Number.Uint64() >= common.BlackListHFNumber { from := tx.From() // check if sender is in black list if common.IsInBlacklist(from) {