Prysm V4: Web3signer changes for capella (#12001)

* adding in changes for capella

* fixing metrics

* updating the web3signer version
This commit is contained in:
james-prysm
2023-02-24 00:21:39 -06:00
committed by GitHub
parent ae76240f83
commit 40589905bc
7 changed files with 144 additions and 38 deletions

View File

@@ -6,10 +6,10 @@ lighthouse_archive_name = "lighthouse-%s-x86_64-unknown-linux-gnu-portable.tar.g
def e2e_deps(): def e2e_deps():
http_archive( http_archive(
name = "web3signer", name = "web3signer",
urls = ["https://artifacts.consensys.net/public/web3signer/raw/names/web3signer.tar.gz/versions/22.8.1/web3signer-22.8.1.tar.gz"], urls = ["https://artifacts.consensys.net/public/web3signer/raw/names/web3signer.tar.gz/versions/23.2.1/web3signer-23.2.1.tar.gz"],
sha256 = "ec888222484c4d1b6203bd6d248890adf713f8bf47fb362fb36e8d47a98cb401", sha256 = "652f88bce1945f1c8ad3943b20c7c9adba730b2e4a5b9dec13a695c41f3e2ff1",
build_file = "@prysm//testing/endtoend:web3signer.BUILD", build_file = "@prysm//testing/endtoend:web3signer.BUILD",
strip_prefix = "web3signer-22.8.1", strip_prefix = "web3signer-23.2.1",
) )
http_archive( http_archive(

View File

@@ -163,7 +163,7 @@ func getSignRequestJson(ctx context.Context, validator *validator.Validate, requ
blockAltairSignRequestsTotal.Inc() blockAltairSignRequestsTotal.Inc()
return json.Marshal(blockv2AltairSignRequest) return json.Marshal(blockv2AltairSignRequest)
case *validatorpb.SignRequest_BlockBellatrix: case *validatorpb.SignRequest_BlockBellatrix:
blockv2BellatrixSignRequest, err := web3signerv1.GetBlockBellatrixSignRequest(request, genesisValidatorsRoot) blockv2BellatrixSignRequest, err := web3signerv1.GetBlockV2BlindedSignRequest(request, genesisValidatorsRoot)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -173,15 +173,35 @@ func getSignRequestJson(ctx context.Context, validator *validator.Validate, requ
blockBellatrixSignRequestsTotal.Inc() blockBellatrixSignRequestsTotal.Inc()
return json.Marshal(blockv2BellatrixSignRequest) return json.Marshal(blockv2BellatrixSignRequest)
case *validatorpb.SignRequest_BlindedBlockBellatrix: case *validatorpb.SignRequest_BlindedBlockBellatrix:
blindedBlockv2SignRequest, err := web3signerv1.GetBlockBellatrixSignRequest(request, genesisValidatorsRoot) blindedBlockv2SignRequest, err := web3signerv1.GetBlockV2BlindedSignRequest(request, genesisValidatorsRoot)
if err != nil { if err != nil {
return nil, err return nil, err
} }
if err = validator.StructCtx(ctx, blindedBlockv2SignRequest); err != nil { if err = validator.StructCtx(ctx, blindedBlockv2SignRequest); err != nil {
return nil, err return nil, err
} }
blindedblockBellatrixSignRequestsTotal.Inc() blindedBlockBellatrixSignRequestsTotal.Inc()
return json.Marshal(blindedBlockv2SignRequest) return json.Marshal(blindedBlockv2SignRequest)
case *validatorpb.SignRequest_BlockCapella:
blockv2CapellaSignRequest, err := web3signerv1.GetBlockV2BlindedSignRequest(request, genesisValidatorsRoot)
if err != nil {
return nil, err
}
if err = validator.StructCtx(ctx, blockv2CapellaSignRequest); err != nil {
return nil, err
}
blockCapellaSignRequestsTotal.Inc()
return json.Marshal(blockv2CapellaSignRequest)
case *validatorpb.SignRequest_BlindedBlockCapella:
blindedBlockv2CapellaSignRequest, err := web3signerv1.GetBlockV2BlindedSignRequest(request, genesisValidatorsRoot)
if err != nil {
return nil, err
}
if err = validator.StructCtx(ctx, blindedBlockv2CapellaSignRequest); err != nil {
return nil, err
}
blindedBlockCapellaSignRequestsTotal.Inc()
return json.Marshal(blindedBlockv2CapellaSignRequest)
// We do not support "DEPOSIT" type. // We do not support "DEPOSIT" type.
/* /*
case *validatorpb.: case *validatorpb.:

View File

@@ -38,10 +38,18 @@ var (
Name: "remote_web3signer_block_bellatrix_sign_requests_total", Name: "remote_web3signer_block_bellatrix_sign_requests_total",
Help: "Total number of block bellatrix sign requests", Help: "Total number of block bellatrix sign requests",
}) })
blindedblockBellatrixSignRequestsTotal = promauto.NewCounter(prometheus.CounterOpts{ blindedBlockBellatrixSignRequestsTotal = promauto.NewCounter(prometheus.CounterOpts{
Name: "remote_web3signer_blinded_block_bellatrix_sign_requests_total", Name: "remote_web3signer_blinded_block_bellatrix_sign_requests_total",
Help: "Total number of blinded block bellatrix sign requests", Help: "Total number of blinded block bellatrix sign requests",
}) })
blockCapellaSignRequestsTotal = promauto.NewCounter(prometheus.CounterOpts{
Name: "remote_web3signer_block_capella_sign_requests_total",
Help: "Total number of block capella sign requests",
})
blindedBlockCapellaSignRequestsTotal = promauto.NewCounter(prometheus.CounterOpts{
Name: "remote_web3signer_blinded_block_capella_sign_requests_total",
Help: "Total number of block capella sign requests",
})
randaoRevealSignRequestsTotal = promauto.NewCounter(prometheus.CounterOpts{ randaoRevealSignRequestsTotal = promauto.NewCounter(prometheus.CounterOpts{
Name: "remote_web3signer_randao_reveal_sign_requests_total", Name: "remote_web3signer_randao_reveal_sign_requests_total",
Help: "Total number of randao reveal sign requests", Help: "Total number of randao reveal sign requests",

View File

@@ -345,6 +345,24 @@ func GetMockSignRequest(t string) *validatorpb.SignRequest {
BlindedBlockBellatrix: util.HydrateBlindedBeaconBlockBellatrix(&eth.BlindedBeaconBlockBellatrix{}), BlindedBlockBellatrix: util.HydrateBlindedBeaconBlockBellatrix(&eth.BlindedBeaconBlockBellatrix{}),
}, },
} }
case "BLOCK_V2_CAPELLA":
return &validatorpb.SignRequest{
PublicKey: make([]byte, fieldparams.BLSPubkeyLength),
SigningRoot: make([]byte, fieldparams.RootLength),
SignatureDomain: make([]byte, 4),
Object: &validatorpb.SignRequest_BlockCapella{
BlockCapella: util.HydrateBeaconBlockCapella(&eth.BeaconBlockCapella{}),
},
}
case "BLOCK_V2_BLINDED_CAPELLA":
return &validatorpb.SignRequest{
PublicKey: make([]byte, fieldparams.BLSPubkeyLength),
SigningRoot: make([]byte, fieldparams.RootLength),
SignatureDomain: make([]byte, 4),
Object: &validatorpb.SignRequest_BlindedBlockCapella{
BlindedBlockCapella: util.HydrateBlindedBeaconBlockCapella(&eth.BlindedBeaconBlockCapella{}),
},
}
case "RANDAO_REVEAL": case "RANDAO_REVEAL":
return &validatorpb.SignRequest{ return &validatorpb.SignRequest{
PublicKey: make([]byte, fieldparams.BLSPubkeyLength), PublicKey: make([]byte, fieldparams.BLSPubkeyLength),
@@ -495,13 +513,13 @@ func MockBlockV2AltairSignRequest() *v1.BlockAltairSignRequest {
} }
} }
func MockBlockV2BellatrixSignRequest(bodyRoot []byte) *v1.BlockBellatrixSignRequest { func MockBlockV2BlindedSignRequest(bodyRoot []byte, version string) *v1.BlockV2BlindedSignRequest {
return &v1.BlockBellatrixSignRequest{ return &v1.BlockV2BlindedSignRequest{
Type: "BLOCK_V2", Type: "BLOCK_V2",
ForkInfo: MockForkInfo(), ForkInfo: MockForkInfo(),
SigningRoot: make([]byte, fieldparams.RootLength), SigningRoot: make([]byte, fieldparams.RootLength),
BeaconBlock: &v1.BeaconBlockBellatrixBlockV2{ BeaconBlock: &v1.BeaconBlockV2Blinded{
Version: "BELLATRIX", Version: version,
BlockHeader: &v1.BeaconBlockHeader{ BlockHeader: &v1.BeaconBlockHeader{
Slot: "0", Slot: "0",
ProposerIndex: "0", ProposerIndex: "0",

View File

@@ -271,20 +271,23 @@ func GetSyncCommitteeContributionAndProofSignRequest(request *validatorpb.SignRe
}, nil }, nil
} }
// GetBlockBellatrixSignRequest maps the request for signing type BLOCK_V2_BELLATRIX. // GetBlockV2BlindedSignRequest maps the request for signing types
func GetBlockBellatrixSignRequest(request *validatorpb.SignRequest, genesisValidatorsRoot []byte) (*BlockBellatrixSignRequest, error) { // Supports Bellatrix and Capella
func GetBlockV2BlindedSignRequest(request *validatorpb.SignRequest, genesisValidatorsRoot []byte) (*BlockV2BlindedSignRequest, error) {
if request == nil { if request == nil {
return nil, errors.New("nil sign request provided") return nil, errors.New("nil sign request provided")
} }
var b interfaces.ReadOnlyBeaconBlock var b interfaces.ReadOnlyBeaconBlock
var version string
switch request.Object.(type) { switch request.Object.(type) {
case *validatorpb.SignRequest_BlindedBlockBellatrix: case *validatorpb.SignRequest_BlindedBlockBellatrix:
version = "BELLATRIX"
blindedBlockBellatrix, ok := request.Object.(*validatorpb.SignRequest_BlindedBlockBellatrix) blindedBlockBellatrix, ok := request.Object.(*validatorpb.SignRequest_BlindedBlockBellatrix)
if !ok { if !ok {
return nil, errors.New("failed to cast request object to blinded block bellatrix") return nil, errors.New("failed to cast request object to blinded block bellatrix")
} }
if blindedBlockBellatrix == nil { if blindedBlockBellatrix == nil {
return nil, errors.New("invalid sign request - blindedBlockBellatrix is nil") return nil, errors.New("invalid sign request - blinded bellatrix block is nil")
} }
beaconBlock, err := blocks.NewBeaconBlock(blindedBlockBellatrix.BlindedBlockBellatrix) beaconBlock, err := blocks.NewBeaconBlock(blindedBlockBellatrix.BlindedBlockBellatrix)
if err != nil { if err != nil {
@@ -292,19 +295,48 @@ func GetBlockBellatrixSignRequest(request *validatorpb.SignRequest, genesisValid
} }
b = beaconBlock b = beaconBlock
case *validatorpb.SignRequest_BlockBellatrix: case *validatorpb.SignRequest_BlockBellatrix:
version = "BELLATRIX"
blockBellatrix, ok := request.Object.(*validatorpb.SignRequest_BlockBellatrix) blockBellatrix, ok := request.Object.(*validatorpb.SignRequest_BlockBellatrix)
if !ok { if !ok {
return nil, errors.New("failed to cast request object to block v3 bellatrix") return nil, errors.New("failed to cast request object to bellatrix block")
} }
if blockBellatrix == nil { if blockBellatrix == nil {
return nil, errors.New("invalid sign request: blockBellatrix is nil") return nil, errors.New("invalid sign request: bellatrix block is nil")
} }
beaconBlock, err := blocks.NewBeaconBlock(blockBellatrix.BlockBellatrix) beaconBlock, err := blocks.NewBeaconBlock(blockBellatrix.BlockBellatrix)
if err != nil { if err != nil {
return nil, err return nil, err
} }
b = beaconBlock b = beaconBlock
case *validatorpb.SignRequest_BlockCapella:
version = "CAPELLA"
blockCapella, ok := request.Object.(*validatorpb.SignRequest_BlockCapella)
if !ok {
return nil, errors.New("failed to cast request object to capella block")
}
if blockCapella == nil {
return nil, errors.New("invalid sign request: capella block is nil")
}
beaconBlock, err := blocks.NewBeaconBlock(blockCapella.BlockCapella)
if err != nil {
return nil, err
}
b = beaconBlock
case *validatorpb.SignRequest_BlindedBlockCapella:
version = "CAPELLA"
blindedBlockCapella, ok := request.Object.(*validatorpb.SignRequest_BlindedBlockCapella)
if !ok {
return nil, errors.New("failed to cast request object to blinded capella block")
}
if blindedBlockCapella == nil {
return nil, errors.New("invalid sign request: blinded capella block is nil")
}
beaconBlock, err := blocks.NewBeaconBlock(blindedBlockCapella.BlindedBlockCapella)
if err != nil {
return nil, err
}
b = beaconBlock
default: default:
return nil, errors.New("invalid sign request - invalid object type") return nil, errors.New("invalid sign request - invalid object type")
} }
@@ -316,12 +348,12 @@ func GetBlockBellatrixSignRequest(request *validatorpb.SignRequest, genesisValid
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &BlockBellatrixSignRequest{ return &BlockV2BlindedSignRequest{
Type: "BLOCK_V2", Type: "BLOCK_V2",
ForkInfo: fork, ForkInfo: fork,
SigningRoot: request.SigningRoot, SigningRoot: request.SigningRoot,
BeaconBlock: &BeaconBlockBellatrixBlockV2{ BeaconBlock: &BeaconBlockV2Blinded{
Version: "BELLATRIX", Version: version,
BlockHeader: &BeaconBlockHeader{ BlockHeader: &BeaconBlockHeader{
Slot: fmt.Sprint(beaconBlockHeader.Slot), Slot: fmt.Sprint(beaconBlockHeader.Slot),
ProposerIndex: fmt.Sprint(beaconBlockHeader.ProposerIndex), ProposerIndex: fmt.Sprint(beaconBlockHeader.ProposerIndex),

View File

@@ -361,7 +361,7 @@ func TestGetVoluntaryExitSignRequest(t *testing.T) {
} }
} }
func TestGetBlockBellatrixSignRequest(t *testing.T) { func TestGetBlockV2BlindedSignRequest(t *testing.T) {
type args struct { type args struct {
request *validatorpb.SignRequest request *validatorpb.SignRequest
genesisValidatorsRoot []byte genesisValidatorsRoot []byte
@@ -369,45 +369,71 @@ func TestGetBlockBellatrixSignRequest(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
args args args args
want *v1.BlockBellatrixSignRequest want *v1.BlockV2BlindedSignRequest
wantErr bool wantErr bool
}{ }{
{ {
name: "Happy Path Test non blinded", name: "Happy Path Test non blinded Bellatrix",
args: args{ args: args{
request: mock.GetMockSignRequest("BLOCK_V2_BELLATRIX"), request: mock.GetMockSignRequest("BLOCK_V2_BELLATRIX"),
genesisValidatorsRoot: make([]byte, fieldparams.RootLength), genesisValidatorsRoot: make([]byte, fieldparams.RootLength),
}, },
want: mock.MockBlockV2BellatrixSignRequest(func(t *testing.T) []byte { want: mock.MockBlockV2BlindedSignRequest(func(t *testing.T) []byte {
bytevalue, err := hexutil.Decode("0xcd7c49966ebe72b1214e6d4733adf6bf06935c5fbc3b3ad08e84e3085428b82f") bytevalue, err := hexutil.Decode("0xcd7c49966ebe72b1214e6d4733adf6bf06935c5fbc3b3ad08e84e3085428b82f")
require.NoError(t, err) require.NoError(t, err)
return bytevalue return bytevalue
}(t)), }(t), "BELLATRIX"),
wantErr: false, wantErr: false,
}, },
{ {
name: "Happy Path Test blinded", name: "Happy Path Test blinded Bellatrix",
args: args{ args: args{
request: mock.GetMockSignRequest("BLOCK_V2_BLINDED_BELLATRIX"), request: mock.GetMockSignRequest("BLOCK_V2_BLINDED_BELLATRIX"),
genesisValidatorsRoot: make([]byte, fieldparams.RootLength), genesisValidatorsRoot: make([]byte, fieldparams.RootLength),
}, },
want: mock.MockBlockV2BellatrixSignRequest(func(t *testing.T) []byte { want: mock.MockBlockV2BlindedSignRequest(func(t *testing.T) []byte {
bytevalue, err := hexutil.Decode("0xbabb9c2d10dd3f16dc50e31fd6eb270c9c5e95a6dcb5a1eb34389ef28194285b") bytevalue, err := hexutil.Decode("0xbabb9c2d10dd3f16dc50e31fd6eb270c9c5e95a6dcb5a1eb34389ef28194285b")
require.NoError(t, err) require.NoError(t, err)
return bytevalue return bytevalue
}(t)), }(t), "BELLATRIX"),
wantErr: false,
},
{
name: "Happy Path Test non blinded Capella",
args: args{
request: mock.GetMockSignRequest("BLOCK_V2_CAPELLA"),
genesisValidatorsRoot: make([]byte, fieldparams.RootLength),
},
want: mock.MockBlockV2BlindedSignRequest(func(t *testing.T) []byte {
bytevalue, err := hexutil.Decode("0x74b4bb048d39c75f175fbb2311062eb9867d79b712907f39544fcaf2d7e1b433")
require.NoError(t, err)
return bytevalue
}(t), "CAPELLA"),
wantErr: false,
},
{
name: "Happy Path Test blinded Capella",
args: args{
request: mock.GetMockSignRequest("BLOCK_V2_BLINDED_CAPELLA"),
genesisValidatorsRoot: make([]byte, fieldparams.RootLength),
},
want: mock.MockBlockV2BlindedSignRequest(func(t *testing.T) []byte {
bytevalue, err := hexutil.Decode("0x54797f27f45a91d2cf4d73e509c62e464d648ec34e07ddba946adee742039e76")
require.NoError(t, err)
return bytevalue
}(t), "CAPELLA"),
wantErr: false, wantErr: false,
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
got, err := v1.GetBlockBellatrixSignRequest(tt.args.request, tt.args.genesisValidatorsRoot) got, err := v1.GetBlockV2BlindedSignRequest(tt.args.request, tt.args.genesisValidatorsRoot)
if (err != nil) != tt.wantErr { if (err != nil) != tt.wantErr {
t.Errorf("GetBlockBellatrixSignRequest() error = %v, wantErr %v", err, tt.wantErr) t.Errorf("GetBlockV2BlindedSignRequest() error = %v, wantErr %v", err, tt.wantErr)
return return
} }
if !reflect.DeepEqual(got, tt.want) { if !reflect.DeepEqual(got, tt.want) {
t.Errorf("GetBlockAltairSignRequest() got = %v, want %v", got, tt.want) t.Errorf("GetBlockV2BlindedSignRequest() got = %v, want %v", got, tt.want)
} }
}) })
} }

View File

@@ -46,12 +46,13 @@ type BlockAltairSignRequest struct {
BeaconBlock *BeaconBlockAltairBlockV2 `json:"beacon_block" validate:"required"` BeaconBlock *BeaconBlockAltairBlockV2 `json:"beacon_block" validate:"required"`
} }
// BlockBellatrixSignRequest is a request object for web3signer sign api for supporting Bellatrix fork. // BlockV2BlindedSignRequest is a request object for web3signer sign api
type BlockBellatrixSignRequest struct { // Supports Bellatrix(merge) and Capella
Type string `json:"type" validate:"required"` type BlockV2BlindedSignRequest struct {
ForkInfo *ForkInfo `json:"fork_info" validate:"required"` Type string `json:"type" validate:"required"`
SigningRoot hexutil.Bytes `json:"signingRoot"` ForkInfo *ForkInfo `json:"fork_info" validate:"required"`
BeaconBlock *BeaconBlockBellatrixBlockV2 `json:"beacon_block" validate:"required"` SigningRoot hexutil.Bytes `json:"signingRoot"`
BeaconBlock *BeaconBlockV2Blinded `json:"beacon_block" validate:"required"`
} }
// DepositSignRequest Not currently supported by Prysm. // DepositSignRequest Not currently supported by Prysm.
@@ -275,8 +276,9 @@ type BeaconBlockBodyAltair struct {
SyncAggregate *SyncAggregate `json:"sync_aggregate"` SyncAggregate *SyncAggregate `json:"sync_aggregate"`
} }
// BeaconBlockBellatrixBlockV2 a field of BlockBellatrixSignRequest. // BeaconBlockV2Blinded a field of BlockV2BlindedSignRequest.
type BeaconBlockBellatrixBlockV2 struct { // Supports Bellatrix(merge) and Capella
type BeaconBlockV2Blinded struct {
Version string `json:"version" enum:"true"` Version string `json:"version" enum:"true"`
BlockHeader *BeaconBlockHeader `json:"block_header"` BlockHeader *BeaconBlockHeader `json:"block_header"`
} }