Move rlp block import into it's own subcommand (#2904)
* Move rlp block import into it's own subcommand * Fix test_configuration
This commit is contained in:
parent
56caa5f62f
commit
1101895f92
|
@ -104,6 +104,7 @@ type
|
||||||
NimbusCmd* {.pure.} = enum
|
NimbusCmd* {.pure.} = enum
|
||||||
noCommand
|
noCommand
|
||||||
`import`
|
`import`
|
||||||
|
`import-rlp`
|
||||||
|
|
||||||
RpcFlag* {.pure.} = enum
|
RpcFlag* {.pure.} = enum
|
||||||
## RPC flags
|
## RPC flags
|
||||||
|
@ -485,11 +486,6 @@ type
|
||||||
name: "jwt-secret" .}: Option[InputFile]
|
name: "jwt-secret" .}: Option[InputFile]
|
||||||
|
|
||||||
of `import`:
|
of `import`:
|
||||||
blocksFile* {.
|
|
||||||
argument
|
|
||||||
desc: "One or more RLP encoded block(s) files"
|
|
||||||
name: "blocks-file" }: seq[InputFile]
|
|
||||||
|
|
||||||
maxBlocks* {.
|
maxBlocks* {.
|
||||||
desc: "Maximum number of blocks to import"
|
desc: "Maximum number of blocks to import"
|
||||||
defaultValue: uint64.high()
|
defaultValue: uint64.high()
|
||||||
|
@ -540,6 +536,12 @@ type
|
||||||
defaultValue: false
|
defaultValue: false
|
||||||
name: "debug-store-slot-hashes".}: bool
|
name: "debug-store-slot-hashes".}: bool
|
||||||
|
|
||||||
|
of `import-rlp`:
|
||||||
|
blocksFile* {.
|
||||||
|
argument
|
||||||
|
desc: "One or more RLP encoded block(s) files"
|
||||||
|
name: "blocks-file" }: seq[InputFile]
|
||||||
|
|
||||||
func parseCmdArg(T: type NetworkId, p: string): T
|
func parseCmdArg(T: type NetworkId, p: string): T
|
||||||
{.gcsafe, raises: [ValueError].} =
|
{.gcsafe, raises: [ValueError].} =
|
||||||
parseBiggestUInt(p).T
|
parseBiggestUInt(p).T
|
||||||
|
|
|
@ -11,9 +11,11 @@
|
||||||
|
|
||||||
import
|
import
|
||||||
chronicles,
|
chronicles,
|
||||||
eth/rlp, stew/io2,
|
eth/rlp,
|
||||||
|
stew/io2,
|
||||||
./chain,
|
./chain,
|
||||||
../config
|
../config,
|
||||||
|
../utils/utils
|
||||||
|
|
||||||
proc importRlpBlocks*(blocksRlp: openArray[byte],
|
proc importRlpBlocks*(blocksRlp: openArray[byte],
|
||||||
chain: ForkedChainRef,
|
chain: ForkedChainRef,
|
||||||
|
@ -23,10 +25,9 @@ proc importRlpBlocks*(blocksRlp: openArray[byte],
|
||||||
# the encoded rlp can contains one or more blocks
|
# the encoded rlp can contains one or more blocks
|
||||||
rlp = rlpFromBytes(blocksRlp)
|
rlp = rlpFromBytes(blocksRlp)
|
||||||
blk: Block
|
blk: Block
|
||||||
|
printBanner = false
|
||||||
|
firstSkip = Opt.none(uint64)
|
||||||
|
|
||||||
# even though the new imported blocks have block number
|
|
||||||
# smaller than head, we keep importing it.
|
|
||||||
# it maybe a side chain.
|
|
||||||
while rlp.hasData:
|
while rlp.hasData:
|
||||||
blk = try:
|
blk = try:
|
||||||
rlp.read(Block)
|
rlp.read(Block)
|
||||||
|
@ -34,7 +35,36 @@ proc importRlpBlocks*(blocksRlp: openArray[byte],
|
||||||
# terminate if there was a decoding error
|
# terminate if there was a decoding error
|
||||||
return err($e.name & ": " & e.msg)
|
return err($e.name & ": " & e.msg)
|
||||||
|
|
||||||
? chain.importBlock(blk)
|
if blk.header.number <= chain.baseNumber:
|
||||||
|
if firstSkip.isNone:
|
||||||
|
firstSkip = Opt.some(blk.header.number)
|
||||||
|
continue
|
||||||
|
|
||||||
|
if firstSkip.isSome:
|
||||||
|
if firstSkip.get == blk.header.number - 1:
|
||||||
|
info "Block number smaller than base",
|
||||||
|
skip=firstSkip.get
|
||||||
|
else:
|
||||||
|
info "Block number smaller than base",
|
||||||
|
startSkip=firstSkip.get,
|
||||||
|
skipTo=blk.header.number-1
|
||||||
|
firstSkip.reset()
|
||||||
|
|
||||||
|
if not printBanner:
|
||||||
|
info "Start importing block",
|
||||||
|
hash=blk.header.blockHash.short,
|
||||||
|
number=blk.header.number
|
||||||
|
printBanner = true
|
||||||
|
|
||||||
|
let res = chain.importBlock(blk)
|
||||||
|
if res.isErr:
|
||||||
|
error "Error occured when importing block",
|
||||||
|
hash=blk.header.blockHash.short,
|
||||||
|
number=blk.header.number,
|
||||||
|
msg=res.error
|
||||||
|
if finalize:
|
||||||
|
? chain.forkChoice(chain.latestHash, chain.latestHash)
|
||||||
|
return res
|
||||||
|
|
||||||
if finalize:
|
if finalize:
|
||||||
? chain.forkChoice(chain.latestHash, chain.latestHash)
|
? chain.forkChoice(chain.latestHash, chain.latestHash)
|
||||||
|
|
|
@ -23,6 +23,7 @@ import
|
||||||
./constants,
|
./constants,
|
||||||
./nimbus_desc,
|
./nimbus_desc,
|
||||||
./nimbus_import,
|
./nimbus_import,
|
||||||
|
./core/block_import,
|
||||||
./core/eip4844,
|
./core/eip4844,
|
||||||
./db/core_db/persistent,
|
./db/core_db/persistent,
|
||||||
./db/storage_types,
|
./db/storage_types,
|
||||||
|
@ -235,6 +236,8 @@ proc run(nimbus: NimbusNode, conf: NimbusConf) =
|
||||||
case conf.cmd
|
case conf.cmd
|
||||||
of NimbusCmd.`import`:
|
of NimbusCmd.`import`:
|
||||||
importBlocks(conf, com)
|
importBlocks(conf, com)
|
||||||
|
of NimbusCmd.`import-rlp`:
|
||||||
|
importRlpBlocks(conf, com)
|
||||||
else:
|
else:
|
||||||
basicServices(nimbus, conf, com)
|
basicServices(nimbus, conf, com)
|
||||||
manageAccounts(nimbus, conf)
|
manageAccounts(nimbus, conf)
|
||||||
|
|
|
@ -19,7 +19,7 @@ import
|
||||||
beacon_chain/networking/network_metadata,
|
beacon_chain/networking/network_metadata,
|
||||||
./config,
|
./config,
|
||||||
./common/common,
|
./common/common,
|
||||||
./core/[block_import, chain],
|
./core/chain,
|
||||||
./db/era1_db,
|
./db/era1_db,
|
||||||
./utils/era_helpers
|
./utils/era_helpers
|
||||||
|
|
||||||
|
@ -341,5 +341,3 @@ proc importBlocks*(conf: NimbusConf, com: CommonRef) =
|
||||||
|
|
||||||
if blocks.len > 0:
|
if blocks.len > 0:
|
||||||
process()
|
process()
|
||||||
|
|
||||||
importRlpBlocks(conf, com)
|
|
||||||
|
|
|
@ -46,12 +46,12 @@ proc configurationMain*() =
|
||||||
let ff = makeConfig(@["--chaindb:ariPrune"])
|
let ff = makeConfig(@["--chaindb:ariPrune"])
|
||||||
check ff.chainDbMode == ChainDbMode.AriPrune
|
check ff.chainDbMode == ChainDbMode.AriPrune
|
||||||
|
|
||||||
test "import":
|
test "import-rlp":
|
||||||
let aa = makeTestConfig()
|
let aa = makeTestConfig()
|
||||||
check aa.cmd == NimbusCmd.noCommand
|
check aa.cmd == NimbusCmd.noCommand
|
||||||
|
|
||||||
let bb = makeConfig(@["import", genesisFile])
|
let bb = makeConfig(@["import-rlp", genesisFile])
|
||||||
check bb.cmd == NimbusCmd.`import`
|
check bb.cmd == NimbusCmd.`import-rlp`
|
||||||
check bb.blocksFile[0].string == genesisFile
|
check bb.blocksFile[0].string == genesisFile
|
||||||
|
|
||||||
test "custom-network loading config file with no genesis data":
|
test "custom-network loading config file with no genesis data":
|
||||||
|
|
Loading…
Reference in New Issue