make message_router.routeSignedBeaconBlock blob-aware (#4537)

* make message_router.outeSignedBeaconBlock blob-aware

* Update beacon_chain/spec/forks.nim

* Update beacon_chain/spec/forks.nim
This commit is contained in:
henridf 2023-01-21 07:34:04 +01:00 committed by GitHub
parent a57cec56cb
commit 96dfe18a3d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 20 deletions

View File

@ -2653,23 +2653,13 @@ proc broadcastBeaconBlock*(
let topic = getBeaconBlocksTopic(node.forkDigests.capella) let topic = getBeaconBlocksTopic(node.forkDigests.capella)
node.broadcast(topic, blck) node.broadcast(topic, blck)
proc broadcastBeaconBlockAndBlobsSidecar*(
node: Eth2Node, blck: eip4844.SignedBeaconBlockAndBlobsSidecar): Future[SendResult] =
let topic = getBeaconBlockAndBlobsSidecarTopic(node.forkDigests.eip4844)
node.broadcast(topic, blck)
from ../spec/datatypes/eip4844 import SignedBeaconBlock from ../spec/datatypes/eip4844 import SignedBeaconBlock
proc broadcastBeaconBlock*(
node: Eth2Node, blck: eip4844.SignedBeaconBlock): Future[SendResult] =
debugRaiseAssert $eip4844ImplementationMissing & ": eth2_network.nim:broadcastBeaconBlock EIP4844 uses different approach (1)"
proc broadcastBeaconBlock*(
node: Eth2Node, forked: ForkedSignedBeaconBlock): Future[SendResult] =
withBlck(forked):
when stateFork == BeaconStateFork.EIP4844:
debugRaiseAssert $eip4844ImplementationMissing & ": eth2_network.nim:broadcastBeaconBlock EIP4844 uses different approach (2)"
let f = newFuture[SendResult]()
f.fail(new CatchableError)
f
else:
node.broadcastBeaconBlock(blck)
proc broadcastSyncCommitteeMessage*( proc broadcastSyncCommitteeMessage*(
node: Eth2Node, msg: SyncCommitteeMessage, node: Eth2Node, msg: SyncCommitteeMessage,
subcommitteeIdx: SyncSubcommitteeIndex): Future[SendResult] = subcommitteeIdx: SyncSubcommitteeIndex): Future[SendResult] =

View File

@ -9,6 +9,7 @@
import import
stew/assign2, stew/assign2,
stew/results,
chronicles, chronicles,
../extras, ../extras,
"."/[ "."/[
@ -272,6 +273,14 @@ template toSignedBeaconBlock*(b: ForkySignedBeaconBlockMaybeBlobs): ForkySignedB
else: else:
b b
func optBlobs*(b: ForkySignedBeaconBlockMaybeBlobs):
Opt[eip4844.BlobsSidecar] =
when b is phase0.SignedBeaconBlock or b is altair.SignedBeaconBlock or
b is bellatrix.SignedBeaconBlock or b is capella.SignedBeaconBlock:
Opt.none(eip4844.BlobsSidecar)
elif b is eip4844.SignedBeaconBlockAndBlobsSidecar:
Opt.some(b.blobs_sidecar)
template toFork*[T: phase0.BeaconState | phase0.HashedBeaconState]( template toFork*[T: phase0.BeaconState | phase0.HashedBeaconState](
t: type T): BeaconStateFork = t: type T): BeaconStateFork =
BeaconStateFork.Phase0 BeaconStateFork.Phase0

View File

@ -107,7 +107,12 @@ proc routeSignedBeaconBlock*(
# The block passed basic gossip validation - we can "safely" broadcast it # The block passed basic gossip validation - we can "safely" broadcast it
# now. In fact, per the spec, we should broadcast it even if it later fails # now. In fact, per the spec, we should broadcast it even if it later fails
# to apply to our state. # to apply to our state.
res = await router[].network.broadcastBeaconBlock(blck)
let res =
when blckAndBlobs is eip4844.SignedBeaconBlockAndBlobsSidecar:
await router[].network.broadcastBeaconBlockAndBlobsSidecar(blckAndBlobs)
else:
await router[].network.broadcastBeaconBlock(blck)
if res.isOk(): if res.isOk():
beacon_blocks_sent.inc() beacon_blocks_sent.inc()
@ -121,9 +126,8 @@ proc routeSignedBeaconBlock*(
blockRoot = shortLog(blck.root), blck = shortLog(blck.message), blockRoot = shortLog(blck.root), blck = shortLog(blck.message),
signature = shortLog(blck.signature), error = res.error() signature = shortLog(blck.signature), error = res.error()
let let newBlockRef = await router[].blockProcessor.storeBlock(
newBlockRef = await router[].blockProcessor.storeBlock( MsgSource.api, sendTime, blck, optBlobs(blckAndBlobs))
MsgSource.api, sendTime, blck, Opt.none(eip4844.BlobsSidecar))
# The boolean we return tells the caller whether the block was integrated # The boolean we return tells the caller whether the block was integrated
# into the chain # into the chain