Skip to content

Commit

Permalink
Merge branch 'master' into illia-malachyn/765-block-header-response
Browse files Browse the repository at this point in the history
  • Loading branch information
illia-malachyn authored Oct 21, 2024
2 parents d070f5e + aadf896 commit 9f84549
Show file tree
Hide file tree
Showing 14 changed files with 142 additions and 33 deletions.
83 changes: 77 additions & 6 deletions access/grpc/convert/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,24 +482,85 @@ 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(),
ReferenceBlockId: g.ReferenceBlockID.Bytes(),
Signature: g.Signature,
SignerIndices: g.SignerIndices,
}
}

func BlockSealToMessage(g flow.BlockSeal) *entities.BlockSeal {
return &entities.BlockSeal{
BlockId: g.BlockID.Bytes(),
ExecutionReceiptId: g.ExecutionReceiptID.Bytes(),
BlockId: g.BlockID.Bytes(),
ExecutionReceiptId: g.ExecutionReceiptID.Bytes(),
ExecutionReceiptSignatures: g.ExecutionReceiptSignatures,
ResultApprovalSignatures: g.ResultApprovalSignatures,
FinalState: g.FinalState,
ResultId: g.ResultId.Bytes(),
AggregatedApprovalSigs: AggregatedSignaturesToMessage(g.AggregatedApprovalSigs),
}
}

func AggregatedSignaturesToMessage(s []*flow.AggregatedSignature) []*entities.AggregatedSignature {
sigs := make([]*entities.AggregatedSignature, len(s))
for i, sig := range s {
sigs[i] = AggregatedSignatureToMessage(*sig)
}
return sigs
}

func AggregatedSignatureToMessage(sig flow.AggregatedSignature) *entities.AggregatedSignature {
signerIds := make([][]byte, len(sig.SignerIds))
for i, id := range sig.SignerIds {
signerIds[i] = id.Bytes()
}

return &entities.AggregatedSignature{
VerifierSignatures: sig.VerifierSignatures,
SignerIds: signerIds,
}
}

func MessageToAggregatedSignatures(m []*entities.AggregatedSignature) ([]*flow.AggregatedSignature, error) {
sigs := make([]*flow.AggregatedSignature, len(m))
for i, sig := range m {
convertedSig, err := MessageToAggregatedSignature(sig)
if err != nil {
return nil, err
}

sigs[i] = &convertedSig
}

return sigs, nil
}

func MessageToAggregatedSignature(m *entities.AggregatedSignature) (flow.AggregatedSignature, error) {
if m == nil {
return flow.AggregatedSignature{}, ErrEmptyMessage
}

ids := make([]flow.Identifier, len(m.SignerIds))
for i, id := range m.SignerIds {
ids[i] = flow.HashToID(id)
}

return flow.AggregatedSignature{
VerifierSignatures: m.GetVerifierSignatures(),
SignerIds: ids,
}, nil
}

func MessageToCollectionGuarantee(m *entities.CollectionGuarantee) (flow.CollectionGuarantee, error) {
if m == nil {
return flow.CollectionGuarantee{}, ErrEmptyMessage
}

return flow.CollectionGuarantee{
CollectionID: flow.HashToID(m.CollectionId),
CollectionID: flow.HashToID(m.CollectionId),
ReferenceBlockID: flow.HashToID(m.ReferenceBlockId),
Signature: m.Signature,
SignerIndices: m.SignerIndices,
}, nil
}

Expand All @@ -508,9 +569,19 @@ func MessageToBlockSeal(m *entities.BlockSeal) (flow.BlockSeal, error) {
return flow.BlockSeal{}, ErrEmptyMessage
}

sigs, err := MessageToAggregatedSignatures(m.GetAggregatedApprovalSigs())
if err != nil {
return flow.BlockSeal{}, err
}

