Skip to content

Commit

Permalink
Add util to generate chain from rpc-address (#13753)
Browse files Browse the repository at this point in the history
  • Loading branch information
Giulio2002 authored Feb 10, 2025
1 parent 1cc6de6 commit 0e25f80
Show file tree
Hide file tree
Showing 7 changed files with 481 additions and 13 deletions.
3 changes: 0 additions & 3 deletions cl/beacon/handler/headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,10 @@ func (a *ApiHandler) getHeader(w http.ResponseWriter, r *http.Request) (*beaconh
return nil, err
}

version := a.beaconChainCfg.GetCurrentStateVersion(signedHeader.Header.Slot / a.beaconChainCfg.SlotsPerEpoch)

return newBeaconResponse(&headerResponse{
Root: root,
Canonical: canonicalRoot == root,
Header: signedHeader,
}).WithFinalized(canonicalRoot == root && signedHeader.Header.Slot <= a.forkchoiceStore.FinalizedSlot()).
WithVersion(version).
WithOptimistic(a.forkchoiceStore.IsRootOptimistic(root)), nil
}
4 changes: 1 addition & 3 deletions cl/beacon/handler/states.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,6 @@ func (a *ApiHandler) getFinalityCheckpoints(w http.ResponseWriter, r *http.Reque
return nil, beaconhttp.NewEndpointError(http.StatusNotFound, fmt.Errorf("could not read checkpoints: %x, %d", blockRoot, a.beaconChainCfg.RoundSlotToEpoch(*slot)))
}
}
version := a.beaconChainCfg.GetCurrentStateVersion(*slot / a.beaconChainCfg.SlotsPerEpoch)
canonicalRoot, err := beacon_indicies.ReadCanonicalBlockRoot(tx, *slot)
if err != nil {
return nil, err
Expand All @@ -279,8 +278,7 @@ func (a *ApiHandler) getFinalityCheckpoints(w http.ResponseWriter, r *http.Reque
FinalizedCheckpoint: finalizedCheckpoint,
CurrentJustifiedCheckpoint: currentJustifiedCheckpoint,
PreviousJustifiedCheckpoint: previousJustifiedCheckpoint,
}).WithFinalized(canonicalRoot == blockRoot && *slot <= a.forkchoiceStore.FinalizedSlot()).
WithVersion(version).WithOptimistic(isOptimistic), nil
}).WithFinalized(canonicalRoot == blockRoot && *slot <= a.forkchoiceStore.FinalizedSlot()).WithOptimistic(isOptimistic), nil
}

type syncCommitteesResponse struct {
Expand Down
2 changes: 1 addition & 1 deletion cl/beacon/handler/states_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ func TestGetStateFinalityCheckpoints(t *testing.T) {
code: http.StatusOK,
},
}
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"
expected := `{"data":{"finalized":{"epoch":"1","root":"0xde46b0f2ed5e72f0cec20246403b14c963ec995d7c2825f3532b0460c09d5693"},"current_justified":{"epoch":"3","root":"0xa6e47f164b1a3ca30ea3b2144bd14711de442f51e5b634750a12a1734e24c987"},"previous_justified":{"epoch":"2","root":"0x4c3ee7969e485696669498a88c17f70e6999c40603e2f4338869004392069063"}},"execution_optimistic":false,"finalized":false}` + "\n"
for _, c := range cases {
t.Run(c.blockID, func(t *testing.T) {
server := httptest.NewServer(handler.mux)
Expand Down
2 changes: 1 addition & 1 deletion cl/beacon/handler/test_data/states_1.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
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}
finality_checkpoint: {"data":{"finalized":{"epoch":"1","root":"0xde46b0f2ed5e72f0cec20246403b14c963ec995d7c2825f3532b0460c09d5693"},"current_justified":{"epoch":"3","root":"0xa6e47f164b1a3ca30ea3b2144bd14711de442f51e5b634750a12a1734e24c987"},"previous_justified":{"epoch":"2","root":"0x4c3ee7969e485696669498a88c17f70e6999c40603e2f4338869004392069063"}},"finalized":false,"execution_optimistic":false}
randao: {"data":{"randao":"0xdeec617717272914bfd73e02ca1da113a83cf4cf33cd4939486509e2da4ccf4e"},"finalized":false,"execution_optimistic":false}
22 changes: 17 additions & 5 deletions cl/cltypes/solid/validator_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,26 @@ func (v *ValidatorSet) Append(val Validator) {
if offset+validatorSize >= len(v.buffer) {
v.expandBuffer(v.l + 1)
v.phase0Data = append(v.phase0Data, Phase0Data{})

if v.MerkleTree != nil {
v.MerkleTree.AppendLeaf()
}
v.zeroTreeHash(v.l)
copy(v.buffer[offset:], val)
}
if v.MerkleTree != nil {
v.MerkleTree.AppendLeaf()
if v.l >= len(v.phase0Data) {
for i := len(v.phase0Data); i < v.l+1; i++ {
v.phase0Data = append(v.phase0Data, Phase0Data{})
}
}
v.zeroTreeHash(v.l)
copy(v.buffer[offset:], val)
v.phase0Data[v.l] = Phase0Data{} // initialize to empty.
v.attesterBits = append(v.attesterBits, 0x0)

if v.l >= len(v.attesterBits) {
for i := len(v.attesterBits); i < v.l+1; i++ {
v.attesterBits = append(v.attesterBits, 0)
}
}
v.attesterBits[v.l] = 0 // initialize to empty.
v.l++
}

Expand Down
Loading

0 comments on commit 0e25f80

Please sign in to comment.