From 3ff84e2eea15f5614a7910b0a6d43c46f61a04eb Mon Sep 17 00:00:00 2001 From: Angus Scott Date: Fri, 21 Jun 2024 14:05:59 +0100 Subject: [PATCH 1/2] Changing the response for finality checkpoints to match the Ethereum specification https://ethereum.github.io/beacon-APIs/#/Beacon/getStateFinalityCheckpoints --- cl/beacon/handler/states.go | 6 ++-- cl/beacon/handler/states_test.go | 2 +- cl/beacon/handler/test_data/states_1.yaml | 2 +- cl/phase1/core/state/raw/state.go | 42 +++++++++++------------ 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/cl/beacon/handler/states.go b/cl/beacon/handler/states.go index 62d405ddb50..de8d0102881 100644 --- a/cl/beacon/handler/states.go +++ b/cl/beacon/handler/states.go @@ -208,9 +208,9 @@ func (a *ApiHandler) getFullState(w http.ResponseWriter, r *http.Request) (*beac } type finalityCheckpointsResponse struct { - FinalizedCheckpoint solid.Checkpoint `json:"finalized_checkpoint"` - CurrentJustifiedCheckpoint solid.Checkpoint `json:"current_justified_checkpoint"` - PreviousJustifiedCheckpoint solid.Checkpoint `json:"previous_justified_checkpoint"` + FinalizedCheckpoint solid.Checkpoint `json:"finalized"` + CurrentJustifiedCheckpoint solid.Checkpoint `json:"current_justified"` + PreviousJustifiedCheckpoint solid.Checkpoint `json:"previous_justified"` } func (a *ApiHandler) getFinalityCheckpoints(w http.ResponseWriter, r *http.Request) (*beaconhttp.BeaconResponse, error) { diff --git a/cl/beacon/handler/states_test.go b/cl/beacon/handler/states_test.go index fcf61c8e09c..1fb00a03111 100644 --- a/cl/beacon/handler/states_test.go +++ b/cl/beacon/handler/states_test.go @@ -427,7 +427,7 @@ func TestGetStateFinalityCheckpoints(t *testing.T) { code: http.StatusOK, }, } - expected := `{"data":{"finalized_checkpoint":{"epoch":"1","root":"0xde46b0f2ed5e72f0cec20246403b14c963ec995d7c2825f3532b0460c09d5693"},"current_justified_checkpoint":{"epoch":"3","root":"0xa6e47f164b1a3ca30ea3b2144bd14711de442f51e5b634750a12a1734e24c987"},"previous_justified_checkpoint":{"epoch":"2","root":"0x4c3ee7969e485696669498a88c17f70e6999c40603e2f4338869004392069063"}},"execution_optimistic":false,"finalized":false,"version":"bellatrix"}` + "\n" + expected := `{"data":{"finalized":{"epoch":"1","root":"0xde46b0f2ed5e72f0cec20246403b14c963ec995d7c2825f3532b0460c09d5693"},"current_justified":{"epoch":"3","root":"0xa6e47f164b1a3ca30ea3b2144bd14711de442f51e5b634750a12a1734e24c987"},"previous_justified":{"epoch":"2","root":"0x4c3ee7969e485696669498a88c17f70e6999c40603e2f4338869004392069063"}},"execution_optimistic":false,"finalized":false,"version":"bellatrix"}` + "\n" for _, c := range cases { t.Run(c.blockID, func(t *testing.T) { server := httptest.NewServer(handler.mux) diff --git a/cl/beacon/handler/test_data/states_1.yaml b/cl/beacon/handler/test_data/states_1.yaml index f5e63003f7a..8b1e1866a8c 100644 --- a/cl/beacon/handler/test_data/states_1.yaml +++ b/cl/beacon/handler/test_data/states_1.yaml @@ -1,2 +1,2 @@ -finality_checkpoint: {"data":{"finalized_checkpoint":{"epoch":"1","root":"0xde46b0f2ed5e72f0cec20246403b14c963ec995d7c2825f3532b0460c09d5693"},"current_justified_checkpoint":{"epoch":"3","root":"0xa6e47f164b1a3ca30ea3b2144bd14711de442f51e5b634750a12a1734e24c987"},"previous_justified_checkpoint":{"epoch":"2","root":"0x4c3ee7969e485696669498a88c17f70e6999c40603e2f4338869004392069063"}},"finalized":false,"version":2,"execution_optimistic":false} +finality_checkpoint: {"data":{"finalized":{"epoch":"1","root":"0xde46b0f2ed5e72f0cec20246403b14c963ec995d7c2825f3532b0460c09d5693"},"current_justified":{"epoch":"3","root":"0xa6e47f164b1a3ca30ea3b2144bd14711de442f51e5b634750a12a1734e24c987"},"previous_justified":{"epoch":"2","root":"0x4c3ee7969e485696669498a88c17f70e6999c40603e2f4338869004392069063"}},"finalized":false,"version":2,"execution_optimistic":false} randao: {"data":{"randao":"0xdeec617717272914bfd73e02ca1da113a83cf4cf33cd4939486509e2da4ccf4e"},"finalized":false,"execution_optimistic":false} diff --git a/cl/phase1/core/state/raw/state.go b/cl/phase1/core/state/raw/state.go index 7e5ec23d3ce..e522bf7b582 100644 --- a/cl/phase1/core/state/raw/state.go +++ b/cl/phase1/core/state/raw/state.go @@ -109,27 +109,27 @@ func (b *BeaconState) init() error { func (b *BeaconState) MarshalJSON() ([]byte, error) { obj := map[string]interface{}{ - "genesis_time": strconv.FormatInt(int64(b.genesisTime), 10), - "genesis_validators_root": b.genesisValidatorsRoot, - "slot": strconv.FormatInt(int64(b.slot), 10), - "fork": b.fork, - "latest_block_header": b.latestBlockHeader, - "block_roots": b.blockRoots, - "state_roots": b.stateRoots, - "historical_roots": b.historicalRoots, - "eth1_data": b.eth1Data, - "eth1_data_votes": b.eth1DataVotes, - "eth1_deposit_index": strconv.FormatInt(int64(b.eth1DepositIndex), 10), - "validators": b.validators, - "balances": b.balances, - "randao_mixes": b.randaoMixes, - "slashings": b.slashings, - "previous_epoch_participation": b.previousEpochParticipation, - "current_epoch_participation": b.currentEpochParticipation, - "justification_bits": b.justificationBits, - "previous_justified_checkpoint": b.previousJustifiedCheckpoint, - "current_justified_checkpoint": b.currentJustifiedCheckpoint, - "finalized_checkpoint": b.finalizedCheckpoint, + "genesis_time": strconv.FormatInt(int64(b.genesisTime), 10), + "genesis_validators_root": b.genesisValidatorsRoot, + "slot": strconv.FormatInt(int64(b.slot), 10), + "fork": b.fork, + "latest_block_header": b.latestBlockHeader, + "block_roots": b.blockRoots, + "state_roots": b.stateRoots, + "historical_roots": b.historicalRoots, + "eth1_data": b.eth1Data, + "eth1_data_votes": b.eth1DataVotes, + "eth1_deposit_index": strconv.FormatInt(int64(b.eth1DepositIndex), 10), + "validators": b.validators, + "balances": b.balances, + "randao_mixes": b.randaoMixes, + "slashings": b.slashings, + "previous_epoch_participation": b.previousEpochParticipation, + "current_epoch_participation": b.currentEpochParticipation, + "justification_bits": b.justificationBits, + "previous_justified": b.previousJustifiedCheckpoint, + "current_justified": b.currentJustifiedCheckpoint, + "finalized": b.finalizedCheckpoint, } if b.version == clparams.Phase0Version { obj["previous_epoch_attestations"] = b.previousEpochAttestations From aa25821191d93a1eb7a4918304fb154d864f6a62 Mon Sep 17 00:00:00 2001 From: Angus Scott Date: Mon, 24 Jun 2024 08:01:39 +0100 Subject: [PATCH 2/2] Changing the response for finality checkpoints to match the Ethereum specification https://ethereum.github.io/beacon-APIs/#/Beacon/getStateFinalityCheckpoints --- cl/phase1/core/state/raw/state.go | 42 +++++++++++++++---------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/cl/phase1/core/state/raw/state.go b/cl/phase1/core/state/raw/state.go index e522bf7b582..7e5ec23d3ce 100644 --- a/cl/phase1/core/state/raw/state.go +++ b/cl/phase1/core/state/raw/state.go @@ -109,27 +109,27 @@ func (b *BeaconState) init() error { func (b *BeaconState) MarshalJSON() ([]byte, error) { obj := map[string]interface{}{ - "genesis_time": strconv.FormatInt(int64(b.genesisTime), 10), - "genesis_validators_root": b.genesisValidatorsRoot, - "slot": strconv.FormatInt(int64(b.slot), 10), - "fork": b.fork, - "latest_block_header": b.latestBlockHeader, - "block_roots": b.blockRoots, - "state_roots": b.stateRoots, - "historical_roots": b.historicalRoots, - "eth1_data": b.eth1Data, - "eth1_data_votes": b.eth1DataVotes, - "eth1_deposit_index": strconv.FormatInt(int64(b.eth1DepositIndex), 10), - "validators": b.validators, - "balances": b.balances, - "randao_mixes": b.randaoMixes, - "slashings": b.slashings, - "previous_epoch_participation": b.previousEpochParticipation, - "current_epoch_participation": b.currentEpochParticipation, - "justification_bits": b.justificationBits, - "previous_justified": b.previousJustifiedCheckpoint, - "current_justified": b.currentJustifiedCheckpoint, - "finalized": b.finalizedCheckpoint, + "genesis_time": strconv.FormatInt(int64(b.genesisTime), 10), + "genesis_validators_root": b.genesisValidatorsRoot, + "slot": strconv.FormatInt(int64(b.slot), 10), + "fork": b.fork, + "latest_block_header": b.latestBlockHeader, + "block_roots": b.blockRoots, + "state_roots": b.stateRoots, + "historical_roots": b.historicalRoots, + "eth1_data": b.eth1Data, + "eth1_data_votes": b.eth1DataVotes, + "eth1_deposit_index": strconv.FormatInt(int64(b.eth1DepositIndex), 10), + "validators": b.validators, + "balances": b.balances, + "randao_mixes": b.randaoMixes, + "slashings": b.slashings, + "previous_epoch_participation": b.previousEpochParticipation, + "current_epoch_participation": b.currentEpochParticipation, + "justification_bits": b.justificationBits, + "previous_justified_checkpoint": b.previousJustifiedCheckpoint, + "current_justified_checkpoint": b.currentJustifiedCheckpoint, + "finalized_checkpoint": b.finalizedCheckpoint, } if b.version == clparams.Phase0Version { obj["previous_epoch_attestations"] = b.previousEpochAttestations