mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-01-27 06:47:13 +00:00
Wire in blob validation (#4864)
* Wire in blob validation * Remove unused "is_data_available" * Log blobs when blob validation fails
This commit is contained in:
parent
74511f61d1
commit
01549f6aa4
@ -14,6 +14,7 @@ import
|
||||
../sszdump
|
||||
|
||||
from std/deques import Deque, addLast, contains, initDeque, items, len, shrink
|
||||
from std/sequtils import mapIt
|
||||
from ../consensus_object_pools/consensus_manager import
|
||||
ConsensusManager, checkNextProposer, optimisticExecutionPayloadHash,
|
||||
runProposalForkchoiceUpdated, shouldSyncOptimistically, updateHead,
|
||||
@ -33,6 +34,7 @@ from ../validators/validator_monitor import
|
||||
MsgSource, ValidatorMonitor, registerAttestationInBlock, registerBeaconBlock,
|
||||
registerSyncAggregateInBlock
|
||||
from ../beacon_chain_db import putBlobSidecar
|
||||
from ../spec/state_transition_block import validate_blobs
|
||||
|
||||
export sszdump, signatures_batch
|
||||
|
||||
@ -196,8 +198,20 @@ proc storeBackfillBlock(
|
||||
# writing the block in case of blob error.
|
||||
let blobsOk =
|
||||
when typeof(signedBlock).toFork() >= ConsensusFork.Deneb:
|
||||
blobs.len > 0 or true
|
||||
# TODO: validate blobs
|
||||
let kzgCommits = signedBlock.message.body.blob_kzg_commitments.asSeq
|
||||
if blobs.len > 0 or kzgCommits.len > 0:
|
||||
let r = validate_blobs(kzgCommits, blobs.mapIt(it.blob),
|
||||
blobs.mapIt(it.kzg_proof))
|
||||
if r.isErr():
|
||||
debug "backfill blob validation failed",
|
||||
blockRoot = shortLog(signedBlock.root),
|
||||
blobs = shortLog(blobs),
|
||||
blck = shortLog(signedBlock.message),
|
||||
signature = shortLog(signedBlock.signature),
|
||||
msg = r.error()
|
||||
r.isOk()
|
||||
else:
|
||||
true
|
||||
else:
|
||||
true
|
||||
if not blobsOk:
|
||||
@ -222,7 +236,8 @@ proc storeBackfillBlock(
|
||||
return res
|
||||
|
||||
# Only store blobs after successfully establishing block viability.
|
||||
# TODO: store blobs in db
|
||||
for b in blobs:
|
||||
self.consensusManager.dag.db.putBlobSidecar(b[])
|
||||
|
||||
res
|
||||
|
||||
@ -450,9 +465,18 @@ proc storeBlock*(
|
||||
# Establish blob viability before calling addHeadBlock to avoid
|
||||
# writing the block in case of blob error.
|
||||
when typeof(signedBlock).toFork() >= ConsensusFork.Deneb:
|
||||
if blobs.len > 0:
|
||||
discard
|
||||
# TODO: validate blobs
|
||||
let kzgCommits = signedBlock.message.body.blob_kzg_commitments.asSeq
|
||||
if blobs.len > 0 or kzgCommits.len > 0:
|
||||
let r = validate_blobs(kzgCommits, blobs.mapIt(it.blob),
|
||||
blobs.mapIt(it.kzg_proof))
|
||||
if r.isErr():
|
||||
debug "blob validation failed",
|
||||
blockRoot = shortLog(signedBlock.root),
|
||||
blobs = shortLog(blobs),
|
||||
blck = shortLog(signedBlock.message),
|
||||
signature = shortLog(signedBlock.signature),
|
||||
msg = r.error()
|
||||
return err((VerifierError.Invalid, ProcessingStatus.completed))
|
||||
|
||||
type Trusted = typeof signedBlock.asTrusted()
|
||||
let blck = dag.addHeadBlock(self.verifier, signedBlock, payloadValid) do (
|
||||
|
@ -544,6 +544,9 @@ func shortLog*(v: BlobSidecar): auto =
|
||||
bloblen: v.blob.len(),
|
||||
)
|
||||
|
||||
func shortLog*(v: seq[ref BlobSidecar]): auto =
|
||||
"[" & v.mapIt(shortLog(it[])).join(", ") & "]"
|
||||
|
||||
func shortLog*(v: SignedBlobSidecar): auto =
|
||||
(
|
||||
blob: shortLog(v.message),
|
||||
|
@ -772,15 +772,6 @@ proc validate_blobs*(expected_kzg_commitments: seq[KzgCommitment],
|
||||
|
||||
ok()
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/deneb/fork-choice.md#is_data_available
|
||||
func is_data_available(
|
||||
slot: Slot, beacon_block_root: Eth2Digest,
|
||||
blob_kzg_commitments: seq[deneb.KZGCommitment]): bool =
|
||||
discard $denebImplementationMissing & ": state_transition_block.nim:is_data_available"
|
||||
|
||||
true
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/phase0/beacon-chain.md#block-processing
|
||||
# TODO workaround for https://github.com/nim-lang/Nim/issues/18095
|
||||
# copy of datatypes/phase0.nim
|
||||
type SomePhase0Block =
|
||||
@ -926,9 +917,4 @@ proc process_block*(
|
||||
|
||||
? process_blob_kzg_commitments(state, blck.body) # [New in Deneb]
|
||||
|
||||
# New in EIP-4844
|
||||
if not is_data_available(
|
||||
blck.slot, hash_tree_root(blck), blck.body.blob_kzg_commitments.asSeq):
|
||||
return err("not is_data_available")
|
||||
|
||||
ok()
|
||||
|
Loading…
x
Reference in New Issue
Block a user