Files
prysm/validator/client/beacon-api/submit_signed_contribution_and_proof.go
james-prysm cf94ccbf72 node fallback cleanup (#16316)
**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).
2026-02-04 15:59:42 +00:00

58 lines
1.8 KiB
Go

package beacon_api
import (
"bytes"
"context"
"encoding/json"
"strconv"
"github.com/OffchainLabs/prysm/v7/api/server/structs"
ethpb "github.com/OffchainLabs/prysm/v7/proto/prysm/v1alpha1"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/pkg/errors"
)
func (c *beaconApiValidatorClient) submitSignedContributionAndProof(ctx context.Context, in *ethpb.SignedContributionAndProof) error {
if in == nil {
return errors.New("signed contribution and proof is nil")
}
if in.Message == nil {
return errors.New("signed contribution and proof message is nil")
}
if in.Message.Contribution == nil {
return errors.New("signed contribution and proof contribution is nil")
}
jsonContributionAndProofs := []structs.SignedContributionAndProof{
{
Message: &structs.ContributionAndProof{
AggregatorIndex: strconv.FormatUint(uint64(in.Message.AggregatorIndex), 10),
Contribution: &structs.SyncCommitteeContribution{
Slot: strconv.FormatUint(uint64(in.Message.Contribution.Slot), 10),
BeaconBlockRoot: hexutil.Encode(in.Message.Contribution.BlockRoot),
SubcommitteeIndex: strconv.FormatUint(in.Message.Contribution.SubcommitteeIndex, 10),
AggregationBits: hexutil.Encode(in.Message.Contribution.AggregationBits),
Signature: hexutil.Encode(in.Message.Contribution.Signature),
},
SelectionProof: hexutil.Encode(in.Message.SelectionProof),
},
Signature: hexutil.Encode(in.Signature),
},
}
jsonContributionAndProofsBytes, err := json.Marshal(jsonContributionAndProofs)
if err != nil {
return errors.Wrap(err, "failed to marshall signed contribution and proof")
}
return c.handler.Post(
ctx,
"/eth/v1/validator/contribution_and_proofs",
nil,
bytes.NewBuffer(jsonContributionAndProofsBytes),
nil,
)
}