Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added GetEth1V1BuilderStatesExpectedWithdrawals #9152

Merged
merged 1 commit into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions cl/beacon/handler/builder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package handler

import (
"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/persistence/beacon_indicies"
"github.com/ledgerwatch/erigon/cl/phase1/core/state"
)

func (a *ApiHandler) GetEth1V1BuilderStatesExpectedWit(w http.ResponseWriter, r *http.Request) (*beaconResponse, error) {
ctx := r.Context()

tx, err := a.indiciesDB.BeginRo(ctx)
if err != nil {
return nil, err
}
defer tx.Rollback()

blockId, err := stateIdFromRequest(r)
if err != nil {
return nil, beaconhttp.NewEndpointError(http.StatusBadRequest, err.Error())
}
root, httpStatus, err := a.blockRootFromStateId(ctx, tx, blockId)
if err != nil {
return nil, beaconhttp.NewEndpointError(httpStatus, err.Error())
}
slot, err := beacon_indicies.ReadBlockSlotByBlockRoot(tx, root)
if err != nil {
return nil, err
}
if slot == nil {
return nil, beaconhttp.NewEndpointError(http.StatusNotFound, "state not found")
}
if a.beaconChainCfg.GetCurrentStateVersion(*slot/a.beaconChainCfg.SlotsPerEpoch) < clparams.CapellaVersion {
return nil, beaconhttp.NewEndpointError(http.StatusBadRequest, "the specified state is not a capella state")
}
headRoot, _, err := a.forkchoiceStore.GetHead()
if err != nil {
return nil, err
}
if root == headRoot {
s, cn := a.syncedData.HeadState()
defer cn()
return newBeaconResponse(state.ExpectedWithdrawals(s)).withFinalized(false), nil
}
lookAhead := 1024
for currSlot := *slot + 1; currSlot < *slot+uint64(lookAhead); currSlot++ {
if currSlot > a.syncedData.HeadSlot() {
return nil, beaconhttp.NewEndpointError(http.StatusNotFound, "state not found")
}
blockRoot, err := beacon_indicies.ReadCanonicalBlockRoot(tx, currSlot)
if err != nil {
return nil, err
}
if blockRoot == (libcommon.Hash{}) {
continue
}
blk, err := a.blockReader.ReadBlockByRoot(ctx, tx, blockRoot)
if err != nil {
return nil, err
}
return newBeaconResponse(blk.Block.Body.ExecutionPayload.Withdrawals).withFinalized(false), nil
}

return nil, beaconhttp.NewEndpointError(http.StatusNotFound, "state not found")
}
2 changes: 1 addition & 1 deletion cl/beacon/handler/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func stateIdFromRequest(r *http.Request) (*segmentID, error) {

stateId := chi.URLParam(r, "state_id")
if !regex.MatchString(stateId) {
return nil, fmt.Errorf("invalid path variable: {block_id}")
return nil, fmt.Errorf("invalid path variable: {state_id}")
}

if stateId == "head" {
Expand Down
1 change: 1 addition & 0 deletions cl/beacon/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func (a *ApiHandler) init() {
// otterscn specific ones are commented as such
r.Route("/eth", func(r chi.Router) {
r.Route("/v1", func(r chi.Router) {
r.Get("/builder/states/{state_id}/expected_withdrawals", beaconhttp.HandleEndpointFunc(a.GetEth1V1BuilderStatesExpectedWit))
r.Get("/events", http.NotFound)
r.Route("/node", func(r chi.Router) {
r.Get("/health", a.GetEthV1NodeHealth)
Expand Down
Loading