Skip to content

Commit

Permalink
Add BlobAttestaionInfo data type and fetch API support (#1214)
Browse files Browse the repository at this point in the history
  • Loading branch information
jianoaix authored Feb 5, 2025
1 parent b4a1f21 commit f4f3ed7
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 1 deletion.
9 changes: 9 additions & 0 deletions disperser/common/v2/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,12 @@ type BlobMetadata struct {

*encoding.FragmentInfo
}

// BlobAttestationInfo describes the attestation information for a blob regarding to the batch
// that the blob belongs to and the validators' attestation to that batch.
//
// Note: for a blob, there will be at most one attested/signed batch that contains the blob.
type BlobAttestationInfo struct {
InclusionInfo *corev2.BlobInclusionInfo
Attestation *corev2.Attestation
}
39 changes: 39 additions & 0 deletions disperser/common/v2/blobstore/dynamo_metadata_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"strings"
"time"

"github.com/Layr-Labs/eigenda/api"
commondynamodb "github.com/Layr-Labs/eigenda/common/aws/dynamodb"
"github.com/Layr-Labs/eigenda/core"
corev2 "github.com/Layr-Labs/eigenda/core/v2"
Expand Down Expand Up @@ -976,6 +977,44 @@ func (s *BlobMetadataStore) GetBlobInclusionInfo(ctx context.Context, blobKey co
return info, nil
}

func (s *BlobMetadataStore) GetBlobAttestationInfo(ctx context.Context, blobKey corev2.BlobKey) (*v2.BlobAttestationInfo, error) {
blobInclusionInfos, err := s.GetBlobInclusionInfos(ctx, blobKey)
if err != nil {
s.logger.Error("failed to get blob inclusion info for blob", "err", err, "blobKey", blobKey.Hex())
return nil, api.NewErrorInternal(fmt.Sprintf("failed to get blob inclusion info: %s", err.Error()))
}

if len(blobInclusionInfos) == 0 {
s.logger.Error("no blob inclusion info found for blob", "blobKey", blobKey.Hex())
return nil, api.NewErrorInternal("no blob inclusion info found")
}

if len(blobInclusionInfos) > 1 {
s.logger.Warn("multiple inclusion info found for blob", "blobKey", blobKey.Hex())
}

for _, inclusionInfo := range blobInclusionInfos {
// get the signed batch from this inclusion info
batchHeaderHash, err := inclusionInfo.BatchHeader.Hash()
if err != nil {
s.logger.Error("failed to get batch header hash from blob inclusion info", "err", err, "blobKey", blobKey.Hex())
continue
}
_, attestation, err := s.GetSignedBatch(ctx, batchHeaderHash)
if err != nil {
s.logger.Error("failed to get signed batch", "err", err, "blobKey", blobKey.Hex())
continue
}

return &v2.BlobAttestationInfo{
InclusionInfo: inclusionInfo,
Attestation: attestation,
}, nil
}

return nil, fmt.Errorf("no attestation info found for blobkey: %s", blobKey.Hex())
}

func (s *BlobMetadataStore) GetBlobInclusionInfos(ctx context.Context, blobKey corev2.BlobKey) ([]*corev2.BlobInclusionInfo, error) {
items, err := s.dynamoDBClient.Query(ctx, s.tableName, "PK = :pk AND begins_with(SK, :prefix)", commondynamodb.ExpressionValues{
":pk": &types.AttributeValueMemberS{
Expand Down
78 changes: 77 additions & 1 deletion disperser/common/v2/blobstore/dynamo_metadata_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"errors"
"math"
"math/big"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -669,7 +670,7 @@ func TestBlobMetadataStoreGetAttestationByAttestedAtPagination(t *testing.T) {
// bucket.
startBucket, endBucket := blobstore.GetAttestedAtBucketIDRange(firstBatchTs-1, now)
if startBucket < endBucket {
now -= uint64(25 * time.Hour.Nanoseconds())
now -= uint64(time.Hour.Nanoseconds())
firstBatchTs = now - uint64(5*time.Minute.Nanoseconds())
}
startBucket, endBucket = blobstore.GetAttestedAtBucketIDRange(firstBatchTs-1, now)
Expand Down Expand Up @@ -1046,6 +1047,81 @@ func TestBlobMetadataStoreDispersals(t *testing.T) {
})
}

func TestBlobMetadataStoreBlobAttestationInfo(t *testing.T) {
ctx := context.Background()
blobKey := corev2.BlobKey{1, 1, 1}
batchHeader := &corev2.BatchHeader{
BatchRoot: [32]byte{1, 2, 3},
ReferenceBlockNumber: 1024,
}
bhh, err := batchHeader.Hash()
assert.NoError(t, err)
err = blobMetadataStore.PutBatchHeader(ctx, batchHeader)
assert.NoError(t, err)

inclusionInfo := &corev2.BlobInclusionInfo{
BatchHeader: batchHeader,
BlobKey: blobKey,
BlobIndex: 10,
InclusionProof: []byte("proof"),
}
err = blobMetadataStore.PutBlobInclusionInfo(ctx, inclusionInfo)
assert.NoError(t, err)

// Test 1: the batch isn't signed yet, so there is no attestation info
_, err = blobMetadataStore.GetBlobAttestationInfo(ctx, blobKey)
assert.Error(t, err)
assert.True(t, strings.Contains(err.Error(), "no attestation info found"))

keyPair, err := core.GenRandomBlsKeys()
assert.NoError(t, err)
apk := keyPair.GetPubKeyG2()
attestation := &corev2.Attestation{
BatchHeader: batchHeader,
AttestedAt: uint64(time.Now().UnixNano()),
NonSignerPubKeys: []*core.G1Point{
core.NewG1Point(big.NewInt(1), big.NewInt(2)),
core.NewG1Point(big.NewInt(3), big.NewInt(4)),
},
APKG2: apk,
QuorumAPKs: map[uint8]*core.G1Point{
0: core.NewG1Point(big.NewInt(5), big.NewInt(6)),
1: core.NewG1Point(big.NewInt(7), big.NewInt(8)),
},
Sigma: &core.Signature{
G1Point: core.NewG1Point(big.NewInt(9), big.NewInt(10)),
},
QuorumNumbers: []core.QuorumID{0, 1},
QuorumResults: map[uint8]uint8{
0: 100,
1: 80,
},
}
err = blobMetadataStore.PutAttestation(ctx, attestation)
assert.NoError(t, err)

// Test 2: the batch is signed, so we can fetch blob's attestation info
blobAttestationInfo, err := blobMetadataStore.GetBlobAttestationInfo(ctx, blobKey)
require.NoError(t, err)
assert.Equal(t, inclusionInfo, blobAttestationInfo.InclusionInfo)
assert.Equal(t, attestation, blobAttestationInfo.Attestation)

deleteItems(t, []commondynamodb.Key{
{
"PK": &types.AttributeValueMemberS{Value: "BatchHeader#" + hex.EncodeToString(bhh[:])},
"SK": &types.AttributeValueMemberS{Value: "BatchHeader"},
},
{
"PK": &types.AttributeValueMemberS{Value: "BatchHeader#" + hex.EncodeToString(bhh[:])},
"SK": &types.AttributeValueMemberS{Value: "Attestation"},
},
{
"PK": &types.AttributeValueMemberS{Value: "BlobKey#" + blobKey.Hex()},
"SK": &types.AttributeValueMemberS{Value: "BatchHeader#" + hex.EncodeToString(bhh[:])},
},
})
}

func TestBlobMetadataStoreInclusionInfo(t *testing.T) {
ctx := context.Background()
blobKey := corev2.BlobKey{1, 1, 1}
Expand Down

0 comments on commit f4f3ed7

Please sign in to comment.