Prysm V3: update signing type (#11099)

* updating proto name

* updating generated files

* updating names on block v2 and v3 signing types

* fixing import format

* fixing unit tests

* fixing unit test

* fixing more conflicts

Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>
Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
james-prysm
2022-08-15 13:22:14 -05:00
committed by GitHub
parent 8de5512908
commit 63b7376b75
10 changed files with 191 additions and 197 deletions

View File

@@ -26,8 +26,9 @@ WIP
- ATTESTATION <- *validatorpb.SignRequest_AttestationData
- AGGREGATE_AND_PROOF <- *validatorpb.SignRequest_AggregateAttestationAndProof
- AGGREGATION_SLOT <- *validatorpb.SignRequest_Slot
- BLOCK_V2 <- *validatorpb.SignRequest_BlockV2
- BLOCK_V3 <- *validatorpb.SignRequest_BlockV3
- BLOCK_ALTAIR <- *validatorpb.SignRequest_BlockAltair
- BLOCK_BELLATRIX <- *validatorpb.SignRequest_BlockBellatrix
- BLINDED_BLOCK_BELLATRIX <- *validatorpb.SignRequest_BlindedBlockBellatrix
- DEPOSIT <- not supported
- RANDAO_REVEAL <- *validatorpb.SignRequest_Epoch
- VOLUNTARY_EXIT <- *validatorpb.SignRequest_Exit

View File

@@ -152,35 +152,35 @@ func getSignRequestJson(ctx context.Context, validator *validator.Validate, requ
}
aggregationSlotSignRequestsTotal.Inc()
return json.Marshal(aggregationSlotSignRequest)
case *validatorpb.SignRequest_BlockV2:
blockv2AltairSignRequest, err := web3signerv1.GetBlockV2AltairSignRequest(request, genesisValidatorsRoot)
case *validatorpb.SignRequest_BlockAltair:
blockv2AltairSignRequest, err := web3signerv1.GetBlockAltairSignRequest(request, genesisValidatorsRoot)
if err != nil {
return nil, err
}
if err = validator.StructCtx(ctx, blockv2AltairSignRequest); err != nil {
return nil, err
}
blockV2SignRequestsTotal.Inc()
blockAltairSignRequestsTotal.Inc()
return json.Marshal(blockv2AltairSignRequest)
case *validatorpb.SignRequest_BlockV3:
blockv2BellatrixSignRequest, err := web3signerv1.GetBlockV2BellatrixSignRequest(request, genesisValidatorsRoot)
case *validatorpb.SignRequest_BlockBellatrix:
blockv2BellatrixSignRequest, err := web3signerv1.GetBlockBellatrixSignRequest(request, genesisValidatorsRoot)
if err != nil {
return nil, err
}
if err = validator.StructCtx(ctx, blockv2BellatrixSignRequest); err != nil {
return nil, err
}
blockV3SignRequestsTotal.Inc()
blockBellatrixSignRequestsTotal.Inc()
return json.Marshal(blockv2BellatrixSignRequest)
case *validatorpb.SignRequest_BlindedBlockV3:
blindedBlockv2SignRequest, err := web3signerv1.GetBlockV2BellatrixSignRequest(request, genesisValidatorsRoot)
case *validatorpb.SignRequest_BlindedBlockBellatrix:
blindedBlockv2SignRequest, err := web3signerv1.GetBlockBellatrixSignRequest(request, genesisValidatorsRoot)
if err != nil {
return nil, err
}
if err = validator.StructCtx(ctx, blindedBlockv2SignRequest); err != nil {
return nil, err
}
blindedblockV3SignRequestsTotal.Inc()
blindedblockBellatrixSignRequestsTotal.Inc()
return json.Marshal(blindedBlockv2SignRequest)
// We do not support "DEPOSIT" type.
/*

View File

@@ -30,17 +30,17 @@ var (
Name: "remote_web3signer_attestation_sign_requests_total",
Help: "Total number of attestation sign requests",
})
blockV2SignRequestsTotal = promauto.NewCounter(prometheus.CounterOpts{
Name: "remote_web3signer_block_v2_sign_requests_total",
Help: "Total number of block v2 sign requests",
blockAltairSignRequestsTotal = promauto.NewCounter(prometheus.CounterOpts{
Name: "remote_web3signer_block_altair_sign_requests_total",
Help: "Total number of block altair sign requests",
})
blockV3SignRequestsTotal = promauto.NewCounter(prometheus.CounterOpts{
Name: "remote_web3signer_block_v3_sign_requests_total",
Help: "Total number of block v3 sign requests",
blockBellatrixSignRequestsTotal = promauto.NewCounter(prometheus.CounterOpts{
Name: "remote_web3signer_block_bellatrix_sign_requests_total",
Help: "Total number of block bellatrix sign requests",
})
blindedblockV3SignRequestsTotal = promauto.NewCounter(prometheus.CounterOpts{
Name: "remote_web3signer_blinded_block_v3_sign_requests_total",
Help: "Total number of blinded block v3 sign requests",
blindedblockBellatrixSignRequestsTotal = promauto.NewCounter(prometheus.CounterOpts{
Name: "remote_web3signer_blinded_block_bellatrix_sign_requests_total",
Help: "Total number of blinded block bellatrix sign requests",
})
randaoRevealSignRequestsTotal = promauto.NewCounter(prometheus.CounterOpts{
Name: "remote_web3signer_randao_reveal_sign_requests_total",

View File

@@ -210,13 +210,13 @@ func GetMockSignRequest(t string) *validatorpb.SignRequest {
},
SigningSlot: 0,
}
case "BLOCK_V2":
case "BLOCK_V2", "BLOCK_V2_ALTAIR":
return &validatorpb.SignRequest{
PublicKey: make([]byte, fieldparams.BLSPubkeyLength),
SigningRoot: make([]byte, fieldparams.RootLength),
SignatureDomain: make([]byte, 4),
Object: &validatorpb.SignRequest_BlockV2{
BlockV2: &eth.BeaconBlockAltair{
Object: &validatorpb.SignRequest_BlockAltair{
BlockAltair: &eth.BeaconBlockAltair{
Slot: 0,
ProposerIndex: 0,
ParentRoot: make([]byte, fieldparams.RootLength),
@@ -332,8 +332,8 @@ func GetMockSignRequest(t string) *validatorpb.SignRequest {
PublicKey: make([]byte, fieldparams.BLSPubkeyLength),
SigningRoot: make([]byte, fieldparams.RootLength),
SignatureDomain: make([]byte, 4),
Object: &validatorpb.SignRequest_BlockV3{
BlockV3: util.HydrateBeaconBlockBellatrix(&eth.BeaconBlockBellatrix{}),
Object: &validatorpb.SignRequest_BlockBellatrix{
BlockBellatrix: util.HydrateBeaconBlockBellatrix(&eth.BeaconBlockBellatrix{}),
},
}
case "BLOCK_V2_BLINDED_BELLATRIX":
@@ -341,8 +341,8 @@ func GetMockSignRequest(t string) *validatorpb.SignRequest {
PublicKey: make([]byte, fieldparams.BLSPubkeyLength),
SigningRoot: make([]byte, fieldparams.RootLength),
SignatureDomain: make([]byte, 4),
Object: &validatorpb.SignRequest_BlindedBlockV3{
BlindedBlockV3: util.HydrateBlindedBeaconBlockBellatrix(&eth.BlindedBeaconBlockBellatrix{}),
Object: &validatorpb.SignRequest_BlindedBlockBellatrix{
BlindedBlockBellatrix: util.HydrateBlindedBeaconBlockBellatrix(&eth.BlindedBeaconBlockBellatrix{}),
},
}
case "RANDAO_REVEAL":
@@ -482,9 +482,9 @@ func MockBlockSignRequest() *v1.BlockSignRequest {
}
}
// MockBlockV2AltairSignRequest is a mock implementation of the BlockV2AltairSignRequest.
func MockBlockV2AltairSignRequest() *v1.BlockV2AltairSignRequest {
return &v1.BlockV2AltairSignRequest{
// MockBlockV2AltairSignRequest is a mock implementation of the BlockAltairSignRequest.
func MockBlockV2AltairSignRequest() *v1.BlockAltairSignRequest {
return &v1.BlockAltairSignRequest{
Type: "BLOCK_V2",
ForkInfo: MockForkInfo(),
SigningRoot: make([]byte, fieldparams.RootLength),
@@ -495,8 +495,8 @@ func MockBlockV2AltairSignRequest() *v1.BlockV2AltairSignRequest {
}
}
func MockBlockV2BellatrixSignRequest(bodyRoot []byte) *v1.BlockV2BellatrixSignRequest {
return &v1.BlockV2BellatrixSignRequest{
func MockBlockV2BellatrixSignRequest(bodyRoot []byte) *v1.BlockBellatrixSignRequest {
return &v1.BlockBellatrixSignRequest{
Type: "BLOCK_V2",
ForkInfo: MockForkInfo(),
SigningRoot: make([]byte, fieldparams.RootLength),

View File

@@ -113,30 +113,30 @@ func GetAttestationSignRequest(request *validatorpb.SignRequest, genesisValidato
}, nil
}
// GetBlockV2AltairSignRequest maps the request for signing type BLOCK_V2.
func GetBlockV2AltairSignRequest(request *validatorpb.SignRequest, genesisValidatorsRoot []byte) (*BlockV2AltairSignRequest, error) {
beaconBlockV2, ok := request.Object.(*validatorpb.SignRequest_BlockV2)
// GetBlockAltairSignRequest maps the request for signing type BLOCK_V2.
func GetBlockAltairSignRequest(request *validatorpb.SignRequest, genesisValidatorsRoot []byte) (*BlockAltairSignRequest, error) {
beaconBlockAltair, ok := request.Object.(*validatorpb.SignRequest_BlockAltair)
if !ok {
return nil, errors.New("failed to cast request object to block v2")
return nil, errors.New("failed to cast request object to block altair")
}
if beaconBlockV2 == nil {
if beaconBlockAltair == nil {
return nil, errors.New("invalid sign request: BeaconBlock is nil")
}
fork, err := MapForkInfo(request.SigningSlot, genesisValidatorsRoot)
if err != nil {
return nil, err
}
beaconBlockAltair, err := MapBeaconBlockAltair(beaconBlockV2.BlockV2)
blockAltair, err := MapBeaconBlockAltair(beaconBlockAltair.BlockAltair)
if err != nil {
return nil, err
}
return &BlockV2AltairSignRequest{
return &BlockAltairSignRequest{
Type: "BLOCK_V2",
ForkInfo: fork,
SigningRoot: request.SigningRoot,
BeaconBlock: &BeaconBlockAltairBlockV2{
Version: "ALTAIR",
Block: beaconBlockAltair,
Block: blockAltair,
},
}, nil
}
@@ -271,37 +271,36 @@ func GetSyncCommitteeContributionAndProofSignRequest(request *validatorpb.SignRe
}, nil
}
// GetBlockV2BellatrixSignRequest maps the request for signing type BLOCK_V2_BELLATRIX.
// note: web3signer uses blockv2 instead of block v3 for signing type
func GetBlockV2BellatrixSignRequest(request *validatorpb.SignRequest, genesisValidatorsRoot []byte) (*BlockV2BellatrixSignRequest, error) {
// GetBlockBellatrixSignRequest maps the request for signing type BLOCK_V2_BELLATRIX.
func GetBlockBellatrixSignRequest(request *validatorpb.SignRequest, genesisValidatorsRoot []byte) (*BlockBellatrixSignRequest, error) {
if request == nil {
return nil, errors.New("nil sign request provided")
}
var b interfaces.BeaconBlock
switch request.Object.(type) {
case *validatorpb.SignRequest_BlindedBlockV3:
blindedBlockV3, ok := request.Object.(*validatorpb.SignRequest_BlindedBlockV3)
case *validatorpb.SignRequest_BlindedBlockBellatrix:
blindedBlockBellatrix, ok := request.Object.(*validatorpb.SignRequest_BlindedBlockBellatrix)
if !ok {
return nil, errors.New("failed to cast request object to blinded block v3")
return nil, errors.New("failed to cast request object to blinded block bellatrix")
}
if blindedBlockV3 == nil {
return nil, errors.New("invalid sign request - blindedBlockV3 is nil")
if blindedBlockBellatrix == nil {
return nil, errors.New("invalid sign request - blindedBlockBellatrix is nil")
}
beaconBlock, err := blocks.NewBeaconBlock(blindedBlockV3.BlindedBlockV3)
beaconBlock, err := blocks.NewBeaconBlock(blindedBlockBellatrix.BlindedBlockBellatrix)
if err != nil {
return nil, err
}
b = beaconBlock
case *validatorpb.SignRequest_BlockV3:
blockV3Bellatrix, ok := request.Object.(*validatorpb.SignRequest_BlockV3)
case *validatorpb.SignRequest_BlockBellatrix:
blockBellatrix, ok := request.Object.(*validatorpb.SignRequest_BlockBellatrix)
if !ok {
return nil, errors.New("failed to cast request object to block v3 bellatrix")
}
if blockV3Bellatrix == nil {
return nil, errors.New("invalid sign request: blockV3Bellatrix is nil")
if blockBellatrix == nil {
return nil, errors.New("invalid sign request: blockBellatrix is nil")
}
beaconBlock, err := blocks.NewBeaconBlock(blockV3Bellatrix.BlockV3)
beaconBlock, err := blocks.NewBeaconBlock(blockBellatrix.BlockBellatrix)
if err != nil {
return nil, err
}
@@ -317,7 +316,7 @@ func GetBlockV2BellatrixSignRequest(request *validatorpb.SignRequest, genesisVal
if err != nil {
return nil, err
}
return &BlockV2BellatrixSignRequest{
return &BlockBellatrixSignRequest{
Type: "BLOCK_V2",
ForkInfo: fork,
SigningRoot: request.SigningRoot,

View File

@@ -159,7 +159,7 @@ func TestGetBlockV2AltairSignRequest(t *testing.T) {
tests := []struct {
name string
args args
want *v1.BlockV2AltairSignRequest
want *v1.BlockAltairSignRequest
wantErr bool
}{
{
@@ -174,13 +174,13 @@ func TestGetBlockV2AltairSignRequest(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := v1.GetBlockV2AltairSignRequest(tt.args.request, tt.args.genesisValidatorsRoot)
got, err := v1.GetBlockAltairSignRequest(tt.args.request, tt.args.genesisValidatorsRoot)
if (err != nil) != tt.wantErr {
t.Errorf("GetBlockV2AltairSignRequest() error = %v, wantErr %v", err, tt.wantErr)
t.Errorf("GetBlockAltairSignRequest() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("GetBlockV2AltairSignRequest() got = %v, want %v", got, tt.want)
t.Errorf("GetBlockAltairSignRequest() got = %v, want %v", got, tt.want)
}
})
}
@@ -361,7 +361,7 @@ func TestGetVoluntaryExitSignRequest(t *testing.T) {
}
}
func TestGetBlockV3BellatrixSignRequest(t *testing.T) {
func TestGetBlockBellatrixSignRequest(t *testing.T) {
type args struct {
request *validatorpb.SignRequest
genesisValidatorsRoot []byte
@@ -369,7 +369,7 @@ func TestGetBlockV3BellatrixSignRequest(t *testing.T) {
tests := []struct {
name string
args args
want *v1.BlockV2BellatrixSignRequest
want *v1.BlockBellatrixSignRequest
wantErr bool
}{
{
@@ -401,13 +401,13 @@ func TestGetBlockV3BellatrixSignRequest(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := v1.GetBlockV2BellatrixSignRequest(tt.args.request, tt.args.genesisValidatorsRoot)
got, err := v1.GetBlockBellatrixSignRequest(tt.args.request, tt.args.genesisValidatorsRoot)
if (err != nil) != tt.wantErr {
t.Errorf("GetBlockV2BellatrixSignRequest() error = %v, wantErr %v", err, tt.wantErr)
t.Errorf("GetBlockBellatrixSignRequest() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("GetBlockV2AltairSignRequest() got = %v, want %v", got, tt.want)
t.Errorf("GetBlockAltairSignRequest() got = %v, want %v", got, tt.want)
}
})
}

View File

@@ -38,30 +38,22 @@ type BlockSignRequest struct {
Block *BeaconBlock `json:"block" validate:"required"`
}
// BlockV2AltairSignRequest is a request object for web3signer sign api.
type BlockV2AltairSignRequest struct {
// BlockAltairSignRequest is a request object for web3signer sign api.
type BlockAltairSignRequest struct {
Type string `json:"type" validate:"required"`
ForkInfo *ForkInfo `json:"fork_info" validate:"required"`
SigningRoot hexutil.Bytes `json:"signingRoot"`
BeaconBlock *BeaconBlockAltairBlockV2 `json:"beacon_block" validate:"required"`
}
// BlockV2BellatrixSignRequest is a request object for web3signer sign api for supporting Bellatrix fork.
type BlockV2BellatrixSignRequest struct {
// BlockBellatrixSignRequest is a request object for web3signer sign api for supporting Bellatrix fork.
type BlockBellatrixSignRequest struct {
Type string `json:"type" validate:"required"`
ForkInfo *ForkInfo `json:"fork_info" validate:"required"`
SigningRoot hexutil.Bytes `json:"signingRoot"`
BeaconBlock *BeaconBlockBellatrixBlockV2 `json:"beacon_block" validate:"required"`
}
// BlockV2SignRequest is a request object for web3signer sign api.
type BlockV2SignRequest struct {
Type string `json:"type" validate:"required"`
ForkInfo *ForkInfo `json:"fork_info" validate:"required"`
SigningRoot hexutil.Bytes `json:"signingRoot"`
BeaconBlock *BeaconBlockBlockV2 `json:"beacon_block" validate:"required"`
}
// DepositSignRequest Not currently supported by Prysm.
// DepositSignRequest is a request object for web3signer sign api.
@@ -255,7 +247,7 @@ type VoluntaryExit struct {
ValidatorIndex string `json:"validator_index"` /* uint64 */
}
// BeaconBlockAltairBlockV2 a sub property of BlockV2AltairSignRequest.
// BeaconBlockAltairBlockV2 a sub property of BlockAltairSignRequest.
type BeaconBlockAltairBlockV2 struct {
Version string `json:"version"`
Block *BeaconBlockAltair `json:"block"`
@@ -283,7 +275,7 @@ type BeaconBlockBodyAltair struct {
SyncAggregate *SyncAggregate `json:"sync_aggregate"`
}
// BeaconBlockBellatrixBlockV2 a field of BlockV2BellatrixSignRequest.
// BeaconBlockBellatrixBlockV2 a field of BlockBellatrixSignRequest.
type BeaconBlockBellatrixBlockV2 struct {
Version string `json:"version"`
BlockHeader *BeaconBlockHeader `json:"block_header"`