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).
56 lines
1.5 KiB
Go
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 ðpb.ProposeExitResponse{
|
|
ExitRoot: exitRoot[:],
|
|
}, nil
|
|
}
|