Skip to content

Commit

Permalink
dynamic config blockedlist (#216)
Browse files Browse the repository at this point in the history
* dynamic config blockedlist

* rm: update dynamic config to db
  • Loading branch information
ylsGit authored Jun 5, 2024
1 parent bccf14c commit ecd6a35
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 14 deletions.
2 changes: 1 addition & 1 deletion docs/config-file/node-config-doc.html

Large diffs are not rendered by default.

26 changes: 16 additions & 10 deletions docs/config-file/node-config-doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<br />FreeGasAddress is the default free gas address |
| - [BlockedList](#Pool_BlockedList ) | No | array of string | No | - | XLayer config<br />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 |
Expand Down Expand Up @@ -1218,22 +1219,27 @@ L2GasPriceSuggesterFactor=0.5
ForkID=0
```

### <a name="Pool_FreeGasAddress"></a>7.15. `Pool.FreeGasAddress`
### <a name="Pool_BlockedList"></a>7.15. `Pool.BlockedList`

**Type:** : `array of string`
**Description:** XLayer config
BlockedList is the blocked address list

### <a name="Pool_FreeGasAddress"></a>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"]):
```
[Pool]
FreeGasAddress=["0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"]
```

### <a name="Pool_FreeClaimGasLimit"></a>7.16. `Pool.FreeClaimGasLimit`
### <a name="Pool_FreeClaimGasLimit"></a>7.17. `Pool.FreeClaimGasLimit`

**Type:** : `integer`

Expand All @@ -1247,12 +1253,12 @@ FreeGasAddress=["0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"]
FreeClaimGasLimit=150000
```

### <a name="Pool_BridgeClaimMethodSigs"></a>7.17. `Pool.BridgeClaimMethodSigs`
### <a name="Pool_BridgeClaimMethodSigs"></a>7.18. `Pool.BridgeClaimMethodSigs`

**Type:** : `array of string`
**Description:** BridgeClaimMethodSignature for tracking BridgeClaimMethodSignature method

### <a name="Pool_EnableFreeGasByNonce"></a>7.18. `Pool.EnableFreeGasByNonce`
### <a name="Pool_EnableFreeGasByNonce"></a>7.19. `Pool.EnableFreeGasByNonce`

**Type:** : `boolean`

Expand All @@ -1266,12 +1272,12 @@ FreeClaimGasLimit=150000
EnableFreeGasByNonce=false
```

### <a name="Pool_FreeGasExAddress"></a>7.19. `Pool.FreeGasExAddress`
### <a name="Pool_FreeGasExAddress"></a>7.20. `Pool.FreeGasExAddress`

**Type:** : `array of string`
**Description:** FreeGasExAddress is the ex address which can be free gas for the transfer receiver

### <a name="Pool_FreeGasCountPerAddr"></a>7.20. `Pool.FreeGasCountPerAddr`
### <a name="Pool_FreeGasCountPerAddr"></a>7.21. `Pool.FreeGasCountPerAddr`

**Type:** : `integer`

Expand All @@ -1285,7 +1291,7 @@ EnableFreeGasByNonce=false
FreeGasCountPerAddr=0
```

### <a name="Pool_FreeGasLimit"></a>7.21. `Pool.FreeGasLimit`
### <a name="Pool_FreeGasLimit"></a>7.22. `Pool.FreeGasLimit`

**Type:** : `integer`

Expand Down
9 changes: 8 additions & 1 deletion docs/config-file/node-config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
Expand Down
21 changes: 21 additions & 0 deletions pool/apollo_xlayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ type apolloConfig struct {
FreeGasCountPerAddr uint64
FreeGasLimit uint64

BlockedList []string

sync.RWMutex
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
}
2 changes: 2 additions & 0 deletions pool/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,15 +467,15 @@ 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
}

// 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
Expand Down
10 changes: 10 additions & 0 deletions pool/pool_xlayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit ecd6a35

Please sign in to comment.