2022-12-05 10:27:41 +00:00
|
|
|
package beacon_api
|
|
|
|
|
|
|
|
import (
|
2023-01-06 03:32:13 +00:00
|
|
|
"context"
|
|
|
|
|
2022-12-05 10:27:41 +00:00
|
|
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/prysmaticlabs/prysm/v3/beacon-chain/core/signing"
|
|
|
|
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
|
|
|
"github.com/prysmaticlabs/prysm/v3/network/forks"
|
|
|
|
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
|
|
|
)
|
|
|
|
|
2023-01-06 03:32:13 +00:00
|
|
|
func (c beaconApiValidatorClient) getDomainData(ctx context.Context, epoch types.Epoch, domainType [4]byte) (*ethpb.DomainResponse, error) {
|
2022-12-05 10:27:41 +00:00
|
|
|
// Get the fork version from the given epoch
|
|
|
|
fork, err := forks.Fork(epoch)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrapf(err, "failed to get fork version for epoch %d", epoch)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the genesis validator root
|
2023-01-06 03:32:13 +00:00
|
|
|
genesis, _, err := c.genesisProvider.GetGenesis(ctx)
|
2022-12-05 10:27:41 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "failed to get genesis info")
|
|
|
|
}
|
|
|
|
|
|
|
|
if !validRoot(genesis.GenesisValidatorsRoot) {
|
|
|
|
return nil, errors.Errorf("invalid genesis validators root: %s", genesis.GenesisValidatorsRoot)
|
|
|
|
}
|
|
|
|
|
|
|
|
genesisValidatorRoot, err := hexutil.Decode(genesis.GenesisValidatorsRoot)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "failed to decode genesis validators root")
|
|
|
|
}
|
|
|
|
|
|
|
|
signatureDomain, err := signing.Domain(fork, epoch, domainType, genesisValidatorRoot)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "failed to compute signature domain")
|
|
|
|
}
|
|
|
|
|
|
|
|
return ðpb.DomainResponse{SignatureDomain: signatureDomain}, nil
|
|
|
|
}
|