diff --git a/cl/beacon/builder/client.go b/cl/beacon/builder/client.go index 62bb008dbb1..b34fe5d546f 100644 --- a/cl/beacon/builder/client.go +++ b/cl/beacon/builder/client.go @@ -26,7 +26,7 @@ func NewBlockBuilderClient(baseUrl string) *BlockBuilderClient { } } -func (b *BlockBuilderClient) RegisterValidator(ctx context.Context, registers []*ValidatorRegistration) error { +func (b *BlockBuilderClient) RegisterValidator(ctx context.Context, registers []*cltypes.ValidatorRegistration) error { // https://ethereum.github.io/builder-specs/#/Builder/registerValidator url := b.baseUrl + "/eth/v1/builder/validators" payload, err := json.Marshal(registers) diff --git a/cl/beacon/builder/types.go b/cl/beacon/builder/types.go index c5573e72fe5..60917660b85 100644 --- a/cl/beacon/builder/types.go +++ b/cl/beacon/builder/types.go @@ -12,16 +12,6 @@ type ExecutionPayloadHeader struct { } `json:"data"` } -type ValidatorRegistration struct { - Message struct { - FeeRecipient string `json:"fee_recipient"` - GasLimit string `json:"gas_limit"` - Timestamp string `json:"timestamp"` - PubKey string `json:"pubkey"` - } `json:"message"` - Sginature string `json:"signature"` -} - type BlindedBlockResponse struct { Version string `json:"version"` Data cltypes.Eth1Block `json:"data"` diff --git a/cl/beacon/handler/builder.go b/cl/beacon/handler/builder.go index 006678528af..a8dcd3223d0 100644 --- a/cl/beacon/handler/builder.go +++ b/cl/beacon/handler/builder.go @@ -1,12 +1,14 @@ package handler import ( + "encoding/json" "fmt" "net/http" libcommon "github.com/ledgerwatch/erigon-lib/common" "github.com/ledgerwatch/erigon/cl/beacon/beaconhttp" "github.com/ledgerwatch/erigon/cl/clparams" + "github.com/ledgerwatch/erigon/cl/cltypes" "github.com/ledgerwatch/erigon/cl/persistence/beacon_indicies" "github.com/ledgerwatch/erigon/cl/phase1/core/state" ) @@ -70,3 +72,20 @@ func (a *ApiHandler) GetEth1V1BuilderStatesExpectedWithdrawals(w http.ResponseWr return nil, beaconhttp.NewEndpointError(http.StatusNotFound, fmt.Errorf("state not found")) } + +func (a *ApiHandler) PostEthV1BuilderRegisterValidator(w http.ResponseWriter, r *http.Request) (*beaconhttp.BeaconResponse, error) { + registerReq := []*cltypes.ValidatorRegistration{} + if err := json.NewDecoder(r.Body).Decode(®isterReq); err != nil { + return nil, beaconhttp.NewEndpointError(http.StatusBadRequest, err) + } + if len(registerReq) == 0 { + return nil, beaconhttp.NewEndpointError(http.StatusBadRequest, fmt.Errorf("empty request")) + } + if err := a.builderClient.RegisterValidator(r.Context(), registerReq); err != nil { + return nil, beaconhttp.NewEndpointError(http.StatusInternalServerError, err) + } + for _, v := range registerReq { + a.logger.Debug("[Caplin] Registred new validator", "fee_recipient", v.Message.FeeRecipient) + } + return newBeaconResponse(nil), nil +} diff --git a/cl/beacon/handler/handler.go b/cl/beacon/handler/handler.go index 846b9521bad..10e06f0be16 100644 --- a/cl/beacon/handler/handler.go +++ b/cl/beacon/handler/handler.go @@ -12,6 +12,7 @@ import ( "github.com/ledgerwatch/erigon/cl/beacon/beacon_router_configuration" "github.com/ledgerwatch/erigon/cl/beacon/beaconevents" "github.com/ledgerwatch/erigon/cl/beacon/beaconhttp" + "github.com/ledgerwatch/erigon/cl/beacon/builder" "github.com/ledgerwatch/erigon/cl/beacon/synced_data" "github.com/ledgerwatch/erigon/cl/clparams" "github.com/ledgerwatch/erigon/cl/cltypes" @@ -86,6 +87,7 @@ type ApiHandler struct { voluntaryExitService services.VoluntaryExitService blsToExecutionChangeService services.BLSToExecutionChangeService proposerSlashingService services.ProposerSlashingService + builderClient *builder.BlockBuilderClient } func NewApiHandler( @@ -118,6 +120,7 @@ func NewApiHandler( voluntaryExitService services.VoluntaryExitService, blsToExecutionChangeService services.BLSToExecutionChangeService, proposerSlashingService services.ProposerSlashingService, + builderClient *builder.BlockBuilderClient, ) *ApiHandler { blobBundles, err := lru.New[common.Bytes48, BlobBundle]("blobs", maxBlobBundleCacheSize) if err != nil { @@ -158,6 +161,7 @@ func NewApiHandler( voluntaryExitService: voluntaryExitService, blsToExecutionChangeService: blsToExecutionChangeService, proposerSlashingService: proposerSlashingService, + builderClient: builderClient, } } @@ -182,6 +186,7 @@ func (a *ApiHandler) init() { r.Route("/v1", func(r chi.Router) { if a.routerCfg.Builder { r.Get("/builder/states/{state_id}/expected_withdrawals", beaconhttp.HandleEndpointFunc(a.GetEth1V1BuilderStatesExpectedWithdrawals)) + r.Post("/validator/register_validator", beaconhttp.HandleEndpointFunc(a.PostEthV1BuilderRegisterValidator)) } if a.routerCfg.Events { r.Get("/events", a.EventSourceGetV1Events) diff --git a/cl/cltypes/builder.go b/cl/cltypes/builder.go new file mode 100644 index 00000000000..57ec41840c5 --- /dev/null +++ b/cl/cltypes/builder.go @@ -0,0 +1,13 @@ +package cltypes + +import libcommon "github.com/ledgerwatch/erigon-lib/common" + +type ValidatorRegistration struct { + Message struct { + FeeRecipient libcommon.Address `json:"fee_recipient"` + GasLimit string `json:"gas_limit"` + Timestamp string `json:"timestamp"` + PubKey libcommon.Bytes48 `json:"pubkey"` + } `json:"message"` + Signature libcommon.Bytes96 `json:"signature"` +} diff --git a/cmd/caplin/caplin1/run.go b/cmd/caplin/caplin1/run.go index 22cc2266fec..969be1f2a52 100644 --- a/cmd/caplin/caplin1/run.go +++ b/cmd/caplin/caplin1/run.go @@ -297,6 +297,7 @@ func RunCaplinPhase1(ctx context.Context, engine execution_client.ExecutionEngin voluntaryExitService, blsToExecutionChangeService, proposerSlashingService, + option.builderClient, ) go beacon.ListenAndServe(&beacon.LayeredBeaconHandler{ ArchiveApi: apiHandler,