From 1da539d42b4c4d45a2fceba9488f687d1675d767 Mon Sep 17 00:00:00 2001 From: Kirill Fedoseev Date: Sun, 22 May 2022 13:12:30 +0400 Subject: [PATCH] Rework senders blacklist --- config.schema.json | 16 ++++++++-------- config.yml | 6 +++--- config/config.go | 28 ++++++++++++++-------------- monitor/handlers.go | 11 ++++++++--- 4 files changed, 33 insertions(+), 28 deletions(-) diff --git a/config.schema.json b/config.schema.json index 1e5dc5d..454d365 100644 --- a/config.schema.json +++ b/config.schema.json @@ -272,20 +272,20 @@ }, "end_block": { "type": "integer" + }, + "blacklisted_senders": { + "type": "array", + "minItems": 1, + "items": { + "type": "string", + "pattern": "^0x[a-fA-F0-9]{40}$" + } } }, "required": [ "address" ] } - }, - "erc_to_native_blacklisted_senders": { - "type": "array", - "minItems": 1, - "items": { - "type": "string", - "pattern": "^0x[a-fA-F0-9]{40}$" - } } }, "required": [ diff --git a/config.yml b/config.yml index dbc7c82..e139e22 100644 --- a/config.yml +++ b/config.yml @@ -80,9 +80,9 @@ bridges: end_block: 9884448 - address: 0x6B175474E89094C44Da98b954EedeAC495271d0F start_block: 8928158 - erc_to_native_blacklisted_senders: - - 0x0000000000000000000000000000000000000000 - - 0x5d3a536E4D6DbD6114cc1Ead35777bAB948E3643 + blacklisted_senders: + - 0x0000000000000000000000000000000000000000 + - 0x5d3a536E4D6DbD6114cc1Ead35777bAB948E3643 alerts: unknown_erc_to_native_message_confirmation: unknown_erc_to_native_message_execution: diff --git a/config/config.go b/config/config.go index 96c49a9..1696c14 100644 --- a/config/config.go +++ b/config/config.go @@ -32,23 +32,23 @@ type ReloadJobConfig struct { } type TokenConfig struct { - Address common.Address `yaml:"address"` - StartBlock uint `yaml:"start_block"` - EndBlock uint `yaml:"end_block"` + Address common.Address `yaml:"address"` + StartBlock uint `yaml:"start_block"` + EndBlock uint `yaml:"end_block"` + BlacklistedSenders []common.Address `yaml:"blacklisted_senders"` } type BridgeSideConfig struct { - ChainName string `yaml:"chain"` - Chain *ChainConfig `yaml:"-"` - Address common.Address `yaml:"address"` - ValidatorContractAddress common.Address `yaml:"validator_contract_address"` - StartBlock uint `yaml:"start_block"` - BlockConfirmations uint `yaml:"required_block_confirmations"` - MaxBlockRangeSize uint `yaml:"max_block_range_size"` - RefetchEvents []*ReloadJobConfig `yaml:"refetch_events"` - WhitelistedSenders []common.Address `yaml:"whitelisted_senders"` - ErcToNativeTokens []TokenConfig `yaml:"erc_to_native_tokens"` - ErcToNativeBlacklistedSenders []common.Address `yaml:"erc_to_native_blacklisted_senders"` + ChainName string `yaml:"chain"` + Chain *ChainConfig `yaml:"-"` + Address common.Address `yaml:"address"` + ValidatorContractAddress common.Address `yaml:"validator_contract_address"` + StartBlock uint `yaml:"start_block"` + BlockConfirmations uint `yaml:"required_block_confirmations"` + MaxBlockRangeSize uint `yaml:"max_block_range_size"` + RefetchEvents []*ReloadJobConfig `yaml:"refetch_events"` + WhitelistedSenders []common.Address `yaml:"whitelisted_senders"` + ErcToNativeTokens []TokenConfig `yaml:"erc_to_native_tokens"` } type BridgeAlertConfig struct { diff --git a/monitor/handlers.go b/monitor/handlers.go index b597a02..cdb178b 100644 --- a/monitor/handlers.go +++ b/monitor/handlers.go @@ -65,9 +65,14 @@ func (p *BridgeEventHandler) HandleErcToNativeTransfer(ctx context.Context, log from := data["from"].(common.Address) value := data["value"].(*big.Int) - for _, addr := range p.cfg.Foreign.ErcToNativeBlacklistedSenders { - if from == addr { - return nil + for _, token := range p.cfg.Foreign.ErcToNativeTokens { + if token.Address == log.Address { + for _, addr := range token.BlacklistedSenders { + if from == addr { + return nil + } + } + break } } logs, err := p.repo.Logs.FindByTxHash(ctx, log.TransactionHash)