fix phase0 block parsing on submitblock (#12857)

* adding fixes to address new changes in deneb

* removing logs

---------

Co-authored-by: Nishant Das <nishdas93@gmail.com>
This commit is contained in:
james-prysm 2023-09-06 20:49:18 -05:00 committed by GitHub
parent 4f48c551da
commit 41dff74e90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -62,8 +62,13 @@ func wrapValidatorIndicesArray(
return true, nil return true, nil
} }
type v1alpha1SignedPhase0Block struct {
Block *BeaconBlockJson `json:"block"` // tech debt on phase 0 called this block instead of "message"
Signature string `json:"signature" hex:"true"`
}
type phase0PublishBlockRequestJson struct { type phase0PublishBlockRequestJson struct {
Phase0Block *SignedBeaconBlockJson `json:"phase0_block"` Message *v1alpha1SignedPhase0Block `json:"phase0_block"`
} }
type altairPublishBlockRequestJson struct { type altairPublishBlockRequestJson struct {
@ -160,42 +165,40 @@ func setInitialPublishBlockPostRequest(endpoint *apimiddleware.Endpoint,
func preparePublishedBlock(endpoint *apimiddleware.Endpoint, _ http.ResponseWriter, _ *http.Request) apimiddleware.ErrorJson { func preparePublishedBlock(endpoint *apimiddleware.Endpoint, _ http.ResponseWriter, _ *http.Request) apimiddleware.ErrorJson {
if block, ok := endpoint.PostRequest.(*SignedBeaconBlockJson); ok { if block, ok := endpoint.PostRequest.(*SignedBeaconBlockJson); ok {
// Prepare post request that can be properly decoded on gRPC side. // Prepare post request that can be properly decoded on gRPC side.
actualPostReq := &phase0PublishBlockRequestJson{ endpoint.PostRequest = &phase0PublishBlockRequestJson{
Phase0Block: block, Message: &v1alpha1SignedPhase0Block{
Block: block.Message,
Signature: block.Signature,
},
} }
endpoint.PostRequest = actualPostReq
return nil return nil
} }
if block, ok := endpoint.PostRequest.(*SignedBeaconBlockAltairJson); ok { if block, ok := endpoint.PostRequest.(*SignedBeaconBlockAltairJson); ok {
// Prepare post request that can be properly decoded on gRPC side. // Prepare post request that can be properly decoded on gRPC side.
actualPostReq := &altairPublishBlockRequestJson{ endpoint.PostRequest = &altairPublishBlockRequestJson{
AltairBlock: block, AltairBlock: block,
} }
endpoint.PostRequest = actualPostReq
return nil return nil
} }
if block, ok := endpoint.PostRequest.(*SignedBeaconBlockBellatrixJson); ok { if block, ok := endpoint.PostRequest.(*SignedBeaconBlockBellatrixJson); ok {
// Prepare post request that can be properly decoded on gRPC side. // Prepare post request that can be properly decoded on gRPC side.
actualPostReq := &bellatrixPublishBlockRequestJson{ endpoint.PostRequest = &bellatrixPublishBlockRequestJson{
BellatrixBlock: block, BellatrixBlock: block,
} }
endpoint.PostRequest = actualPostReq
return nil return nil
} }
if block, ok := endpoint.PostRequest.(*SignedBeaconBlockCapellaJson); ok { if block, ok := endpoint.PostRequest.(*SignedBeaconBlockCapellaJson); ok {
// Prepare post request that can be properly decoded on gRPC side. // Prepare post request that can be properly decoded on gRPC side.
actualPostReq := &capellaPublishBlockRequestJson{ endpoint.PostRequest = &capellaPublishBlockRequestJson{
CapellaBlock: block, CapellaBlock: block,
} }
endpoint.PostRequest = actualPostReq
return nil return nil
} }
if block, ok := endpoint.PostRequest.(*SignedBeaconBlockContentsDenebJson); ok { if block, ok := endpoint.PostRequest.(*SignedBeaconBlockContentsDenebJson); ok {
// Prepare post request that can be properly decoded on gRPC side. // Prepare post request that can be properly decoded on gRPC side.
actualPostReq := &denebPublishBlockRequestJson{ endpoint.PostRequest = &denebPublishBlockRequestJson{
DenebContents: block, DenebContents: block,
} }
endpoint.PostRequest = actualPostReq
return nil return nil
} }
return apimiddleware.InternalServerError(errors.New("unsupported block type")) return apimiddleware.InternalServerError(errors.New("unsupported block type"))
@ -266,11 +269,12 @@ func setInitialPublishBlindedBlockPostRequest(endpoint *apimiddleware.Endpoint,
// (which was filled out previously in setInitialPublishBlockPostRequest). // (which was filled out previously in setInitialPublishBlockPostRequest).
func preparePublishedBlindedBlock(endpoint *apimiddleware.Endpoint, _ http.ResponseWriter, _ *http.Request) apimiddleware.ErrorJson { func preparePublishedBlindedBlock(endpoint *apimiddleware.Endpoint, _ http.ResponseWriter, _ *http.Request) apimiddleware.ErrorJson {
if block, ok := endpoint.PostRequest.(*SignedBeaconBlockJson); ok { if block, ok := endpoint.PostRequest.(*SignedBeaconBlockJson); ok {
// Prepare post request that can be properly decoded on gRPC side. endpoint.PostRequest = &phase0PublishBlockRequestJson{
actualPostReq := &phase0PublishBlockRequestJson{ Message: &v1alpha1SignedPhase0Block{
Phase0Block: block, Block: block.Message,
Signature: block.Signature,
},
} }
endpoint.PostRequest = actualPostReq
return nil return nil
} }
if block, ok := endpoint.PostRequest.(*SignedBeaconBlockAltairJson); ok { if block, ok := endpoint.PostRequest.(*SignedBeaconBlockAltairJson); ok {