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
|
||||
noCommand
|
||||
`import`
|
||||
`import-rlp`
|
||||
|
||||
RpcFlag* {.pure.} = enum
|
||||
## RPC flags
|
||||
|
@ -485,11 +486,6 @@ type
|
|||
name: "jwt-secret" .}: Option[InputFile]
|
||||
|
||||
of `import`:
|
||||
blocksFile* {.
|
||||
argument
|
||||
desc: "One or more RLP encoded block(s) files"
|
||||
name: "blocks-file" }: seq[InputFile]
|
||||
|
||||
maxBlocks* {.
|
||||
desc: "Maximum number of blocks to import"
|
||||
defaultValue: uint64.high()
|
||||
|
@ -540,6 +536,12 @@ type
|
|||
defaultValue: false
|
||||
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
|
||||
{.gcsafe, raises: [ValueError].} =
|
||||
parseBiggestUInt(p).T
|
||||
|
|
|
@ -11,9 +11,11 @@
|
|||
|
||||
import
|
||||
chronicles,
|
||||
eth/rlp, stew/io2,
|
||||
eth/rlp,
|
||||
stew/io2,
|
||||
./chain,
|
||||
../config
|
||||
../config,
|
||||
../utils/utils
|
||||
|
||||
proc importRlpBlocks*(blocksRlp: openArray[byte],
|
||||
chain: ForkedChainRef,
|
||||
|
@ -23,10 +25,9 @@ proc importRlpBlocks*(blocksRlp: openArray[byte],
|
|||
# the encoded rlp can contains one or more blocks
|
||||
rlp = rlpFromBytes(blocksRlp)
|
||||
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:
|
||||
blk = try:
|
||||
rlp.read(Block)
|
||||
|
@ -34,7 +35,36 @@ proc importRlpBlocks*(blocksRlp: openArray[byte],
|
|||
# terminate if there was a decoding error
|
||||
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:
|
||||
? chain.forkChoice(chain.latestHash, chain.latestHash)
|
||||
|
|
|
@ -23,6 +23,7 @@ import
|
|||
./constants,
|
||||
./nimbus_desc,
|
||||
./nimbus_import,
|
||||
./core/block_import,
|
||||
./core/eip4844,
|
||||
./db/core_db/persistent,
|
||||
./db/storage_types,
|
||||
|
@ -235,6 +236,8 @@ proc run(nimbus: NimbusNode, conf: NimbusConf) =
|
|||
case conf.cmd
|
||||
of NimbusCmd.`import`:
|
||||
importBlocks(conf, com)
|
||||
of NimbusCmd.`import-rlp`:
|
||||
importRlpBlocks(conf, com)
|
||||
else:
|
||||
basicServices(nimbus, conf, com)
|
||||
manageAccounts(nimbus, conf)
|
||||
|
|
|
@ -19,7 +19,7 @@ import
|
|||
beacon_chain/networking/network_metadata,
|
||||
./config,
|
||||
./common/common,
|
||||
./core/[block_import, chain],
|
||||
./core/chain,
|
||||
./db/era1_db,
|
||||
./utils/era_helpers
|
||||
|
||||
|
@ -341,5 +341,3 @@ proc importBlocks*(conf: NimbusConf, com: CommonRef) =
|
|||
|
||||
if blocks.len > 0:
|
||||
process()
|
||||
|
||||
importRlpBlocks(conf, com)
|
||||
|
|
|
@ -46,12 +46,12 @@ proc configurationMain*() =
|
|||
let ff = makeConfig(@["--chaindb:ariPrune"])
|
||||
check ff.chainDbMode == ChainDbMode.AriPrune
|
||||
|
||||
test "import":
|
||||
test "import-rlp":
|
||||
let aa = makeTestConfig()
|
||||
check aa.cmd == NimbusCmd.noCommand
|
||||
|
||||
let bb = makeConfig(@["import", genesisFile])
|
||||
check bb.cmd == NimbusCmd.`import`
|
||||
let bb = makeConfig(@["import-rlp", genesisFile])
|
||||
check bb.cmd == NimbusCmd.`import-rlp`
|
||||
check bb.blocksFile[0].string == genesisFile
|
||||
|
||||
test "custom-network loading config file with no genesis data":
|
||||
|
|
Loading…
Reference in New Issue