From f28e4fe45d88417e39864eb42c580c3126c10986 Mon Sep 17 00:00:00 2001 From: luanxu-mxc Date: Sat, 19 Aug 2023 17:17:22 +0800 Subject: [PATCH 1/2] feat: mxc_txpool block addresses --- eth/mxc_api_backend.go | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/eth/mxc_api_backend.go b/eth/mxc_api_backend.go index b0b2e28d5d28..4163b25b76ab 100644 --- a/eth/mxc_api_backend.go +++ b/eth/mxc_api_backend.go @@ -1,7 +1,9 @@ package eth import ( + "fmt" "math/big" + "strings" "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/common" @@ -68,6 +70,7 @@ func (s *MxcAPIBackend) TxPoolContent( maxBytesPerTxList uint64, minTxGasLimit uint64, locals []string, + blockedAddresses []string, ) ([]types.Transactions, error) { pending := s.eth.TxPool().Pending(false) @@ -79,6 +82,7 @@ func (s *MxcAPIBackend) TxPoolContent( "maxBytesPerTxList", maxBytesPerTxList, "minTxGasLimit", minTxGasLimit, "locals", locals, + "blockedAddresses", blockedAddresses, ) contentSplitter, err := core.NewPoolContentSplitter( @@ -97,7 +101,7 @@ func (s *MxcAPIBackend) TxPoolContent( txsCount = 0 txLists []types.Transactions ) - for _, splittedTxs := range contentSplitter.Split(filterTxs(pending, s.eth.blockchain.CurrentHeader().BaseFee)) { + for _, splittedTxs := range contentSplitter.Split(filterTxs(filterBlockedTxs(pending, blockedAddresses), s.eth.blockchain.CurrentHeader().BaseFee)) { if txsCount+splittedTxs.Len() < int(maxTransactionsPerBlock) { txLists = append(txLists, splittedTxs) txsCount += splittedTxs.Len() @@ -111,6 +115,42 @@ func (s *MxcAPIBackend) TxPoolContent( return txLists, nil } +func filterBlockedTxs(pendings map[common.Address]types.Transactions, blockedAddresses []string) map[common.Address]types.Transactions { + if len(blockedAddresses) == 0 { + return pendings + } + var localsAddresses []common.Address + for _, account := range blockedAddresses { + if trimmed := strings.TrimSpace(account); !common.IsHexAddress(trimmed) { + log.Warn(fmt.Sprintf("Invalid address: %s", trimmed)) + } else { + localsAddresses = append(localsAddresses, common.HexToAddress(account)) + } + } + executableTxs := make(map[common.Address]types.Transactions) + + for addr, txs := range pendings { + pendingTxs := make(types.Transactions, 0) + + for _, blockedAddress := range localsAddresses { + if addr == blockedAddress { + log.Debug(fmt.Sprintf("Ignore blocked address: %s", addr.Hex())) + break + } + } + for _, tx := range txs { + pendingTxs = append(pendingTxs, tx) + } + + if len(pendingTxs) > 0 { + executableTxs[addr] = pendingTxs + } + } + + return executableTxs + +} + func filterTxs(pendings map[common.Address]types.Transactions, baseFee *big.Int) map[common.Address]types.Transactions { executableTxs := make(map[common.Address]types.Transactions) gasPriceLowerLimit := big.NewInt(0).Div(big.NewInt(0).Mul(baseFee, big.NewInt(95)), big.NewInt(100)) From 1221351860c1668e3c3b243c0e177506d52fda6e Mon Sep 17 00:00:00 2001 From: luanxu-mxc Date: Sat, 19 Aug 2023 19:17:43 +0800 Subject: [PATCH 2/2] feat: mxc_txpool block addresses --- eth/mxc_api_backend.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/eth/mxc_api_backend.go b/eth/mxc_api_backend.go index 4163b25b76ab..86602adf9b4e 100644 --- a/eth/mxc_api_backend.go +++ b/eth/mxc_api_backend.go @@ -119,12 +119,12 @@ func filterBlockedTxs(pendings map[common.Address]types.Transactions, blockedAdd if len(blockedAddresses) == 0 { return pendings } - var localsAddresses []common.Address + var ignoreAddresses []common.Address for _, account := range blockedAddresses { if trimmed := strings.TrimSpace(account); !common.IsHexAddress(trimmed) { log.Warn(fmt.Sprintf("Invalid address: %s", trimmed)) } else { - localsAddresses = append(localsAddresses, common.HexToAddress(account)) + ignoreAddresses = append(ignoreAddresses, common.HexToAddress(account)) } } executableTxs := make(map[common.Address]types.Transactions) @@ -132,12 +132,17 @@ func filterBlockedTxs(pendings map[common.Address]types.Transactions, blockedAdd for addr, txs := range pendings { pendingTxs := make(types.Transactions, 0) - for _, blockedAddress := range localsAddresses { + blocked := false + for _, blockedAddress := range ignoreAddresses { if addr == blockedAddress { log.Debug(fmt.Sprintf("Ignore blocked address: %s", addr.Hex())) + blocked = true break } } + if blocked { + continue + } for _, tx := range txs { pendingTxs = append(pendingTxs, tx) }