mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-03-01 04:10:45 +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
|
var ctx: sha256
|
||||||
ctx.init()
|
ctx.init()
|
||||||
ctx.update(networkId)
|
ctx.update(networkId)
|
||||||
ctx.update(conf)
|
ctx.update(conf.chainId)
|
||||||
if genesis.isNil.not:
|
if genesis.isNil.not:
|
||||||
ctx.update(genesis)
|
ctx.update(genesis)
|
||||||
ctx.finish(result.data)
|
ctx.finish(result.data)
|
||||||
|
@ -417,6 +417,11 @@ type
|
|||||||
desc: "Print RDB statistics at exit"
|
desc: "Print RDB statistics at exit"
|
||||||
name: "debug-rdb-print-stats".}: bool
|
name: "debug-rdb-print-stats".}: bool
|
||||||
|
|
||||||
|
rewriteDatadirId* {.
|
||||||
|
hidden
|
||||||
|
desc: "Rewrite selected network config hash to database"
|
||||||
|
name: "debug-rewrite-datadir-id".}: bool
|
||||||
|
|
||||||
case cmd* {.
|
case cmd* {.
|
||||||
command
|
command
|
||||||
defaultValue: NimbusCmd.noCommand }: NimbusCmd
|
defaultValue: NimbusCmd.noCommand }: NimbusCmd
|
||||||
|
@ -156,15 +156,22 @@ proc setupMetrics(nimbus: NimbusNode, conf: NimbusConf) =
|
|||||||
waitFor nimbus.metricsServer.start()
|
waitFor nimbus.metricsServer.start()
|
||||||
|
|
||||||
proc preventLoadingDataDirForTheWrongNetwork(db: CoreDbRef; conf: NimbusConf) =
|
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
|
let
|
||||||
kvt = db.ctx.getKvt()
|
kvt = db.ctx.getKvt()
|
||||||
calculatedId = calcHash(conf.networkId, conf.networkParams)
|
calculatedId = calcHash(conf.networkId, conf.networkParams)
|
||||||
dataDirIdBytes = kvt.get(dataDirIdKey().toOpenArray).valueOr:
|
dataDirIdBytes = kvt.get(dataDirIdKey().toOpenArray).valueOr:
|
||||||
# an empty database
|
# an empty database
|
||||||
info "Writing data dir ID", ID=calculatedId
|
writeDataDirId(kvt, calculatedId)
|
||||||
kvt.put(dataDirIdKey().toOpenArray, calculatedId.data).isOkOr:
|
return
|
||||||
fatal "Cannot write data dir ID", ID=calculatedId
|
|
||||||
quit(QuitFailure)
|
if conf.rewriteDatadirId:
|
||||||
|
writeDataDirId(kvt, calculatedId)
|
||||||
return
|
return
|
||||||
|
|
||||||
if calculatedId.data != dataDirIdBytes:
|
if calculatedId.data != dataDirIdBytes:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user