Files
prysm/validator/client/beacon-api/propose_exit.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

56 lines
1.5 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) proposeExit(ctx context.Context, signedVoluntaryExit *ethpb.SignedVoluntaryExit) (*ethpb.ProposeExitResponse, error) {
if signedVoluntaryExit == nil {
return nil, errors.New("signed voluntary exit is nil")
}
if signedVoluntaryExit.Exit == nil {
return nil, errors.New("exit is nil")
}
jsonSignedVoluntaryExit := structs.SignedVoluntaryExit{
Message: &structs.VoluntaryExit{
Epoch: strconv.FormatUint(uint64(signedVoluntaryExit.Exit.Epoch), 10),
ValidatorIndex: strconv.FormatUint(uint64(signedVoluntaryExit.Exit.ValidatorIndex), 10),
},
Signature: hexutil.Encode(signedVoluntaryExit.Signature),
}
marshalledSignedVoluntaryExit, err := json.Marshal(jsonSignedVoluntaryExit)
if err != nil {
return nil, errors.Wrap(err, "failed to marshal signed voluntary exit")
}
if err = c.handler.Post(
ctx,
"/eth/v1/beacon/pool/voluntary_exits",
nil,
bytes.NewBuffer(marshalledSignedVoluntaryExit),
nil,
); err != nil {
return nil, err
}
exitRoot, err := signedVoluntaryExit.Exit.HashTreeRoot()
if err != nil {
return nil, errors.Wrap(err, "failed to compute exit root")
}
return &ethpb.ProposeExitResponse{
ExitRoot: exitRoot[:],
}, nil
}