mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-22 03:30:37 +00:00
Added EthV1AggregateAndProofs API (#9192)
Added publishing of aggregates and proofs
This commit is contained in:
parent
09ec1f160c
commit
284aa1dd0c
@ -119,7 +119,7 @@ func (a *ApiHandler) init() {
|
||||
r.Get("/blinded_blocks/{slot}", http.NotFound)
|
||||
r.Get("/attestation_data", http.NotFound)
|
||||
r.Get("/aggregate_attestation", http.NotFound)
|
||||
r.Post("/aggregate_and_proofs", http.NotFound)
|
||||
r.Post("/aggregate_and_proofs", a.PostEthV1ValidatorAggregatesAndProof)
|
||||
r.Post("/beacon_committee_subscriptions", http.NotFound)
|
||||
r.Post("/sync_committee_subscriptions", http.NotFound)
|
||||
r.Get("/sync_committee_contribution", http.NotFound)
|
||||
|
@ -191,3 +191,35 @@ func (a *ApiHandler) PostEthV1BeaconPoolBlsToExecutionChanges(w http.ResponseWri
|
||||
// Only write 200
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
func (a *ApiHandler) PostEthV1ValidatorAggregatesAndProof(w http.ResponseWriter, r *http.Request) {
|
||||
req := []*cltypes.SignedAggregateAndProof{}
|
||||
|
||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
failures := []poolingFailure{}
|
||||
for _, v := range req {
|
||||
if err := a.forkchoiceStore.OnAggregateAndProof(v, false); err != nil {
|
||||
failures = append(failures, poolingFailure{Index: len(failures), Message: err.Error()})
|
||||
continue
|
||||
}
|
||||
// Broadcast to gossip
|
||||
if a.sentinel != nil {
|
||||
encodedSSZ, err := v.EncodeSSZ(nil)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
if _, err := a.sentinel.PublishGossip(r.Context(), &sentinel.GossipData{
|
||||
Data: encodedSSZ,
|
||||
Name: gossip.TopicNameBeaconAggregateAndProof,
|
||||
}); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -195,3 +195,52 @@ func TestPoolBlsToExecutionChainges(t *testing.T) {
|
||||
require.Equal(t, msg[0], out.Data[0])
|
||||
require.Equal(t, msg[1], out.Data[1])
|
||||
}
|
||||
|
||||
func TestPoolAggregatesAndProofs(t *testing.T) {
|
||||
msg := []*cltypes.SignedAggregateAndProof{
|
||||
{
|
||||
Message: &cltypes.AggregateAndProof{
|
||||
Aggregate: solid.NewAttestionFromParameters([]byte{1, 2}, solid.NewAttestationData(), libcommon.Bytes96{3, 45, 6}),
|
||||
},
|
||||
Signature: libcommon.Bytes96{2},
|
||||
},
|
||||
{
|
||||
Message: &cltypes.AggregateAndProof{
|
||||
Aggregate: solid.NewAttestionFromParameters([]byte{1, 2, 5, 6}, solid.NewAttestationData(), libcommon.Bytes96{3, 0, 6}),
|
||||
},
|
||||
Signature: libcommon.Bytes96{2, 3, 5},
|
||||
},
|
||||
}
|
||||
// find server
|
||||
_, _, _, _, _, handler, _, _, _ := setupTestingHandler(t, clparams.Phase0Version)
|
||||
|
||||
server := httptest.NewServer(handler.mux)
|
||||
defer server.Close()
|
||||
// json
|
||||
req, err := json.Marshal(msg)
|
||||
require.NoError(t, err)
|
||||
// post attester slashing
|
||||
resp, err := server.Client().Post(server.URL+"/eth/v1/validator/aggregate_and_proofs", "application/json", bytes.NewBuffer(req))
|
||||
require.NoError(t, err)
|
||||
defer resp.Body.Close()
|
||||
|
||||
require.Equal(t, 200, resp.StatusCode)
|
||||
// get attester slashings
|
||||
resp, err = server.Client().Get(server.URL + "/eth/v1/beacon/pool/attestations")
|
||||
require.NoError(t, err)
|
||||
defer resp.Body.Close()
|
||||
|
||||
require.Equal(t, 200, resp.StatusCode)
|
||||
out := struct {
|
||||
Data []*solid.Attestation `json:"data"`
|
||||
}{
|
||||
Data: []*solid.Attestation{},
|
||||
}
|
||||
|
||||
err = json.NewDecoder(resp.Body).Decode(&out)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, 2, len(out.Data))
|
||||
require.Equal(t, msg[0].Message.Aggregate, out.Data[0])
|
||||
require.Equal(t, msg[1].Message.Aggregate, out.Data[1])
|
||||
}
|
||||
|
@ -65,6 +65,7 @@ func (a *Attestation) UnmarshalJSON(buf []byte) error {
|
||||
Signature libcommon.Bytes96 `json:"signature"`
|
||||
Data AttestationData `json:"data"`
|
||||
}
|
||||
tmp.Data = NewAttestationData()
|
||||
if err := json.Unmarshal(buf, &tmp); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -220,3 +220,8 @@ func (f *ForkChoiceStorageMock) OnBlsToExecutionChange(signedChange *cltypes.Sig
|
||||
func (f *ForkChoiceStorageMock) ForkNodes() []ForkNode {
|
||||
return f.WeightsMock
|
||||
}
|
||||
|
||||
func (f *ForkChoiceStorageMock) OnAggregateAndProof(aggregateAndProof *cltypes.SignedAggregateAndProof, test bool) error {
|
||||
f.Pool.AttestationsPool.Insert(aggregateAndProof.Message.Aggregate.Signature(), aggregateAndProof.Message.Aggregate)
|
||||
return nil
|
||||
}
|
||||
|
@ -44,6 +44,7 @@ type ForkChoiceStorageReader interface {
|
||||
}
|
||||
|
||||
type ForkChoiceStorageWriter interface {
|
||||
OnAggregateAndProof(aggregateAndProof *cltypes.SignedAggregateAndProof, test bool) error
|
||||
OnAttestation(attestation *solid.Attestation, fromBlock, insert bool) error
|
||||
OnAttesterSlashing(attesterSlashing *cltypes.AttesterSlashing, test bool) error
|
||||
OnVoluntaryExit(signedVoluntaryExit *cltypes.SignedVoluntaryExit, test bool) error
|
||||
|
Loading…
Reference in New Issue
Block a user