diff --git a/chains/evm/chain.go b/chains/evm/chain.go index 9324129f..50c5ecc2 100644 --- a/chains/evm/chain.go +++ b/chains/evm/chain.go @@ -8,7 +8,6 @@ import ( "fmt" "math/big" - "github.com/ChainSafe/chainbridge-core/config/chain" "github.com/ChainSafe/chainbridge-core/relayer/message" "github.com/ChainSafe/chainbridge-core/store" "github.com/rs/zerolog/log" @@ -27,11 +26,23 @@ type EVMChain struct { listener EventListener writer ProposalExecutor blockstore *store.BlockStore - config *chain.EVMConfig + + domainID uint8 + startBlock *big.Int + freshStart bool + latestBlock bool } -func NewEVMChain(listener EventListener, writer ProposalExecutor, blockstore *store.BlockStore, config *chain.EVMConfig) *EVMChain { - return &EVMChain{listener: listener, writer: writer, blockstore: blockstore, config: config} +func NewEVMChain(listener EventListener, writer ProposalExecutor, blockstore *store.BlockStore, domainID uint8, startBlock *big.Int, latestBlock bool, freshStart bool) *EVMChain { + return &EVMChain{ + listener: listener, + writer: writer, + blockstore: blockstore, + domainID: domainID, + startBlock: startBlock, + latestBlock: latestBlock, + freshStart: freshStart, + } } // PollEvents is the goroutine that polls blocks and searches Deposit events in them. @@ -40,10 +51,10 @@ func (c *EVMChain) PollEvents(ctx context.Context, sysErr chan<- error, msgChan log.Info().Msg("Polling Blocks...") startBlock, err := c.blockstore.GetStartBlock( - *c.config.GeneralChainConfig.Id, - c.config.StartBlock, - c.config.GeneralChainConfig.LatestBlock, - c.config.GeneralChainConfig.FreshStart, + c.domainID, + c.startBlock, + c.latestBlock, + c.freshStart, ) if err != nil { sysErr <- fmt.Errorf("error %w on getting last stored block", err) @@ -65,5 +76,5 @@ func (c *EVMChain) Write(msg []*message.Message) { } func (c *EVMChain) DomainID() uint8 { - return *c.config.GeneralChainConfig.Id + return c.domainID } diff --git a/chains/evm/listener/listener.go b/chains/evm/listener/listener.go index f3cf44c6..5063d70b 100644 --- a/chains/evm/listener/listener.go +++ b/chains/evm/listener/listener.go @@ -8,7 +8,6 @@ import ( "math/big" "time" - "github.com/ChainSafe/chainbridge-core/config/chain" "github.com/ChainSafe/chainbridge-core/relayer/message" "github.com/ChainSafe/chainbridge-core/store" @@ -36,15 +35,22 @@ type EVMListener struct { // NewEVMListener creates an EVMListener that listens to deposit events on chain // and calls event handler when one occurs -func NewEVMListener(client ChainClient, eventHandlers []EventHandler, blockstore *store.BlockStore, config *chain.EVMConfig) *EVMListener { +func NewEVMListener( + client ChainClient, + eventHandlers []EventHandler, + blockstore *store.BlockStore, + domainID uint8, + blockRetryInterval time.Duration, + blockConfirmations *big.Int, + blockInterval *big.Int) *EVMListener { return &EVMListener{ client: client, eventHandlers: eventHandlers, blockstore: blockstore, - domainID: *config.GeneralChainConfig.Id, - blockRetryInterval: config.BlockRetryInterval, - blockConfirmations: config.BlockConfirmations, - blockInterval: config.BlockInterval, + domainID: domainID, + blockRetryInterval: blockRetryInterval, + blockConfirmations: blockConfirmations, + blockInterval: blockInterval, } } diff --git a/example/app/app.go b/example/app/app.go index 0bafbe92..b678048e 100644 --- a/example/app/app.go +++ b/example/app/app.go @@ -76,7 +76,7 @@ func Run() error { eventListener := events.NewListener(client) eventHandlers := make([]listener.EventHandler, 0) eventHandlers = append(eventHandlers, listener.NewDepositEventHandler(eventListener, depositHandler, common.HexToAddress(config.Bridge), *config.GeneralChainConfig.Id)) - evmListener := listener.NewEVMListener(client, eventHandlers, blockstore, config) + evmListener := listener.NewEVMListener(client, eventHandlers, blockstore, *config.GeneralChainConfig.Id, config.BlockRetryInterval, config.BlockConfirmations, config.BlockInterval) mh := executor.NewEVMMessageHandler(bridgeContract) mh.RegisterMessageHandler(config.Erc20Handler, executor.ERC20MessageHandler) @@ -90,7 +90,7 @@ func Run() error { evmVoter = executor.NewVoter(mh, client, bridgeContract) } - chain := evm.NewEVMChain(evmListener, evmVoter, blockstore, config) + chain := evm.NewEVMChain(evmListener, evmVoter, blockstore, *config.GeneralChainConfig.Id, config.StartBlock, config.GeneralChainConfig.LatestBlock, config.GeneralChainConfig.FreshStart) chains = append(chains, chain) }