Skip to content

Commit b705f50

Browse files
Giulio2002yperbasis
authored andcommitted
Added basic block production to Caplin. (#9796)
This PR also does the following additional things: * Introduces correct JSON marshalling/unmarshalling to all objects * BaseFeePerGas marshalled as integer on json caplin-wise * Reduced dumpSlotsStates from 32 to 4 for better performance during reorgs * Added full lock for `OnAttestation` ## Block Production This section highlights how `GET eth/v3/validator/blocks/{slot}` creates a block and then publishes it. The validator client will do execute 2 steps when producing a beacon block. 1) Production step: tell the beacon client to create a block and return it. 2) Publishing step: Sign the block with the proposer private key, and send it back for publishing to other nodes. ### Block creation Let's first look at how block creation happens. So Caplin needs to do 2 things to successfully create a block: 1) Asking the Execution Layer for the Execution block 2) Retrieve Consensus Operations to include in the block (Attestations/VoluntaryExits, etc...) #### Execution block For the execution block, it is quite simple, we ask Erigon to produce us a block through the `AssembleBlock` function avaiable on the Erigon `Eth1` API. We treat erigon as a black box so we do not need to worry too much about this. However, we also need to handle **Blob** bundles, so that later, when we need to publish a block. we can publish the bundles alongside the block (it is important that peers both receive block and the blob or we will fail a check). (Erigon will also gives us the bundle). Right now, we store the blob bundle in an `LRU` which has size set to 8 blocks worth of blobs. **Note: we use an LRU for the convenient eviction policy**. #### Operations TODO. Operations inclusion has not been implemented yet, the execution block is the only thing being delivered. ### Block publishing After we produce the beacon block, we will send it back to the Validator Client, which will sign it and re-forward it to the rest of the network. The flow is straightforward, when we receive the block we simply: 1) pack the block with the blobs the Execution Layer gave caplin during block production 2) Start a separate thread where we import the block into Caplin's database and forkchoice alongside the blobs.. 3) Publish blobs and blocks to the P2P.
1 parent 6e66412 commit b705f50

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1116
-118
lines changed

cl/beacon/beaconhttp/beacon_response.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ func NewBeaconResponse(data any) *BeaconResponse {
2626
func (r *BeaconResponse) With(key string, value any) (out *BeaconResponse) {
2727
out = new(BeaconResponse)
2828
*out = *r
29+
if out.Extra == nil {
30+
out.Extra = make(map[string]any)
31+
}
2932
out.Extra[key] = value
3033
return out
3134
}

0 commit comments

Comments
 (0)