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] =
|
proc ledgerFromTag(api: ServerAPIRef, blockTag: BlockTag): Result[LedgerRef, string] =
|
||||||
let header = ?api.headerFromTag(blockTag)
|
let header = ?api.headerFromTag(blockTag)
|
||||||
if api.chain.stateReady(header):
|
if not api.chain.stateReady(header):
|
||||||
ok(LedgerRef.init(api.com.db))
|
api.chain.replaySegment(header.blockHash)
|
||||||
else:
|
|
||||||
# TODO: Replay state?
|
ok(LedgerRef.init(api.com.db))
|
||||||
err("Block state not ready")
|
|
||||||
|
|
||||||
proc blockFromTag(api: ServerAPIRef, blockTag: BlockTag): Result[Block, string] =
|
proc blockFromTag(api: ServerAPIRef, blockTag: BlockTag): Result[Block, string] =
|
||||||
if blockTag.kind == bidAlias:
|
if blockTag.kind == bidAlias:
|
||||||
|
|
|
@ -420,5 +420,21 @@ proc forkedChainMain*() =
|
||||||
check chain.headerByNumber(5).expect("OK").number == 5
|
check chain.headerByNumber(5).expect("OK").number == 5
|
||||||
check chain.headerByNumber(5).expect("OK").blockHash == blk5.blockHash
|
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:
|
when isMainModule:
|
||||||
forkedChainMain()
|
forkedChainMain()
|
||||||
|
|
Loading…
Reference in New Issue