@@ -66,29 +66,6 @@ func enrForkIdFromState(state: BeaconState): ENRForkID =
6666 next_fork_version: forkVer,
6767 next_fork_epoch: FAR_FUTURE_EPOCH )
6868
69- proc startEth1Monitor (db: BeaconChainDB ,
70- eth1Network: Option [Eth1Network ],
71- conf: BeaconNodeConf ): Future [Eth1Monitor ] {.async .} =
72- let eth1MonitorRes = await Eth1Monitor .init (
73- db,
74- conf.runtimePreset,
75- conf.web3Url,
76- conf.depositContractAddress.get,
77- conf.depositContractDeployedAt.get,
78- eth1Network)
79-
80- result = if eth1MonitorRes.isOk:
81- eth1MonitorRes.get
82- else :
83- fatal " Failed to start Eth1 monitor" ,
84- reason = eth1MonitorRes.error,
85- web3Url = conf.web3Url,
86- depositContractAddress = conf.depositContractAddress.get,
87- depositContractDeployedAt = conf.depositContractDeployedAt.get
88- quit 1
89-
90- result .start ()
91-
9269proc init * (T: type BeaconNode ,
9370 rng: ref BrHmacDrbgContext ,
9471 conf: BeaconNodeConf ,
@@ -162,7 +139,23 @@ proc init*(T: type BeaconNode,
162139
163140 # TODO Could move this to a separate "GenesisMonitor" process or task
164141 # that would do only this - see Paul's proposal for this.
165- eth1Monitor = await startEth1Monitor (db, eth1Network, conf)
142+ let eth1MonitorRes = await Eth1Monitor .init (
143+ db,
144+ conf.runtimePreset,
145+ conf.web3Url,
146+ conf.depositContractAddress.get,
147+ conf.depositContractDeployedAt.get,
148+ eth1Network)
149+
150+ if eth1MonitorRes.isErr:
151+ fatal " Failed to start Eth1 monitor" ,
152+ reason = eth1MonitorRes.error,
153+ web3Url = conf.web3Url,
154+ depositContractAddress = conf.depositContractAddress.get,
155+ depositContractDeployedAt = conf.depositContractDeployedAt.get
156+ quit 1
157+ else :
158+ eth1Monitor = eth1MonitorRes.get
166159
167160 genesisState = await eth1Monitor.waitGenesis ()
168161 if bnStatus == BeaconNodeStatus .Stopping :
@@ -236,7 +229,22 @@ proc init*(T: type BeaconNode,
236229 conf.depositContractDeployedAt.isSome:
237230 # TODO (zah) if we don't have any validators attached,
238231 # we don't need a mainchain monitor
239- eth1Monitor = await startEth1Monitor (db, eth1Network, conf)
232+ let eth1MonitorRes = await Eth1Monitor .init (
233+ db,
234+ conf.runtimePreset,
235+ conf.web3Url,
236+ conf.depositContractAddress.get,
237+ conf.depositContractDeployedAt.get,
238+ eth1Network)
239+
240+ if eth1MonitorRes.isErr:
241+ error " Failed to start Eth1 monitor" ,
242+ reason = eth1MonitorRes.error,
243+ web3Url = conf.web3Url,
244+ depositContractAddress = conf.depositContractAddress.get,
245+ depositContractDeployedAt = conf.depositContractDeployedAt.get
246+ else :
247+ eth1Monitor = eth1MonitorRes.get
240248
241249 let rpcServer = if conf.rpcEnabled:
242250 RpcServer .init (conf.rpcAddress, conf.rpcPort)
@@ -823,6 +831,10 @@ proc start(node: BeaconNode) =
823831 notice " Waiting for genesis" , genesisIn = genesisTime.offset
824832
825833 waitFor node.initializeNetworking ()
834+
835+ if node.eth1Monitor != nil :
836+ node.eth1Monitor.start ()
837+
826838 node.run ()
827839
828840func formatGwei (amount: uint64 ): string =
0 commit comments