implement debug_setHead
This commit is contained in:
parent
74d728f962
commit
281b7dffac
|
@ -180,6 +180,13 @@ proc setAsCanonicalChainHead(self: BaseChainDB; headerHash: Hash256): seq[BlockH
|
|||
|
||||
return newCanonicalHeaders
|
||||
|
||||
proc setHead*(self: BaseChainDB, header: BlockHeader, writeHeader = false) =
|
||||
var headerHash = rlpHash(header)
|
||||
if writeHeader:
|
||||
self.db.put(genericHashKey(headerHash).toOpenArray, rlp.encode(header))
|
||||
self.addBlockNumberToHashLookup(header)
|
||||
self.db.put(canonicalHeadHashKey().toOpenArray, rlp.encode(headerHash))
|
||||
|
||||
proc headerExists*(self: BaseChainDB; blockHash: Hash256): bool =
|
||||
## Returns True if the header with the given block hash is in our DB.
|
||||
self.db.contains(genericHashKey(blockHash).toOpenArray)
|
||||
|
|
|
@ -113,3 +113,11 @@ proc setupDebugRpc*(chainDB: BaseChainDB, rpcsrv: RpcServer) =
|
|||
flags = traceOptionsToFlags(options)
|
||||
|
||||
traceBlock(chainDB, header, body, flags)
|
||||
|
||||
rpcsrv.rpc("debug_setHead") do(quantityTag: string):
|
||||
## Sets the current head of the local chain by block number.
|
||||
## Note, this is a destructive action and may severely damage your chain.
|
||||
## Use with extreme caution.
|
||||
let
|
||||
header = chainDB.headerFromTag(quantityTag)
|
||||
chainDB.setHead(header)
|
||||
|
|
|
@ -4,12 +4,6 @@ import
|
|||
../nimbus/[tracer, vm_types, config],
|
||||
../nimbus/p2p/chain
|
||||
|
||||
proc putCanonicalHead(chainDB: BaseChainDB, header: BlockHeader) =
|
||||
var headerHash = rlpHash(header)
|
||||
chainDB.db.put(genericHashKey(headerHash).toOpenArray, rlp.encode(header))
|
||||
chainDB.addBlockNumberToHashLookup(header)
|
||||
chainDB.db.put(canonicalHeadHashKey().toOpenArray, rlp.encode(headerHash))
|
||||
|
||||
proc dumpTest(chainDB: BaseChainDB, blockNumber: int) =
|
||||
let
|
||||
blockNumber = blockNumber.u256
|
||||
|
@ -30,7 +24,7 @@ proc dumpTest(chainDB: BaseChainDB, blockNumber: int) =
|
|||
headers = @[header]
|
||||
bodies = @[blockBody]
|
||||
|
||||
captureChainDB.putCanonicalHead(parent)
|
||||
captureChainDB.setHead(parent, true)
|
||||
discard chain.persistBlocks(headers, bodies)
|
||||
|
||||
var metaData = %{
|
||||
|
|
|
@ -16,12 +16,6 @@ proc testFixture(node: JsonNode, testStatusIMPL: var TestStatus)
|
|||
suite "persist block json tests":
|
||||
jsonTest("PersistBlockTests", testFixture)
|
||||
|
||||
proc putCanonicalHead(chainDB: BaseChainDB, header: BlockHeader) =
|
||||
var headerHash = rlpHash(header)
|
||||
chainDB.db.put(genericHashKey(headerHash).toOpenArray, rlp.encode(header))
|
||||
chainDB.addBlockNumberToHashLookup(header)
|
||||
chainDB.db.put(canonicalHeadHashKey().toOpenArray, rlp.encode(headerHash))
|
||||
|
||||
# use tracerTestGen.nim to generate additional test data
|
||||
proc testFixture(node: JsonNode, testStatusIMPL: var TestStatus) =
|
||||
var
|
||||
|
@ -45,6 +39,6 @@ proc testFixture(node: JsonNode, testStatusIMPL: var TestStatus) =
|
|||
headers = @[header]
|
||||
bodies = @[blockBody]
|
||||
|
||||
chainDB.putCanonicalHead(parent)
|
||||
chainDB.setHead(parent, true)
|
||||
let validationResult = chain.persistBlocks(headers, bodies)
|
||||
check validationResult == ValidationResult.OK
|
||||
|
|
Loading…
Reference in New Issue