diff --git a/nimbus/common/chain_config_hash.nim b/nimbus/common/chain_config_hash.nim index c11df4ff4..e78da647d 100644 --- a/nimbus/common/chain_config_hash.nim +++ b/nimbus/common/chain_config_hash.nim @@ -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) diff --git a/nimbus/config.nim b/nimbus/config.nim index a8548574a..e64f1bbee 100644 --- a/nimbus/config.nim +++ b/nimbus/config.nim @@ -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 diff --git a/nimbus/nimbus_execution_client.nim b/nimbus/nimbus_execution_client.nim index 5a9ab9443..6010037db 100644 --- a/nimbus/nimbus_execution_client.nim +++ b/nimbus/nimbus_execution_client.nim @@ -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,