-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e958d35
commit 34d3bd2
Showing
3 changed files
with
71 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters