mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-02-28 20:00:43 +00:00
Only hashing immutable part of network configuration for dataDir ID (#2955)
* Only hashing immutable part of network configuration for dataDir ID * Add debug- prefix to rewrite-datadir-id
This commit is contained in:
parent
ac053bf4c8
commit
aa85d6a61c
@ -79,7 +79,7 @@ func calcHash*(networkId: NetworkId, conf: ChainConfig, genesis: Genesis): Hash3
|
||||
var ctx: sha256
|
||||
ctx.init()
|
||||
ctx.update(networkId)
|
||||
ctx.update(conf)
|
||||
ctx.update(conf.chainId)
|
||||
if genesis.isNil.not:
|
||||
ctx.update(genesis)
|
||||
ctx.finish(result.data)
|
||||
|
@ -417,6 +417,11 @@ type
|
||||
desc: "Print RDB statistics at exit"
|
||||
name: "debug-rdb-print-stats".}: bool
|
||||
|
||||
rewriteDatadirId* {.
|
||||
hidden
|
||||
desc: "Rewrite selected network config hash to database"
|
||||
name: "debug-rewrite-datadir-id".}: bool
|
||||
|
||||
case cmd* {.
|
||||
command
|
||||
defaultValue: NimbusCmd.noCommand }: NimbusCmd
|
||||
|
@ -156,17 +156,24 @@ proc setupMetrics(nimbus: NimbusNode, conf: NimbusConf) =
|
||||
waitFor nimbus.metricsServer.start()
|
||||
|
||||
proc preventLoadingDataDirForTheWrongNetwork(db: CoreDbRef; conf: NimbusConf) =
|
||||
proc writeDataDirId(kvt: CoreDbKvtRef, calculatedId: Hash32) =
|
||||
info "Writing data dir ID", ID=calculatedId
|
||||
kvt.put(dataDirIdKey().toOpenArray, calculatedId.data).isOkOr:
|
||||
fatal "Cannot write data dir ID", ID=calculatedId
|
||||
quit(QuitFailure)
|
||||
|
||||
let
|
||||
kvt = db.ctx.getKvt()
|
||||
calculatedId = calcHash(conf.networkId, conf.networkParams)
|
||||
dataDirIdBytes = kvt.get(dataDirIdKey().toOpenArray).valueOr:
|
||||
# an empty database
|
||||
info "Writing data dir ID", ID=calculatedId
|
||||
kvt.put(dataDirIdKey().toOpenArray, calculatedId.data).isOkOr:
|
||||
fatal "Cannot write data dir ID", ID=calculatedId
|
||||
quit(QuitFailure)
|
||||
writeDataDirId(kvt, calculatedId)
|
||||
return
|
||||
|
||||
if conf.rewriteDatadirId:
|
||||
writeDataDirId(kvt, calculatedId)
|
||||
return
|
||||
|
||||
if calculatedId.data != dataDirIdBytes:
|
||||
fatal "Data dir already initialized with other network configuration",
|
||||
get=dataDirIdBytes.toHex,
|
||||
|
Loading…
x
Reference in New Issue
Block a user