fix validator client (#11755)

* fix validator client

(cherry picked from commit deb138959a2ffcb89cd2e3eb8304477526f4a168)

* Use signed changes in middleware block

Co-authored-by: Potuz <potuz@prysmaticlabs.com>
This commit is contained in:
Radosław Kapka 2022-12-12 16:49:02 +01:00 committed by GitHub
parent fa01ee5eba
commit fb981d29e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 11 deletions

View File

@ -498,7 +498,7 @@ type BlindedBeaconBlockBodyCapellaJson struct {
VoluntaryExits []*SignedVoluntaryExitJson `json:"voluntary_exits"`
SyncAggregate *SyncAggregateJson `json:"sync_aggregate"`
ExecutionPayloadHeader *ExecutionPayloadHeaderCapellaJson `json:"execution_payload_header"`
BLSToExecutionChanges []*BLSToExecutionChangeJson `json:"bls_to_execution_changes"`
BLSToExecutionChanges []*SignedBLSToExecutionChangeJson `json:"bls_to_execution_changes"`
}
type ExecutionPayloadJson struct {
@ -623,6 +623,11 @@ type AttestationDataJson struct {
Target *CheckpointJson `json:"target"`
}
type SignedBLSToExecutionChangeJson struct {
Message *BLSToExecutionChangeJson `json:"message"`
Signature string `json:"signature" hex:"true"`
}
type BLSToExecutionChangeJson struct {
ValidatorIndex string `json:"validator_index"`
FromBLSPubkey string `json:"from_bls_pubkey" hex:"true"`

View File

@ -15,15 +15,19 @@ func jsonifyTransactions(transactions [][]byte) []string {
return jsonTransactions
}
func jsonifyBlsToExecutionChanges(blsToExecutionChanges []*ethpb.SignedBLSToExecutionChange) []*apimiddleware.BLSToExecutionChangeJson {
jsonBlsToExecutionChanges := make([]*apimiddleware.BLSToExecutionChangeJson, len(blsToExecutionChanges))
func jsonifyBlsToExecutionChanges(blsToExecutionChanges []*ethpb.SignedBLSToExecutionChange) []*apimiddleware.SignedBLSToExecutionChangeJson {
jsonBlsToExecutionChanges := make([]*apimiddleware.SignedBLSToExecutionChangeJson, len(blsToExecutionChanges))
for index, signedBlsToExecutionChange := range blsToExecutionChanges {
blsToExecutionChangeJson := &apimiddleware.BLSToExecutionChangeJson{
ValidatorIndex: uint64ToString(signedBlsToExecutionChange.Message.ValidatorIndex),
FromBLSPubkey: hexutil.Encode(signedBlsToExecutionChange.Message.FromBlsPubkey),
ToExecutionAddress: hexutil.Encode(signedBlsToExecutionChange.Message.ToExecutionAddress),
}
jsonBlsToExecutionChanges[index] = blsToExecutionChangeJson
signedJson := &apimiddleware.SignedBLSToExecutionChangeJson{
Message: blsToExecutionChangeJson,
Signature: hexutil.Encode(signedBlsToExecutionChange.Signature),
}
jsonBlsToExecutionChanges[index] = signedJson
}
return jsonBlsToExecutionChanges
}

View File

@ -31,6 +31,7 @@ func TestBeaconBlockJsonHelpers_JsonifyBlsToExecutionChanges(t *testing.T) {
FromBlsPubkey: []byte{2},
ToExecutionAddress: []byte{3},
},
Signature: []byte{7},
},
{
Message: &ethpb.BLSToExecutionChange{
@ -38,19 +39,26 @@ func TestBeaconBlockJsonHelpers_JsonifyBlsToExecutionChanges(t *testing.T) {
FromBlsPubkey: []byte{5},
ToExecutionAddress: []byte{6},
},
Signature: []byte{8},
},
}
expectedResult := []*apimiddleware.BLSToExecutionChangeJson{
expectedResult := []*apimiddleware.SignedBLSToExecutionChangeJson{
{
ValidatorIndex: "1",
FromBLSPubkey: hexutil.Encode([]byte{2}),
ToExecutionAddress: hexutil.Encode([]byte{3}),
Message: &apimiddleware.BLSToExecutionChangeJson{
ValidatorIndex: "1",
FromBLSPubkey: hexutil.Encode([]byte{2}),
ToExecutionAddress: hexutil.Encode([]byte{3}),
},
Signature: hexutil.Encode([]byte{7}),
},
{
ValidatorIndex: "4",
FromBLSPubkey: hexutil.Encode([]byte{5}),
ToExecutionAddress: hexutil.Encode([]byte{6}),
Message: &apimiddleware.BLSToExecutionChangeJson{
ValidatorIndex: "4",
FromBLSPubkey: hexutil.Encode([]byte{5}),
ToExecutionAddress: hexutil.Encode([]byte{6}),
},
Signature: hexutil.Encode([]byte{8}),
},
}