From 432011d309b76e87feb45f20cae33f5b7f562b22 Mon Sep 17 00:00:00 2001 From: avalonche Date: Tue, 16 Jan 2024 19:07:30 +1100 Subject: [PATCH] Clean up for Deneb flow --- server/service.go | 5 +- server/utils_test.go | 177 +++++++++++++++++++++++-------------------- 2 files changed, 98 insertions(+), 84 deletions(-) diff --git a/server/service.go b/server/service.go index 9efc4a87..897d67ba 100644 --- a/server/service.go +++ b/server/service.go @@ -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 } diff --git a/server/utils_test.go b/server/utils_test.go index 7cea3ca8..636eaa3c 100644 --- a/server/utils_test.go +++ b/server/utils_test.go @@ -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)) + }) + } }