only initialize JWT if useJwt is set (#3585)

This commit is contained in:
tersec 2022-04-12 22:28:01 +00:00 committed by GitHub
parent 6ab5cb1729
commit 8b74847f85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 26 additions and 21 deletions

View File

@ -404,14 +404,18 @@ proc init*(T: type BeaconNode,
fatal "--finalized-checkpoint-block cannot be specified without --finalized-checkpoint-state" fatal "--finalized-checkpoint-block cannot be specified without --finalized-checkpoint-state"
quit 1 quit 1
let jwtSecret = rng[].checkJwtSecret(string(config.dataDir), config.jwtSecret) let optJwtSecret =
if jwtSecret.isErr: if config.useJwt:
fatal "Specified a JWT secret file which couldn't be loaded", let jwtSecret = rng[].checkJwtSecret(
err = jwtSecret.error string(config.dataDir), config.jwtSecret)
quit 1 if jwtSecret.isErr:
fatal "Specified a JWT secret file which couldn't be loaded",
err = jwtSecret.error
quit 1
# The JWT secret created always exists, it just might not always be used some jwtSecret.get
let optJwtSecret = if config.useJwt: some jwtSecret.get else: none(seq[byte]) else:
none(seq[byte])
template getDepositContractSnapshot: auto = template getDepositContractSnapshot: auto =
if depositContractSnapshot.isSome: if depositContractSnapshot.isSome:
@ -1765,12 +1769,6 @@ proc doCreateTestnet*(config: BeaconNodeConf, rng: var BrHmacDrbgContext) {.rais
for i in 0 ..< launchPadDeposits.len: for i in 0 ..< launchPadDeposits.len:
deposits.add(launchPadDeposits[i] as DepositData) deposits.add(launchPadDeposits[i] as DepositData)
let jwtSecret = rng.checkJwtSecret(string(config.dataDir), config.jwtSecret)
if jwtSecret.isErr:
fatal "Specified a JWT secret file which couldn't be loaded",
err = jwtSecret.error
quit 1
let let
startTime = uint64(times.toUnix(times.getTime()) + config.genesisOffset) startTime = uint64(times.toUnix(times.getTime()) + config.genesisOffset)
outGenesis = config.outputGenesis.string outGenesis = config.outputGenesis.string
@ -1778,6 +1776,13 @@ proc doCreateTestnet*(config: BeaconNodeConf, rng: var BrHmacDrbgContext) {.rais
else: (waitFor getEth1BlockHash( else: (waitFor getEth1BlockHash(
config.web3Urls[0], blockId("latest"), config.web3Urls[0], blockId("latest"),
if config.useJwt: if config.useJwt:
let jwtSecret = rng.checkJwtSecret(
string(config.dataDir), config.jwtSecret)
if jwtSecret.isErr:
fatal "Specified a JWT secret file which couldn't be loaded",
err = jwtSecret.error
quit 1
some jwtSecret.get some jwtSecret.get
else: else:
none(seq[byte]))).asEth2Digest none(seq[byte]))).asEth2Digest
@ -1857,18 +1862,18 @@ proc doWeb3Cmd(config: BeaconNodeConf, rng: var BrHmacDrbgContext)
{.raises: [Defect, CatchableError].} = {.raises: [Defect, CatchableError].} =
case config.web3Cmd: case config.web3Cmd:
of Web3Cmd.test: of Web3Cmd.test:
let let metadata = config.loadEth2Network()
metadata = config.loadEth2Network()
jwtSecret = rng.checkJwtSecret(string(config.dataDir), config.jwtSecret)
if jwtSecret.isErr:
fatal "Specified a JWT secret file which couldn't be loaded",
err = jwtSecret.error
quit 1
waitFor testWeb3Provider(config.web3TestUrl, waitFor testWeb3Provider(config.web3TestUrl,
metadata.cfg.DEPOSIT_CONTRACT_ADDRESS, metadata.cfg.DEPOSIT_CONTRACT_ADDRESS,
if config.useJwt: if config.useJwt:
let jwtSecret = rng.checkJwtSecret(
string(config.dataDir), config.jwtSecret)
if jwtSecret.isErr:
fatal "Specified a JWT secret file which couldn't be loaded",
err = jwtSecret.error
quit 1
some jwtSecret.get some jwtSecret.get
else: else:
none(seq[byte])) none(seq[byte]))