return flow.BlockSeal{
BlockID: flow.BytesToID(m.BlockId),
ExecutionReceiptID: flow.BytesToID(m.ExecutionReceiptId),
BlockID: flow.BytesToID(m.BlockId),
ExecutionReceiptID: flow.BytesToID(m.ExecutionReceiptId),
ExecutionReceiptSignatures: m.GetExecutionReceiptSignatures(),
ResultApprovalSignatures: m.GetResultApprovalSignatures(),
FinalState: m.GetFinalState(),
ResultId: flow.BytesToID(m.GetResultId()),
AggregatedApprovalSigs: sigs,
}, nil
}

Expand Down
2 changes: 1 addition & 1 deletion access/http/convert/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}

Expand Down
16 changes: 14 additions & 2 deletions block.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@

package flow

import "time"
import (
"time"
)

// Block is a set of state mutations applied to the Flow blockchain.
type Block struct {
Expand Down Expand Up @@ -98,7 +100,17 @@ type BlockSeal struct {

// The ID of the execution receipt generated by the Verifier nodes; the work of verifying a
// block produces the same receipt among all verifying nodes
ExecutionReceiptID Identifier
ExecutionReceiptID Identifier
ExecutionReceiptSignatures [][]byte
ResultApprovalSignatures [][]byte
FinalState []byte
ResultId Identifier
AggregatedApprovalSigs []*AggregatedSignature
}

type AggregatedSignature struct {
VerifierSignatures [][]byte
SignerIds []Identifier
}

// BlockDigest holds lightweight block information which includes only block id, block height and block timestamp
Expand Down
5 changes: 4 additions & 1 deletion collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ 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
ReferenceBlockID Identifier
Signature []byte
SignerIndices []byte
}

type FullCollection struct {
Expand Down
2 changes: 1 addition & 1 deletion decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
// NOTE: always import Cadence's stdlib package,
// as it registers the type ID decoder for the Flow types,
// e.g. `flow.AccountCreated`
_ "github.com/onflow/cadence/runtime/stdlib"
_ "github.com/onflow/cadence/stdlib"
"github.com/onflow/flow/protobuf/go/flow/entities"
)

