From ecd6a357ea594bfd3fb81aa1b803b9fd4ac630e8 Mon Sep 17 00:00:00 2001 From: ylsGit Date: Wed, 5 Jun 2024 13:53:17 +0800 Subject: [PATCH] dynamic config blockedlist (#216) * dynamic config blockedlist * rm: update dynamic config to db --- docs/config-file/node-config-doc.html | 2 +- docs/config-file/node-config-doc.md | 26 +++++++++++++++--------- docs/config-file/node-config-schema.json | 9 +++++++- pool/apollo_xlayer.go | 21 +++++++++++++++++++ pool/config.go | 2 ++ pool/pool.go | 4 ++-- pool/pool_xlayer.go | 10 +++++++++ 7 files changed, 60 insertions(+), 14 deletions(-) diff --git a/docs/config-file/node-config-doc.html b/docs/config-file/node-config-doc.html index dcdd35fb91..858b9034fd 100644 --- a/docs/config-file/node-config-doc.html +++ b/docs/config-file/node-config-doc.html @@ -14,7 +14,7 @@
"300ms"
 

Default: "15s"Type: string

PollMinAllowedGasPriceInterval is the interval to poll the suggested min gas price for a tx


Examples:

"1m"
 
"300ms"
-

Default: 64Type: integer

AccountQueue represents the maximum number of non-executable transaction slots permitted per account


Default: 1024Type: integer

GlobalQueue represents the maximum number of non-executable transaction slots for all accounts


EffectiveGasPrice is the config for the effective gas price calculation
Default: falseType: boolean

Enabled is a flag to enable/disable the effective gas price


Default: 0.25Type: number

L1GasPriceFactor is the percentage of the L1 gas price that will be used as the L2 min gas price


Default: 16Type: integer

ByteGasCost is the gas cost per byte that is not 0


Default: 4Type: integer

ZeroByteGasCost is the gas cost per byte that is 0


Default: 1Type: number

NetProfit is the profit margin to apply to the calculated breakEvenGasPrice


Default: 1.1Type: number

BreakEvenFactor is the factor to apply to the calculated breakevenGasPrice when comparing it with the gasPriceSigned of a tx


Default: 10Type: integer

FinalDeviationPct is the max allowed deviation percentage BreakEvenGasPrice on re-calculation


Default: 0Type: integer

EthTransferGasPrice is the fixed gas price returned as effective gas price for txs tha are ETH transfers (0 means disabled)
Only one of EthTransferGasPrice or EthTransferL1GasPriceFactor params can be different than 0. If both params are set to 0, the sequencer will halt and log an error


Default: 0Type: number

EthTransferL1GasPriceFactor is the percentage of L1 gas price returned as effective gas price for txs tha are ETH transfers (0 means disabled)
Only one of EthTransferGasPrice or EthTransferL1GasPriceFactor params can be different than 0. If both params are set to 0, the sequencer will halt and log an error


Default: 0.5Type: number

L2GasPriceSuggesterFactor is the factor to apply to L1 gas price to get the suggested L2 gas price used in the
calculations when the effective gas price is disabled (testing/metrics purposes)


Default: 0Type: integer

ForkID is the current fork ID of the chain


Default: ["0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"]Type: array of string

XLayer config
FreeGasAddress is the default free gas address

Each item of this array must be:


Default: 150000Type: integer

FreeClaimGasLimit is the max gas allowed use to do a free claim


Type: array of string

BridgeClaimMethodSignature for tracking BridgeClaimMethodSignature method

Each item of this array must be:


Default: falseType: boolean

EnableFreeGasByNonce enable free gas


Type: array of string

FreeGasExAddress is the ex address which can be free gas for the transfer receiver

Each item of this array must be:


Default: 0Type: integer

FreeGasCountPerAddr is the count limit of free gas tx per address


Default: 0Type: integer

FreeGasLimit is the max gas allowed use to do a free gas tx


Configuration for RPC service. THis one offers a extended Ethereum JSON-RPC API interface to interact with the node
Default: "0.0.0.0"Type: string

Host defines the network adapter that will be used to serve the HTTP requests


Default: 8545Type: integer

Port defines the port to serve the endpoints via HTTP


Default: "1m0s"Type: string

ReadTimeout is the HTTP server read timeout
check net/http.server.ReadTimeout and net/http.server.ReadHeaderTimeout


Examples:

"1m"
+

Default: 64Type: integer

AccountQueue represents the maximum number of non-executable transaction slots permitted per account


Default: 1024Type: integer

GlobalQueue represents the maximum number of non-executable transaction slots for all accounts


EffectiveGasPrice is the config for the effective gas price calculation
Default: falseType: boolean

Enabled is a flag to enable/disable the effective gas price


Default: 0.25Type: number

L1GasPriceFactor is the percentage of the L1 gas price that will be used as the L2 min gas price


Default: 16Type: integer

ByteGasCost is the gas cost per byte that is not 0


Default: 4Type: integer

ZeroByteGasCost is the gas cost per byte that is 0


Default: 1Type: number

NetProfit is the profit margin to apply to the calculated breakEvenGasPrice


Default: 1.1Type: number

BreakEvenFactor is the factor to apply to the calculated breakevenGasPrice when comparing it with the gasPriceSigned of a tx


Default: 10Type: integer

FinalDeviationPct is the max allowed deviation percentage BreakEvenGasPrice on re-calculation


Default: 0Type: integer

EthTransferGasPrice is the fixed gas price returned as effective gas price for txs tha are ETH transfers (0 means disabled)
Only one of EthTransferGasPrice or EthTransferL1GasPriceFactor params can be different than 0. If both params are set to 0, the sequencer will halt and log an error


Default: 0Type: number

EthTransferL1GasPriceFactor is the percentage of L1 gas price returned as effective gas price for txs tha are ETH transfers (0 means disabled)
Only one of EthTransferGasPrice or EthTransferL1GasPriceFactor params can be different than 0. If both params are set to 0, the sequencer will halt and log an error


Default: 0.5Type: number

L2GasPriceSuggesterFactor is the factor to apply to L1 gas price to get the suggested L2 gas price used in the
calculations when the effective gas price is disabled (testing/metrics purposes)


Default: 0Type: integer

ForkID is the current fork ID of the chain


Type: array of string

XLayer config
BlockedList is the blocked address list

Each item of this array must be:


Default: ["0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"]Type: array of string

FreeGasAddress is the default free gas address

Each item of this array must be:


Default: 150000Type: integer

FreeClaimGasLimit is the max gas allowed use to do a free claim


Type: array of string

BridgeClaimMethodSignature for tracking BridgeClaimMethodSignature method

Each item of this array must be:


Default: falseType: boolean

EnableFreeGasByNonce enable free gas


Type: array of string

FreeGasExAddress is the ex address which can be free gas for the transfer receiver

Each item of this array must be:


Default: 0Type: integer

FreeGasCountPerAddr is the count limit of free gas tx per address


Default: 0Type: integer

FreeGasLimit is the max gas allowed use to do a free gas tx


Configuration for RPC service. THis one offers a extended Ethereum JSON-RPC API interface to interact with the node
Default: "0.0.0.0"Type: string

Host defines the network adapter that will be used to serve the HTTP requests


Default: 8545Type: integer

Port defines the port to serve the endpoints via HTTP


Default: "1m0s"Type: string

ReadTimeout is the HTTP server read timeout
check net/http.server.ReadTimeout and net/http.server.ReadHeaderTimeout


Examples:

"1m"
 
"300ms"
 

Default: "1m0s"Type: string

WriteTimeout is the HTTP server write timeout
check net/http.server.WriteTimeout


Examples:

"1m"
 
"300ms"
diff --git a/docs/config-file/node-config-doc.md b/docs/config-file/node-config-doc.md
index afc70c08a7..4ece9c91a1 100644
--- a/docs/config-file/node-config-doc.md
+++ b/docs/config-file/node-config-doc.md
@@ -706,7 +706,8 @@ SecretKey=""
 | - [GlobalQueue](#Pool_GlobalQueue )                                             | No      | integer         | No         | -          | GlobalQueue represents the maximum number of non-executable transaction slots for all accounts       |
 | - [EffectiveGasPrice](#Pool_EffectiveGasPrice )                                 | No      | object          | No         | -          | EffectiveGasPrice is the config for the effective gas price calculation                              |
 | - [ForkID](#Pool_ForkID )                                                       | No      | integer         | No         | -          | ForkID is the current fork ID of the chain                                                           |
-| - [FreeGasAddress](#Pool_FreeGasAddress )                                       | No      | array of string | No         | -          | XLayer config
FreeGasAddress is the default free gas address | +| - [BlockedList](#Pool_BlockedList ) | No | array of string | No | - | XLayer config
BlockedList is the blocked address list | +| - [FreeGasAddress](#Pool_FreeGasAddress ) | No | array of string | No | - | FreeGasAddress is the default free gas address | | - [FreeClaimGasLimit](#Pool_FreeClaimGasLimit ) | No | integer | No | - | FreeClaimGasLimit is the max gas allowed use to do a free claim | | - [BridgeClaimMethodSigs](#Pool_BridgeClaimMethodSigs ) | No | array of string | No | - | BridgeClaimMethodSignature for tracking BridgeClaimMethodSignature method | | - [EnableFreeGasByNonce](#Pool_EnableFreeGasByNonce ) | No | boolean | No | - | EnableFreeGasByNonce enable free gas | @@ -1218,14 +1219,19 @@ L2GasPriceSuggesterFactor=0.5 ForkID=0 ``` -### 7.15. `Pool.FreeGasAddress` +### 7.15. `Pool.BlockedList` + +**Type:** : `array of string` +**Description:** XLayer config +BlockedList is the blocked address list + +### 7.16. `Pool.FreeGasAddress` **Type:** : `array of string` **Default:** `["0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"]` -**Description:** XLayer config -FreeGasAddress is the default free gas address +**Description:** FreeGasAddress is the default free gas address **Example setting the default value** (["0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"]): ``` @@ -1233,7 +1239,7 @@ FreeGasAddress is the default free gas address FreeGasAddress=["0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"] ``` -### 7.16. `Pool.FreeClaimGasLimit` +### 7.17. `Pool.FreeClaimGasLimit` **Type:** : `integer` @@ -1247,12 +1253,12 @@ FreeGasAddress=["0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"] FreeClaimGasLimit=150000 ``` -### 7.17. `Pool.BridgeClaimMethodSigs` +### 7.18. `Pool.BridgeClaimMethodSigs` **Type:** : `array of string` **Description:** BridgeClaimMethodSignature for tracking BridgeClaimMethodSignature method -### 7.18. `Pool.EnableFreeGasByNonce` +### 7.19. `Pool.EnableFreeGasByNonce` **Type:** : `boolean` @@ -1266,12 +1272,12 @@ FreeClaimGasLimit=150000 EnableFreeGasByNonce=false ``` -### 7.19. `Pool.FreeGasExAddress` +### 7.20. `Pool.FreeGasExAddress` **Type:** : `array of string` **Description:** FreeGasExAddress is the ex address which can be free gas for the transfer receiver -### 7.20. `Pool.FreeGasCountPerAddr` +### 7.21. `Pool.FreeGasCountPerAddr` **Type:** : `integer` @@ -1285,7 +1291,7 @@ EnableFreeGasByNonce=false FreeGasCountPerAddr=0 ``` -### 7.21. `Pool.FreeGasLimit` +### 7.22. `Pool.FreeGasLimit` **Type:** : `integer` diff --git a/docs/config-file/node-config-schema.json b/docs/config-file/node-config-schema.json index 5d48e11755..41582e91f3 100644 --- a/docs/config-file/node-config-schema.json +++ b/docs/config-file/node-config-schema.json @@ -450,12 +450,19 @@ "description": "ForkID is the current fork ID of the chain", "default": 0 }, + "BlockedList": { + "items": { + "type": "string" + }, + "type": "array", + "description": "XLayer config\nBlockedList is the blocked address list" + }, "FreeGasAddress": { "items": { "type": "string" }, "type": "array", - "description": "XLayer config\nFreeGasAddress is the default free gas address", + "description": "FreeGasAddress is the default free gas address", "default": [ "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266" ] diff --git a/pool/apollo_xlayer.go b/pool/apollo_xlayer.go index d0fd26d969..bad98fad87 100644 --- a/pool/apollo_xlayer.go +++ b/pool/apollo_xlayer.go @@ -21,6 +21,8 @@ type apolloConfig struct { FreeGasCountPerAddr uint64 FreeGasLimit uint64 + BlockedList []string + sync.RWMutex } @@ -49,6 +51,14 @@ func (c *apolloConfig) setFreeGasAddresses(freeGasAddrs []string) { copy(c.FreeGasAddresses, freeGasAddrs) } +func (c *apolloConfig) setBlockedList(blockedAddrs []string) { + if c == nil || !c.EnableApollo { + return + } + c.BlockedList = make([]string, len(blockedAddrs)) + copy(c.BlockedList, blockedAddrs) +} + func (c *apolloConfig) setFreeGasExAddresses(freeGasExAddrs []string) { if c == nil || !c.EnableApollo { return @@ -77,6 +87,7 @@ func UpdateConfig(apolloConfig Config) { getApolloConfig().GlobalQueue = apolloConfig.GlobalQueue getApolloConfig().AccountQueue = apolloConfig.AccountQueue getApolloConfig().setFreeGasAddresses(apolloConfig.FreeGasAddress) + getApolloConfig().setBlockedList(apolloConfig.BlockedList) getApolloConfig().EnableWhitelist = apolloConfig.EnableWhitelist getApolloConfig().setBridgeClaimMethods(apolloConfig.BridgeClaimMethodSigs) @@ -181,3 +192,13 @@ func getEnableWhitelist(enableWhitelist bool) bool { return enableWhitelist } + +func isBlockedAddress(localBlockedList []string, address common.Address) bool { + if getApolloConfig().enable() { + getApolloConfig().RLock() + defer getApolloConfig().RUnlock() + return contains(getApolloConfig().BlockedList, address) + } + + return contains(localBlockedList, address) +} diff --git a/pool/config.go b/pool/config.go index 64c9137516..2dc26c1eb5 100644 --- a/pool/config.go +++ b/pool/config.go @@ -51,6 +51,8 @@ type Config struct { ForkID uint64 `mapstructure:"ForkID"` // XLayer config + // BlockedList is the blocked address list + BlockedList []string `mapstructure:"BlockedList"` // FreeGasAddress is the default free gas address FreeGasAddress []string `mapstructure:"FreeGasAddress"` // FreeClaimGasLimit is the max gas allowed use to do a free claim diff --git a/pool/pool.go b/pool/pool.go index b912f86c29..627dfb5a18 100644 --- a/pool/pool.go +++ b/pool/pool.go @@ -467,7 +467,7 @@ func (p *Pool) validateTx(ctx context.Context, poolTx Transaction) error { } // check if sender is blocked - _, blocked := p.blockedAddresses.Load(from.String()) + blocked := p.checkBlockedAddr(from) if blocked { log.Infof("%v: %v", ErrBlockedSender.Error(), from.String()) return ErrBlockedSender @@ -475,7 +475,7 @@ func (p *Pool) validateTx(ctx context.Context, poolTx Transaction) error { // check if receiver is blocked if to := poolTx.To(); to != nil { - _, blocked = p.blockedAddresses.Load(to.String()) + blocked = p.checkBlockedAddr(*to) if blocked { log.Infof("%v: %v", ErrBlockedReceiver.Error(), to.String()) return ErrBlockedReceiver diff --git a/pool/pool_xlayer.go b/pool/pool_xlayer.go index b1f29a500c..ce7b4f1f3a 100644 --- a/pool/pool_xlayer.go +++ b/pool/pool_xlayer.go @@ -198,3 +198,13 @@ func (p *Pool) AddDynamicGp(dgp *big.Int) { p.dynamicGasPrice = result p.dgpMux.Unlock() } + +func (p *Pool) checkBlockedAddr(address common.Address) bool { + // check from db + if _, blocked := p.blockedAddresses.Load(address.String()); blocked { + return true + } + + // check from dynamic config + return isBlockedAddress(p.cfg.BlockedList, address) +}