Allow the deposit contract deployment block to be specified as a number (needed for Medalla)
This commit is contained in:
parent
b45de824a4
commit
0c60e452e7
|
@ -165,14 +165,28 @@ proc init*(T: type BeaconNode,
|
|||
fatal "Deposit contract deployment block not specified"
|
||||
quit 1
|
||||
|
||||
let web3 = web3Provider(conf.web3Url)
|
||||
let deployedAtAsHash =
|
||||
if conf.depositContractDeployedAt.get.startsWith "0x":
|
||||
try: BlockHash.fromHex conf.depositContractDeployedAt.get
|
||||
except ValueError:
|
||||
fatal "Invalid hex value specified for deposit-contract-block"
|
||||
quit 1
|
||||
else:
|
||||
let blockNum = try: parseBiggestUInt conf.depositContractDeployedAt.get
|
||||
except ValueError:
|
||||
fatal "Invalid nummeric value for deposit-contract-block"
|
||||
quit 1
|
||||
await getEth1BlockHash(conf.web3Url, blockId blockNum)
|
||||
|
||||
# TODO Could move this to a separate "GenesisMonitor" process or task
|
||||
# that would do only this - see Paul's proposal for this.
|
||||
mainchainMonitor = MainchainMonitor.init(
|
||||
conf.runtimePreset,
|
||||
web3Provider(conf.web3Url),
|
||||
web3,
|
||||
conf.depositContractAddress.get,
|
||||
Eth1Data(block_hash: conf.depositContractDeployedAt.get.asEth2Digest,
|
||||
deposit_count: 0))
|
||||
Eth1Data(block_hash: deployedAtAsHash.asEth2Digest, deposit_count: 0))
|
||||
|
||||
mainchainMonitor.start()
|
||||
|
||||
genesisState = await mainchainMonitor.waitGenesis()
|
||||
|
@ -1097,7 +1111,7 @@ programMain:
|
|||
startTime = uint64(times.toUnix(times.getTime()) + config.genesisOffset)
|
||||
outGenesis = config.outputGenesis.string
|
||||
eth1Hash = if config.web3Url.len == 0: eth1BlockHash
|
||||
else: waitFor getLatestEth1BlockHash(config.web3Url)
|
||||
else: (waitFor getEth1BlockHash(config.web3Url, blockId("latest"))).asEth2Digest
|
||||
var
|
||||
initialState = initialize_beacon_state_from_eth1(
|
||||
defaultRuntimePreset, eth1Hash, startTime, deposits, {skipBlsValidation})
|
||||
|
|
|
@ -68,8 +68,8 @@ type
|
|||
name: "deposit-contract" }: Option[Eth1Address]
|
||||
|
||||
depositContractDeployedAt* {.
|
||||
desc: "The Eth1 block hash where the deposit contract has been deployed"
|
||||
name: "deposit-contract-block" }: Option[Eth1BlockHash]
|
||||
desc: "The Eth1 block number or hash where the deposit contract has been deployed"
|
||||
name: "deposit-contract-block" }: Option[string]
|
||||
|
||||
nonInteractive* {.
|
||||
desc: "Do not display interative prompts. Quit on missing configuration"
|
||||
|
|
|
@ -798,11 +798,11 @@ proc start(m: MainchainMonitor, delayBeforeStart: Duration) =
|
|||
proc start*(m: MainchainMonitor) {.inline.} =
|
||||
m.start(0.seconds)
|
||||
|
||||
proc getLatestEth1BlockHash*(url: string): Future[Eth2Digest] {.async.} =
|
||||
proc getEth1BlockHash*(url: string, blockId: RtBlockIdentifier): Future[BlockHash] {.async.} =
|
||||
let web3 = await newWeb3(url)
|
||||
try:
|
||||
let blk = await web3.provider.eth_getBlockByNumber("latest", false)
|
||||
return Eth2Digest(data: array[32, byte](blk.hash))
|
||||
let blk = await web3.provider.eth_getBlockByNumber(blockId, false)
|
||||
return blk.hash
|
||||
finally:
|
||||
await web3.close()
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ type
|
|||
bootstrapNodes*: seq[string]
|
||||
|
||||
depositContractAddress*: Eth1Address
|
||||
depositContractDeployedAt*: Eth1BlockHash
|
||||
depositContractDeployedAt*: string
|
||||
|
||||
# Please note that we are using `string` here because SSZ.decode
|
||||
# is not currently usable at compile time and we want to load the
|
||||
|
@ -110,9 +110,9 @@ proc loadEth2NetworkMetadata*(path: string): Eth2NetworkMetadata
|
|||
default(Eth1Address)
|
||||
|
||||
depositContractBlock = if fileExists(depositContractBlockPath):
|
||||
Eth1BlockHash.fromHex readFile(depositContractBlockPath).strip
|
||||
readFile(depositContractBlockPath).strip
|
||||
else:
|
||||
default(Eth1BlockHash)
|
||||
""
|
||||
|
||||
bootstrapNodes = if fileExists(bootstrapNodesPath):
|
||||
readFile(bootstrapNodesPath).splitLines()
|
||||
|
@ -145,7 +145,7 @@ const
|
|||
# TODO The values below are just placeholders for now
|
||||
bootstrapNodes: @[],
|
||||
depositContractAddress: Eth1Address.fromHex "0x1234567890123456789012345678901234567890",
|
||||
depositContractDeployedAt: Eth1BlockHash.fromHex "0x73056f16a59bf70abad5b4365438e8a7d646aa0d7f56d22c3d9e4c6000d8e176",
|
||||
depositContractDeployedAt: "0",
|
||||
genesisData: "")
|
||||
else:
|
||||
Eth2NetworkMetadata(
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 4fe1a81ce7e16413b01467a2f88058127941170e
|
||||
Subproject commit 9fb271b87697bafff9f27c73d5695d9aba648921
|
Loading…
Reference in New Issue