Expand Down
4 changes: 2 additions & 2 deletions decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ package flow_test
import (
"testing"

"github.com/onflow/cadence/runtime/common"
"github.com/onflow/cadence/runtime/stdlib"
"github.com/onflow/cadence/common"
"github.com/onflow/cadence/stdlib"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

Expand Down
2 changes: 1 addition & 1 deletion event.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"time"

"github.com/onflow/cadence"
"github.com/onflow/cadence/runtime/stdlib"
"github.com/onflow/cadence/stdlib"
"github.com/onflow/crypto/hash"

"github.com/onflow/flow-go-sdk/crypto"
Expand Down
2 changes: 1 addition & 1 deletion examples/examples.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import (
"github.com/onflow/cadence"
"github.com/onflow/flow-cli/flowkit/config/json"

"github.com/onflow/cadence/runtime/sema"
"github.com/onflow/cadence/sema"
)

const configPath = "./flow.json"
Expand Down
4 changes: 2 additions & 2 deletions examples/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ toolchain go1.22.4
replace github.com/onflow/flow-go-sdk => ../

require (
github.com/onflow/cadence v1.0.0
github.com/onflow/cadence v1.0.1-0.20241018173327-2e72919b18ac
github.com/onflow/flow-cli/flowkit v1.11.0
github.com/onflow/flow-go-sdk v0.41.17
github.com/spf13/afero v1.11.0
Expand Down Expand Up @@ -41,7 +41,7 @@ require (
github.com/logrusorgru/aurora/v4 v4.0.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/onflow/atree v0.8.0-rc.6 // indirect
github.com/onflow/atree v0.8.0 // indirect
github.com/onflow/crypto v0.25.1 // indirect
github.com/onflow/flow/protobuf/go/flow v0.4.7 // indirect
github.com/onflow/sdks v0.6.0-preview.1 // indirect
Expand Down
2 changes: 2 additions & 0 deletions examples/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ github.com/onflow/atree v0.6.1-0.20230711151834-86040b30171f/go.mod h1:xvP61FoOs
github.com/onflow/atree v0.6.1-0.20240429171449-cb486ceb1f9c/go.mod h1:xvP61FoOs95K7IYdIYRnNcYQGf4nbF/uuJ0tHf4DRuM=
github.com/onflow/atree v0.7.0-rc.2/go.mod h1:xvP61FoOs95K7IYdIYRnNcYQGf4nbF/uuJ0tHf4DRuM=
github.com/onflow/atree v0.8.0-rc.6/go.mod h1:yccR+LR7xc1Jdic0mrjocbHvUD7lnVvg8/Ct1AA5zBo=
github.com/onflow/atree v0.8.0/go.mod h1:yccR+LR7xc1Jdic0mrjocbHvUD7lnVvg8/Ct1AA5zBo=
github.com/onflow/cadence v0.42.7 h1:Qp9VYX901saO7wPwF/rwV4cMS+0mfWxnm9EqbYElYy4=
github.com/onflow/cadence v0.42.7/go.mod h1:raU8va8QRyTa/eUbhej4mbyW2ETePfSaywoo36MddgE=
github.com/onflow/cadence v1.0.0-M3/go.mod h1:odXGZZ/wGNA5mwT8bC9v8u8EXACHllB2ABSZK65TGL8=
Expand All @@ -118,6 +119,7 @@ github.com/onflow/cadence v1.0.0-preview.36/go.mod h1:jOwvPSSLTr9TvaKMs7KKiBYMmp
github.com/onflow/cadence v1.0.0-preview.38/go.mod h1:jOwvPSSLTr9TvaKMs7KKiBYMmpdpNNAFxBsjMlrqVD0=
github.com/onflow/cadence v1.0.0-preview.52/go.mod h1:7wvvecnAZtYOspLOS3Lh+FuAmMeSrXhAWiycC3kQ1UU=
github.com/onflow/cadence v1.0.0/go.mod h1:7wvvecnAZtYOspLOS3Lh+FuAmMeSrXhAWiycC3kQ1UU=
github.com/onflow/cadence v1.0.1-0.20241018173327-2e72919b18ac/go.mod h1:fJxxOAp1wnWDfOHT8GOc1ypsU0RR5E3z51AhG8Yf5jg=
github.com/onflow/crypto v0.25.0 h1:BeWbLsh3ZD13Ej+Uky6kg1PL1ZIVBDVX+2MVBNwqddg=
github.com/onflow/crypto v0.25.0/go.mod h1:C8FbaX0x8y+FxWjbkHy0Q4EASCDR9bSPWZqlpCLYyVI=
github.com/onflow/crypto v0.25.1/go.mod h1:C8FbaX0x8y+FxWjbkHy0Q4EASCDR9bSPWZqlpCLYyVI=
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/aws/aws-sdk-go-v2 v1.27.0
github.com/aws/aws-sdk-go-v2/config v1.27.15
github.com/aws/aws-sdk-go-v2/service/kms v1.31.0
github.com/onflow/cadence v1.0.0
github.com/onflow/cadence v1.1.0
github.com/onflow/crypto v0.25.1
github.com/onflow/flow/protobuf/go/flow v0.4.7
github.com/onflow/go-ethereum v1.13.4
Expand Down Expand Up @@ -59,7 +59,7 @@ require (
github.com/logrusorgru/aurora/v4 v4.0.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/onflow/atree v0.8.0-rc.6 // indirect
github.com/onflow/atree v0.8.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/rogpeppe/go-internal v1.10.0 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovk
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/onflow/atree v0.8.0-rc.6 h1:GWgaylK24b5ta2Hq+TvyOF7X5tZLiLzMMn7lEt59fsA=
github.com/onflow/atree v0.8.0-rc.6/go.mod h1:yccR+LR7xc1Jdic0mrjocbHvUD7lnVvg8/Ct1AA5zBo=
github.com/onflow/cadence v1.0.0 h1:bvT75F2LZJvDCBmmajAv7QLISK6Qp30FAKcSwqNNH+o=
github.com/onflow/cadence v1.0.0/go.mod h1:7wvvecnAZtYOspLOS3Lh+FuAmMeSrXhAWiycC3kQ1UU=
github.com/onflow/atree v0.8.0 h1:qg5c6J1gVDNObughpEeWm8oxqhPGdEyGrda121GM4u0=
github.com/onflow/atree v0.8.0/go.mod h1:yccR+LR7xc1Jdic0mrjocbHvUD7lnVvg8/Ct1AA5zBo=
github.com/onflow/cadence v1.1.0 h1:wPg86IX1kRv6DWjdETxKa4tv6A3iAwJVzzKAwaGdtDA=
github.com/onflow/cadence v1.1.0/go.mod h1:fJxxOAp1wnWDfOHT8GOc1ypsU0RR5E3z51AhG8Yf5jg=
github.com/onflow/crypto v0.25.1 h1:0txy2PKPMM873JbpxQNbJmuOJtD56bfs48RQfm0ts5A=
github.com/onflow/crypto v0.25.1/go.mod h1:C8FbaX0x8y+FxWjbkHy0Q4EASCDR9bSPWZqlpCLYyVI=
github.com/onflow/flow/protobuf/go/flow v0.4.7 h1:iP6DFx4wZ3ETORsyeqzHu7neFT3d1CXF6wdK+AOOjmc=
Expand Down
4 changes: 2 additions & 2 deletions templates/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ import (
"strings"

"github.com/onflow/cadence"
"github.com/onflow/cadence/common"
jsoncdc "github.com/onflow/cadence/encoding/json"
"github.com/onflow/cadence/runtime"
"github.com/onflow/cadence/runtime/common"
"github.com/onflow/cadence/runtime/sema"
"github.com/onflow/cadence/sema"
templates "github.com/onflow/sdks"

"github.com/onflow/flow-go-sdk/crypto"
Expand Down
37 changes: 29 additions & 8 deletions test/entities.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import (
"time"

"github.com/onflow/cadence"
"github.com/onflow/cadence/common"
"github.com/onflow/cadence/encoding/ccf"
jsoncdc "github.com/onflow/cadence/encoding/json"
"github.com/onflow/cadence/runtime/common"
"github.com/onflow/flow/protobuf/go/flow/entities"

"github.com/onflow/flow-go-sdk"
Expand Down Expand Up @@ -252,35 +252,56 @@ func (c *FullCollection) New() *flow.FullCollection {
}

type CollectionGuarantees struct {
ids *Identifiers
ids *Identifiers
bytes *Bytes
sigs *Signatures
}

type BlockSeals struct {
ids *Identifiers
ids *Identifiers
sigs *Signatures
bytes *Bytes
}

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(),
CollectionID: g.ids.New(),
ReferenceBlockID: g.ids.New(),
Signature: g.sigs.New()[0],
SignerIndices: g.bytes.New(),
}
}

func BlockSealGenerator() *BlockSeals {
return &BlockSeals{
ids: IdentifierGenerator(),
ids: IdentifierGenerator(),
sigs: SignaturesGenerator(),
bytes: BytesGenerator(),
}
}

func (g *BlockSeals) New() *flow.BlockSeal {
sigs := []*flow.AggregatedSignature{{
VerifierSignatures: g.sigs.New(),
SignerIds: []flow.Identifier{g.ids.New()},
}}

return &flow.BlockSeal{
BlockID: g.ids.New(),
ExecutionReceiptID: g.ids.New(),
BlockID: g.ids.New(),
ExecutionReceiptID: g.ids.New(),
ExecutionReceiptSignatures: g.sigs.New(),
ResultApprovalSignatures: g.sigs.New(),
FinalState: g.bytes.New(),
ResultId: g.ids.New(),
AggregatedApprovalSigs: sigs,
}
}

Expand Down

0 comments on commit 9f84549

Please sign in to comment.