mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-04-19 03:01:06 -04:00
**What type of PR is this?** Other **What does this PR do? Why is it needed?** Follow up to https://github.com/OffchainLabs/prysm/pull/16215 this pr improves logging, fixes stuttering in package naming, adds additional unit tests, and deduplicates fallback node code. **Which issues(s) does this PR fix?** fixes a potential race if reconnecting to the same host very quickly which has a stale connection still. **Other notes for review** **Acknowledgements** - [x] I have read [CONTRIBUTING.md](https://github.com/prysmaticlabs/prysm/blob/develop/CONTRIBUTING.md). - [x] I have included a uniquely named [changelog fragment file](https://github.com/prysmaticlabs/prysm/blob/develop/CONTRIBUTING.md#maintaining-changelogmd). - [x] I have added a description with sufficient context for reviewers to understand this PR. - [x] I have tested that my changes work as expected and I added a testing plan to the PR description (if applicable).
53 lines
2.3 KiB
Go
53 lines
2.3 KiB
Go
package beacon_api
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"encoding/json"
|
|
|
|
"github.com/OffchainLabs/prysm/v7/api/server/structs"
|
|
ethpb "github.com/OffchainLabs/prysm/v7/proto/prysm/v1alpha1"
|
|
"github.com/OffchainLabs/prysm/v7/runtime/version"
|
|
"github.com/OffchainLabs/prysm/v7/time/slots"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
func (c *beaconApiValidatorClient) submitSignedAggregateSelectionProof(ctx context.Context, in *ethpb.SignedAggregateSubmitRequest) (*ethpb.SignedAggregateSubmitResponse, error) {
|
|
body, err := json.Marshal([]*structs.SignedAggregateAttestationAndProof{jsonifySignedAggregateAndProof(in.SignedAggregateAndProof)})
|
|
if err != nil {
|
|
return nil, errors.Wrap(err, "failed to marshal SignedAggregateAttestationAndProof")
|
|
}
|
|
headers := map[string]string{"Eth-Consensus-Version": version.String(in.SignedAggregateAndProof.Version())}
|
|
err = c.handler.Post(ctx, "/eth/v2/validator/aggregate_and_proofs", headers, bytes.NewBuffer(body), nil)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
attestationDataRoot, err := in.SignedAggregateAndProof.Message.Aggregate.Data.HashTreeRoot()
|
|
if err != nil {
|
|
return nil, errors.Wrap(err, "failed to compute attestation data root")
|
|
}
|
|
|
|
return ðpb.SignedAggregateSubmitResponse{AttestationDataRoot: attestationDataRoot[:]}, nil
|
|
}
|
|
|
|
func (c *beaconApiValidatorClient) submitSignedAggregateSelectionProofElectra(ctx context.Context, in *ethpb.SignedAggregateSubmitElectraRequest) (*ethpb.SignedAggregateSubmitResponse, error) {
|
|
body, err := json.Marshal([]*structs.SignedAggregateAttestationAndProofElectra{jsonifySignedAggregateAndProofElectra(in.SignedAggregateAndProof)})
|
|
if err != nil {
|
|
return nil, errors.Wrap(err, "failed to marshal SignedAggregateAttestationAndProofElectra")
|
|
}
|
|
dataSlot := in.SignedAggregateAndProof.Message.Aggregate.Data.Slot
|
|
consensusVersion := version.String(slots.ToForkVersion(dataSlot))
|
|
headers := map[string]string{"Eth-Consensus-Version": consensusVersion}
|
|
if err = c.handler.Post(ctx, "/eth/v2/validator/aggregate_and_proofs", headers, bytes.NewBuffer(body), nil); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
attestationDataRoot, err := in.SignedAggregateAndProof.Message.Aggregate.Data.HashTreeRoot()
|
|
if err != nil {
|
|
return nil, errors.Wrap(err, "failed to compute attestation data root")
|
|
}
|
|
|
|
return ðpb.SignedAggregateSubmitResponse{AttestationDataRoot: attestationDataRoot[:]}, nil
|
|
}
|