mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-01-09 13:56:23 +00:00
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:
parent
a57cec56cb
commit
96dfe18a3d
@ -2653,23 +2653,13 @@ proc broadcastBeaconBlock*(
|
||||
let topic = getBeaconBlocksTopic(node.forkDigests.capella)
|
||||
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
|
||||
|
||||
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*(
|
||||
node: Eth2Node, msg: SyncCommitteeMessage,
|
||||
subcommitteeIdx: SyncSubcommitteeIndex): Future[SendResult] =
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
import
|
||||
stew/assign2,
|
||||
stew/results,
|
||||
chronicles,
|
||||
../extras,
|
||||
"."/[
|
||||
@ -257,7 +258,7 @@ type
|
||||
# block gossip structures. It is for used only for
|
||||
# gossip-originating blocks, which are eventually separated into the
|
||||
# constituent parts before passing along into core functions.
|
||||
type ForkySignedBeaconBlockMaybeBlobs* =
|
||||
type ForkySignedBeaconBlockMaybeBlobs* =
|
||||
phase0.SignedBeaconBlock |
|
||||
altair.SignedBeaconBlock |
|
||||
bellatrix.SignedBeaconBlock |
|
||||
@ -272,6 +273,14 @@ template toSignedBeaconBlock*(b: ForkySignedBeaconBlockMaybeBlobs): ForkySignedB
|
||||
else:
|
||||
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](
|
||||
t: type T): BeaconStateFork =
|
||||
BeaconStateFork.Phase0
|
||||
|
@ -107,7 +107,12 @@ proc routeSignedBeaconBlock*(
|
||||
# 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
|
||||
# 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():
|
||||
beacon_blocks_sent.inc()
|
||||
@ -121,9 +126,8 @@ proc routeSignedBeaconBlock*(
|
||||
blockRoot = shortLog(blck.root), blck = shortLog(blck.message),
|
||||
signature = shortLog(blck.signature), error = res.error()
|
||||
|
||||
let
|
||||
newBlockRef = await router[].blockProcessor.storeBlock(
|
||||
MsgSource.api, sendTime, blck, Opt.none(eip4844.BlobsSidecar))
|
||||
let newBlockRef = await router[].blockProcessor.storeBlock(
|
||||
MsgSource.api, sendTime, blck, optBlobs(blckAndBlobs))
|
||||
|
||||
# The boolean we return tells the caller whether the block was integrated
|
||||
# into the chain
|
||||
|
Loading…
x
Reference in New Issue
Block a user