Skip to content

Commit

Permalink
Clean up for Deneb flow
Browse files Browse the repository at this point in the history
  • Loading branch information
avalonche committed Jan 19, 2024
1 parent 4ff4d89 commit f297089
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 84 deletions.
5 changes: 4 additions & 1 deletion server/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,10 @@ func (m *BoostService) processDenebPayload(w http.ResponseWriter, req *http.Requ
// Ensure that blobs are valid and matches the request
if len(commitments) != len(blobs.Blobs) || len(commitments) != len(blobs.Commitments) || len(commitments) != len(blobs.Proofs) {
log.WithFields(logrus.Fields{
"requestBlobs": len(commitments),
"requestBlobCommitments": len(commitments),
"responseBlobs": len(blobs.Blobs),
"responseBlobCommitments": len(blobs.Commitments),
"responseBlobProofs": len(blobs.Proofs),
}).Error("block KZG commitment length does not equal responseBlobs length")
return
}
Expand Down
177 changes: 94 additions & 83 deletions server/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,99 +102,110 @@ func TestWeiBigIntToEthBigFloat(t *testing.T) {
}

func TestGetPayloadResponseIsEmpty(t *testing.T) {
t.Run("Non-empty capella payload response", func(t *testing.T) {
payload := &builderApi.VersionedSubmitBlindedBlockResponse{
Version: spec.DataVersionCapella,
Capella: &capella.ExecutionPayload{
BlockHash: phase0.Hash32{0x1},
},
}
require.False(t, getPayloadResponseIsEmpty(payload))
})

t.Run("Non-empty deneb payload response", func(t *testing.T) {
payload := &builderApi.VersionedSubmitBlindedBlockResponse{
Version: spec.DataVersionDeneb,
Deneb: &builderApiDeneb.ExecutionPayloadAndBlobsBundle{
ExecutionPayload: &deneb.ExecutionPayload{
testCases := []struct {
name string
payload *builderApi.VersionedSubmitBlindedBlockResponse
expected bool
}{
{
name: "Non-empty capella payload response",
payload: &builderApi.VersionedSubmitBlindedBlockResponse{
Version: spec.DataVersionCapella,
Capella: &capella.ExecutionPayload{
BlockHash: phase0.Hash32{0x1},
},
BlobsBundle: &builderApiDeneb.BlobsBundle{
Blobs: make([]deneb.Blob, 0),
Commitments: make([]deneb.KZGCommitment, 0),
Proofs: make([]deneb.KZGProof, 0),
},
expected: false,
},
{
name: "Non-empty deneb payload response",
payload: &builderApi.VersionedSubmitBlindedBlockResponse{
Version: spec.DataVersionDeneb,
Deneb: &builderApiDeneb.ExecutionPayloadAndBlobsBundle{
ExecutionPayload: &deneb.ExecutionPayload{
BlockHash: phase0.Hash32{0x1},
},
BlobsBundle: &builderApiDeneb.BlobsBundle{
Blobs: make([]deneb.Blob, 0),
Commitments: make([]deneb.KZGCommitment, 0),
Proofs: make([]deneb.KZGProof, 0),
},
},
},
}
require.False(t, getPayloadResponseIsEmpty(payload))
})

t.Run("Empty capella payload response", func(t *testing.T) {
payload := &builderApi.VersionedSubmitBlindedBlockResponse{
Version: spec.DataVersionCapella,
}
require.True(t, getPayloadResponseIsEmpty(payload))
})

t.Run("Nil block hash for capella payload response", func(t *testing.T) {
payload := &builderApi.VersionedSubmitBlindedBlockResponse{
Version: spec.DataVersionCapella,
Capella: &capella.ExecutionPayload{
BlockHash: nilHash,
expected: false,
},
{
name: "Empty capella payload response",
payload: &builderApi.VersionedSubmitBlindedBlockResponse{
Version: spec.DataVersionCapella,
},
}
require.True(t, getPayloadResponseIsEmpty(payload))
})

t.Run("Empty deneb payload response", func(t *testing.T) {
payload := &builderApi.VersionedSubmitBlindedBlockResponse{
Version: spec.DataVersionDeneb,
}
require.True(t, getPayloadResponseIsEmpty(payload))
})

t.Run("Empty deneb execution payload", func(t *testing.T) {
payload := &builderApi.VersionedSubmitBlindedBlockResponse{
Version: spec.DataVersionDeneb,
Deneb: &builderApiDeneb.ExecutionPayloadAndBlobsBundle{
BlobsBundle: &builderApiDeneb.BlobsBundle{
Blobs: make([]deneb.Blob, 0),
Commitments: make([]deneb.KZGCommitment, 0),
Proofs: make([]deneb.KZGProof, 0),
expected: true,
},
{
name: "Nil block hash for capella payload response",
payload: &builderApi.VersionedSubmitBlindedBlockResponse{
Version: spec.DataVersionCapella,
Capella: &capella.ExecutionPayload{
BlockHash: nilHash,
},
},
}
require.True(t, getPayloadResponseIsEmpty(payload))
})

t.Run("Empty deneb blobs bundle", func(t *testing.T) {
payload := &builderApi.VersionedSubmitBlindedBlockResponse{
Version: spec.DataVersionDeneb,
Deneb: &builderApiDeneb.ExecutionPayloadAndBlobsBundle{
ExecutionPayload: &deneb.ExecutionPayload{
BlockHash: phase0.Hash32{0x1},
expected: true,
},
{
name: "Empty deneb payload response",
payload: &builderApi.VersionedSubmitBlindedBlockResponse{
Version: spec.DataVersionDeneb,
},
expected: true,
},
{
name: "Empty deneb execution payload",
payload: &builderApi.VersionedSubmitBlindedBlockResponse{
Version: spec.DataVersionDeneb,
Deneb: &builderApiDeneb.ExecutionPayloadAndBlobsBundle{
BlobsBundle: &builderApiDeneb.BlobsBundle{
Blobs: make([]deneb.Blob, 0),
Commitments: make([]deneb.KZGCommitment, 0),
Proofs: make([]deneb.KZGProof, 0),
},
},
},
}
require.True(t, getPayloadResponseIsEmpty(payload))
})

t.Run("Nil block hash for deneb payload response", func(t *testing.T) {
payload := &builderApi.VersionedSubmitBlindedBlockResponse{
Version: spec.DataVersionDeneb,
Deneb: &builderApiDeneb.ExecutionPayloadAndBlobsBundle{
ExecutionPayload: &deneb.ExecutionPayload{
BlockHash: nilHash,
expected: true,
},
{
name: "Empty deneb blobs bundle",
payload: &builderApi.VersionedSubmitBlindedBlockResponse{
Deneb: &builderApiDeneb.ExecutionPayloadAndBlobsBundle{
ExecutionPayload: &deneb.ExecutionPayload{
BlockHash: phase0.Hash32{0x1},
},
},
},
}
require.True(t, getPayloadResponseIsEmpty(payload))
})
expected: true,
},
{
name: "Nil block hash for deneb payload response",
payload: &builderApi.VersionedSubmitBlindedBlockResponse{
Deneb: &builderApiDeneb.ExecutionPayloadAndBlobsBundle{
ExecutionPayload: &deneb.ExecutionPayload{
BlockHash: nilHash,
},
},
},
expected: true,
},
{
name: "Unsupported payload version",
payload: &builderApi.VersionedSubmitBlindedBlockResponse{
Version: spec.DataVersionBellatrix,
},
expected: true,
},
}

t.Run("Unsupported payload version", func(t *testing.T) {
payload := &builderApi.VersionedSubmitBlindedBlockResponse{
Version: spec.DataVersionBellatrix,
}
require.True(t, getPayloadResponseIsEmpty(payload))
})
for _, tt := range testCases {
t.Run(tt.name, func(t *testing.T) {
require.Equal(t, tt.expected, getPayloadResponseIsEmpty(tt.payload))
})
}
}

0 comments on commit f297089

Please sign in to comment.