parent
7b2b59a976
commit
ac2f3a4358
|
@ -99,11 +99,10 @@ proc headerFromTag(api: ServerAPIRef, blockTag: Opt[BlockTag]): Result[Header, s
|
|||
|
||||
proc ledgerFromTag(api: ServerAPIRef, blockTag: BlockTag): Result[LedgerRef, string] =
|
||||
let header = ?api.headerFromTag(blockTag)
|
||||
if api.chain.stateReady(header):
|
||||
ok(LedgerRef.init(api.com.db))
|
||||
else:
|
||||
# TODO: Replay state?
|
||||
err("Block state not ready")
|
||||
if not api.chain.stateReady(header):
|
||||
api.chain.replaySegment(header.blockHash)
|
||||
|
||||
ok(LedgerRef.init(api.com.db))
|
||||
|
||||
proc blockFromTag(api: ServerAPIRef, blockTag: BlockTag): Result[Block, string] =
|
||||
if blockTag.kind == bidAlias:
|
||||
|
|
|
@ -420,5 +420,21 @@ proc forkedChainMain*() =
|
|||
check chain.headerByNumber(5).expect("OK").number == 5
|
||||
check chain.headerByNumber(5).expect("OK").blockHash == blk5.blockHash
|
||||
|
||||
test "Import after Replay Segment":
|
||||
let com = env.newCom()
|
||||
var chain = newForkedChain(com, com.genesisHeader, baseDistance = 3)
|
||||
|
||||
check chain.importBlock(blk1).isOk
|
||||
check chain.importBlock(blk2).isOk
|
||||
check chain.importBlock(blk3).isOk
|
||||
check chain.importBlock(blk4).isOk
|
||||
check chain.importBlock(blk5).isOk
|
||||
|
||||
chain.replaySegment(blk2.header.blockHash)
|
||||
chain.replaySegment(blk5.header.blockHash)
|
||||
|
||||
check chain.importBlock(blk6).isOk
|
||||
check chain.importBlock(blk7).isOk
|
||||
|
||||
when isMainModule:
|
||||
forkedChainMain()
|
||||
|
|
Loading…
Reference in New Issue