inserting header without set head from engine api should also validate the header
This commit is contained in:
parent
7dbc92f54c
commit
400722f1fa
|
@ -93,4 +93,6 @@ proc invalidStatus*(validHash: Hash256, msg: string): PayloadStatusV1 =
|
||||||
|
|
||||||
proc toBlockBody*(payload: ExecutionPayloadV1): BlockBody =
|
proc toBlockBody*(payload: ExecutionPayloadV1): BlockBody =
|
||||||
# TODO the transactions from the payload have to be converted here
|
# TODO the transactions from the payload have to be converted here
|
||||||
discard payload.transactions
|
result.transactions.setLen(payload.transactions.len)
|
||||||
|
for i, tx in payload.transactions:
|
||||||
|
result.transactions[i] = rlp.decode(distinctBase tx, Transaction)
|
||||||
|
|
|
@ -34,7 +34,7 @@ when not defined(release):
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
proc persistBlocksImpl(c: Chain; headers: openarray[BlockHeader];
|
proc persistBlocksImpl(c: Chain; headers: openarray[BlockHeader];
|
||||||
bodies: openarray[BlockBody]): ValidationResult
|
bodies: openarray[BlockBody], setHead: bool = true): ValidationResult
|
||||||
# wildcard exception, wrapped below in public section
|
# wildcard exception, wrapped below in public section
|
||||||
{.inline, raises: [Exception].} =
|
{.inline, raises: [Exception].} =
|
||||||
c.db.highestBlock = headers[^1].blockNumber
|
c.db.highestBlock = headers[^1].blockNumber
|
||||||
|
@ -72,8 +72,8 @@ proc persistBlocksImpl(c: Chain; headers: openarray[BlockHeader];
|
||||||
|
|
||||||
if validationResult != ValidationResult.OK:
|
if validationResult != ValidationResult.OK:
|
||||||
return validationResult
|
return validationResult
|
||||||
|
|
||||||
if c.extraValidation and c.verifyFrom <= header.blockNumber:
|
if c.extraValidation and c.verifyFrom <= header.blockNumber:
|
||||||
let isBlockAfterTtd = c.isBlockAfterTtd(header)
|
let isBlockAfterTtd = c.isBlockAfterTtd(header)
|
||||||
if c.db.config.poaEngine and not isBlockAfterTtd:
|
if c.db.config.poaEngine and not isBlockAfterTtd:
|
||||||
var parent = if 0 < i: @[headers[i-1]] else: @[]
|
var parent = if 0 < i: @[headers[i-1]] else: @[]
|
||||||
|
@ -98,7 +98,11 @@ proc persistBlocksImpl(c: Chain; headers: openarray[BlockHeader];
|
||||||
msg = res.error
|
msg = res.error
|
||||||
return ValidationResult.Error
|
return ValidationResult.Error
|
||||||
|
|
||||||
discard c.db.persistHeaderToDb(header)
|
if setHead:
|
||||||
|
discard c.db.persistHeaderToDb(header)
|
||||||
|
else:
|
||||||
|
c.db.persistHeaderToDbWithoutSetHead(header)
|
||||||
|
|
||||||
discard c.db.persistTransactions(header.blockNumber, body.transactions)
|
discard c.db.persistTransactions(header.blockNumber, body.transactions)
|
||||||
discard c.db.persistReceipts(vmState.receipts)
|
discard c.db.persistReceipts(vmState.receipts)
|
||||||
|
|
||||||
|
@ -106,9 +110,20 @@ proc persistBlocksImpl(c: Chain; headers: openarray[BlockHeader];
|
||||||
# so the rpc return consistent result
|
# so the rpc return consistent result
|
||||||
# between eth_blockNumber and eth_syncing
|
# between eth_blockNumber and eth_syncing
|
||||||
c.db.currentBlock = header.blockNumber
|
c.db.currentBlock = header.blockNumber
|
||||||
|
|
||||||
transaction.commit()
|
transaction.commit()
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# Public `ChainDB` methods
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
proc insertBlockWithoutSetHead*(c: Chain, header: BlockHeader,
|
||||||
|
body: BlockBody): ValidationResult
|
||||||
|
{.gcsafe, raises: [Defect,CatchableError].} =
|
||||||
|
|
||||||
|
safeP2PChain("persistBlocks"):
|
||||||
|
result = c.persistBlocksImpl([header], [body], setHead = false)
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Public `AbstractChainDB` overload method
|
# Public `AbstractChainDB` overload method
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
|
@ -93,7 +93,10 @@ proc setupEngineAPI*(
|
||||||
|
|
||||||
trace "Inserting block without sethead",
|
trace "Inserting block without sethead",
|
||||||
hash = blockHash.data.toHex, number = header.blockNumber
|
hash = blockHash.data.toHex, number = header.blockNumber
|
||||||
db.persistHeaderToDbWithoutSetHead(header)
|
let body = toBlockBody(payload)
|
||||||
|
let vres = sealingEngine.chain.insertBlockWithoutSetHead(header, body)
|
||||||
|
if vres != ValidationResult.OK:
|
||||||
|
return invalidStatus(db.getCurrentBlockHash(), "Failed to insert block")
|
||||||
|
|
||||||
# We've accepted a valid payload from the beacon client. Mark the local
|
# We've accepted a valid payload from the beacon client. Mark the local
|
||||||
# chain transitions to notify other subsystems (e.g. downloader) of the
|
# chain transitions to notify other subsystems (e.g. downloader) of the
|
||||||
|
|
Loading…
Reference in New Issue