Skip to content

Commit

Permalink
Add Electra case for GetBeaconStateV2 (#14466)
Browse files Browse the repository at this point in the history
* Add Electra case for GetBeaconStateV2

* Add CHANGELOG.md entry
  • Loading branch information
syjn99 committed Sep 20, 2024
1 parent bc9c719 commit 7231feb
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
9 changes: 5 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ The format is based on Keep a Changelog, and this project adheres to Semantic Ve
- Light client support: Add light client database changes.
- Light client support: Implement capella and deneb changes.
- Light client support: Implement `BlockToLightClientHeaderXXX` functions upto Deneb
- GetBeaconStateV2: add Electra case.

### Changed

Expand Down Expand Up @@ -2673,7 +2674,7 @@ on your validators.
**Beacon chain node**

| Metric | Description | References |
|--------------------------------------------------|-------------------------------------------------------------------------------------------------------|------------|
| ------------------------------------------------ | ----------------------------------------------------------------------------------------------------- | ---------- |
| `p2p_message_ignored_validation_total` | Count of messages that were ignored in validation | |
| `beacon_current_active_validators` | Current total active validators | |
| `beacon_processed_deposits_total` | Total number of deposits processed | |
Expand Down Expand Up @@ -2724,9 +2725,9 @@ on your validators.
#### Changed Metrics

**Beacon chain node**
| Metric | Old Name | Description | References |
|-----------------------|----------------------|------------------------------------------------------|------------|
| `beacon_reorgs_total` | `beacon_reorg_total` | Count the number of times a beacon chain has a reorg | |
| Metric | Old Name | Description | References |
| --------------------- | -------------------- | ---------------------------------------------------- | ---------- |
| `beacon_reorgs_total` | `beacon_reorg_total` | Count the number of times a beacon chain has a reorg | |

### Deprecated

Expand Down
6 changes: 6 additions & 0 deletions beacon-chain/rpc/eth/debug/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ func (s *Server) getBeaconStateV2(ctx context.Context, w http.ResponseWriter, id
httputil.HandleError(w, errMsgStateFromConsensus+": "+err.Error(), http.StatusInternalServerError)
return
}
case version.Electra:
respSt, err = structs.BeaconStateElectraFromConsensus(st)
if err != nil {
httputil.HandleError(w, errMsgStateFromConsensus+": "+err.Error(), http.StatusInternalServerError)
return
}
default:
httputil.HandleError(w, "Unsupported state version", http.StatusInternalServerError)
return
Expand Down
28 changes: 28 additions & 0 deletions beacon-chain/rpc/eth/debug/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,34 @@ func TestGetBeaconStateV2(t *testing.T) {
require.NoError(t, json.Unmarshal(resp.Data, st))
assert.Equal(t, "123", st.Slot)
})
t.Run("Electra", func(t *testing.T) {
fakeState, err := util.NewBeaconStateElectra()
require.NoError(t, err)
require.NoError(t, fakeState.SetSlot(123))
chainService := &blockchainmock.ChainService{}
s := &Server{
Stater: &testutil.MockStater{
BeaconState: fakeState,
},
HeadFetcher: chainService,
OptimisticModeFetcher: chainService,
FinalizationFetcher: chainService,
}

request := httptest.NewRequest(http.MethodGet, "http://example.com/eth/v2/debug/beacon/states/{state_id}", nil)
request.SetPathValue("state_id", "head")
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}

s.GetBeaconStateV2(writer, request)
require.Equal(t, http.StatusOK, writer.Code)
resp := &structs.GetBeaconStateV2Response{}
require.NoError(t, json.Unmarshal(writer.Body.Bytes(), resp))
assert.Equal(t, version.String(version.Electra), resp.Version)
st := &structs.BeaconStateElectra{}
require.NoError(t, json.Unmarshal(resp.Data, st))
assert.Equal(t, "123", st.Slot)
})
t.Run("execution optimistic", func(t *testing.T) {
parentRoot := [32]byte{'a'}
blk := util.NewBeaconBlock()
Expand Down

0 comments on commit 7231feb

Please sign in to comment.