From be6d7ccc8b6dcf1f8b683b1c47acf951718872ef Mon Sep 17 00:00:00 2001 From: Illia Malachyn Date: Tue, 15 Oct 2024 17:05:09 +0300 Subject: [PATCH 1/2] align collection guarantee with protobuf schema --- access/grpc/convert/convert.go | 12 ++++++++++-- access/http/convert/convert.go | 2 +- collection.go | 6 +++++- test/entities.go | 6 +++++- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/access/grpc/convert/convert.go b/access/grpc/convert/convert.go index 93a89b841..ac698f613 100644 --- a/access/grpc/convert/convert.go +++ b/access/grpc/convert/convert.go @@ -327,7 +327,11 @@ func MessageToFullCollection(m []*entities.Transaction) (flow.FullCollection, er func CollectionGuaranteeToMessage(g flow.CollectionGuarantee) *entities.CollectionGuarantee { return &entities.CollectionGuarantee{ - CollectionId: g.CollectionID.Bytes(), + CollectionId: g.CollectionID.Bytes(), + Signatures: g.Signatures, + ReferenceBlockId: g.ReferenceBlockID.Bytes(), + Signature: g.Signature, + SignerIndices: g.SignerIndices, } } @@ -344,7 +348,11 @@ func MessageToCollectionGuarantee(m *entities.CollectionGuarantee) (flow.Collect } return flow.CollectionGuarantee{ - CollectionID: flow.HashToID(m.CollectionId), + CollectionID: flow.HashToID(m.CollectionId), + Signatures: m.Signatures, + ReferenceBlockID: flow.HashToID(m.ReferenceBlockId), + Signature: m.Signature, + SignerIndices: m.SignerIndices, }, nil } diff --git a/access/http/convert/convert.go b/access/http/convert/convert.go index 2f36bf11f..df8640327 100644 --- a/access/http/convert/convert.go +++ b/access/http/convert/convert.go @@ -102,7 +102,7 @@ func ToCollectionGuarantees(guarantees []models.CollectionGuarantee) []*flow.Col for i, guarantee := range guarantees { flowGuarantees[i] = &flow.CollectionGuarantee{ - flow.HexToID(guarantee.CollectionId), + CollectionID: flow.HexToID(guarantee.CollectionId), } } diff --git a/collection.go b/collection.go index 3de5fff16..8325b748c 100644 --- a/collection.go +++ b/collection.go @@ -45,7 +45,11 @@ func (c Collection) Encode() []byte { // A CollectionGuarantee is an attestation signed by the nodes that have guaranteed a collection. type CollectionGuarantee struct { - CollectionID Identifier + CollectionID Identifier + Signatures [][]byte + ReferenceBlockID Identifier + Signature []byte + SignerIndices []byte } type FullCollection struct { diff --git a/test/entities.go b/test/entities.go index b9f607cf3..5108f3e8a 100644 --- a/test/entities.go +++ b/test/entities.go @@ -239,7 +239,11 @@ func CollectionGuaranteeGenerator() *CollectionGuarantees { func (g *CollectionGuarantees) New() *flow.CollectionGuarantee { return &flow.CollectionGuarantee{ - CollectionID: g.ids.New(), + CollectionID: g.ids.New(), + Signatures: [][]byte{[]byte("dummy")}, + ReferenceBlockID: g.ids.New(), + Signature: []byte("dummy"), + SignerIndices: []byte("dummy"), } } From 276409c90fa3a66a87fc544853cf068e16577543 Mon Sep 17 00:00:00 2001 From: Illia Malachyn Date: Thu, 17 Oct 2024 15:00:54 +0300 Subject: [PATCH 2/2] remove outdated field. use bytes and sig generator --- access/grpc/convert/convert.go | 2 -- collection.go | 1 - test/entities.go | 33 ++++++++++++++++++++++++++++----- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/access/grpc/convert/convert.go b/access/grpc/convert/convert.go index 7f132223f..591c87493 100644 --- a/access/grpc/convert/convert.go +++ b/access/grpc/convert/convert.go @@ -382,7 +382,6 @@ func MessageToFullCollection(m []*entities.Transaction) (flow.FullCollection, er func CollectionGuaranteeToMessage(g flow.CollectionGuarantee) *entities.CollectionGuarantee { return &entities.CollectionGuarantee{ CollectionId: g.CollectionID.Bytes(), - Signatures: g.Signatures, ReferenceBlockId: g.ReferenceBlockID.Bytes(), Signature: g.Signature, SignerIndices: g.SignerIndices, @@ -403,7 +402,6 @@ func MessageToCollectionGuarantee(m *entities.CollectionGuarantee) (flow.Collect return flow.CollectionGuarantee{ CollectionID: flow.HashToID(m.CollectionId), - Signatures: m.Signatures, ReferenceBlockID: flow.HashToID(m.ReferenceBlockId), Signature: m.Signature, SignerIndices: m.SignerIndices, diff --git a/collection.go b/collection.go index 8325b748c..14a5dfdc9 100644 --- a/collection.go +++ b/collection.go @@ -46,7 +46,6 @@ func (c Collection) Encode() []byte { // A CollectionGuarantee is an attestation signed by the nodes that have guaranteed a collection. type CollectionGuarantee struct { CollectionID Identifier - Signatures [][]byte ReferenceBlockID Identifier Signature []byte SignerIndices []byte diff --git a/test/entities.go b/test/entities.go index 5108f3e8a..0e9dcc3eb 100644 --- a/test/entities.go +++ b/test/entities.go @@ -19,6 +19,7 @@ package test import ( + "crypto/rand" "errors" "fmt" "strconv" @@ -224,7 +225,9 @@ func (c *FullCollection) New() *flow.FullCollection { } type CollectionGuarantees struct { - ids *Identifiers + ids *Identifiers + bytes *Bytes + sigs *Signatures } type BlockSeals struct { @@ -233,17 +236,18 @@ type BlockSeals struct { func CollectionGuaranteeGenerator() *CollectionGuarantees { return &CollectionGuarantees{ - ids: IdentifierGenerator(), + ids: IdentifierGenerator(), + bytes: BytesGenerator(), + sigs: SignaturesGenerator(), } } func (g *CollectionGuarantees) New() *flow.CollectionGuarantee { return &flow.CollectionGuarantee{ CollectionID: g.ids.New(), - Signatures: [][]byte{[]byte("dummy")}, ReferenceBlockID: g.ids.New(), - Signature: []byte("dummy"), - SignerIndices: []byte("dummy"), + Signature: g.sigs.New()[0], + SignerIndices: g.bytes.New(), } } @@ -575,3 +579,22 @@ func (g *LightTransactionResults) New() *flow.LightTransactionResult { ComputationUsed: uint64(42), } } + +type Bytes struct { + count int +} + +func BytesGenerator() *Bytes { + return &Bytes{ + count: 64, + } +} + +func (b *Bytes) New() []byte { + randomBytes := make([]byte, b.count) + _, err := rand.Read(randomBytes) + if err != nil { + panic("failed to generate random bytes") + } + return randomBytes +}