From 089b5387b9a1e58301eefccf0ca1f3c845d16239 Mon Sep 17 00:00:00 2001 From: Illia Malachyn Date: Tue, 22 Oct 2024 16:41:27 +0300 Subject: [PATCH 1/3] timeout certificate can be nil --- access/grpc/convert/convert.go | 12 +++++------- examples/go.mod | 2 +- examples/go.sum | 1 + 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/access/grpc/convert/convert.go b/access/grpc/convert/convert.go index ea8a1eaa6..63d4dc63a 100644 --- a/access/grpc/convert/convert.go +++ b/access/grpc/convert/convert.go @@ -268,10 +268,7 @@ func MessageToBlockHeader(m *entities.BlockHeader) (flow.BlockHeader, error) { timestamp = m.GetTimestamp().AsTime() } - tc, err := MessageToTimeoutCertificate(m.GetLastViewTc()) - if err != nil { - return flow.BlockHeader{}, err - } + timeoutCertificate, _ := MessageToTimeoutCertificate(m.GetLastViewTc()) return flow.BlockHeader{ ID: flow.HashToID(m.GetId()), @@ -285,19 +282,20 @@ func MessageToBlockHeader(m *entities.BlockHeader) (flow.BlockHeader, error) { ProposerSigData: m.GetProposerSigData(), ChainID: flow.HashToID([]byte(m.GetChainId())), ParentVoterIndices: m.GetParentVoterIndices(), - LastViewTimeoutCertificate: tc, + LastViewTimeoutCertificate: timeoutCertificate, ParentView: m.GetParentView(), }, nil } func MessageToTimeoutCertificate(m *entities.TimeoutCertificate) (flow.TimeoutCertificate, error) { if m == nil { - return flow.TimeoutCertificate{}, ErrEmptyMessage + // timeout certificate can be nil + return flow.TimeoutCertificate{}, nil } qc, err := MessageToQuorumCertificate(m.GetHighestQc()) if err != nil { - return flow.TimeoutCertificate{}, err + return flow.TimeoutCertificate{}, fmt.Errorf("error converting quorum certificate: %w", err) } return flow.TimeoutCertificate{ diff --git a/examples/go.mod b/examples/go.mod index c58c5e374..25d222804 100644 --- a/examples/go.mod +++ b/examples/go.mod @@ -7,7 +7,7 @@ toolchain go1.22.4 replace github.com/onflow/flow-go-sdk => ../ require ( - github.com/onflow/cadence v1.0.1-0.20241018173327-2e72919b18ac + github.com/onflow/cadence v1.2.1 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 diff --git a/examples/go.sum b/examples/go.sum index 6ef27de99..e80f1bdfe 100644 --- a/examples/go.sum +++ b/examples/go.sum @@ -120,6 +120,7 @@ github.com/onflow/cadence v1.0.0-preview.38/go.mod h1:jOwvPSSLTr9TvaKMs7KKiBYMmp 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/cadence v1.2.1/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= From 7435d56394083dcd330ed39d0c9a13d76374c108 Mon Sep 17 00:00:00 2001 From: Illia Malachyn Date: Tue, 22 Oct 2024 16:48:15 +0300 Subject: [PATCH 2/3] handle error --- access/grpc/convert/convert.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/access/grpc/convert/convert.go b/access/grpc/convert/convert.go index 63d4dc63a..7b94ab871 100644 --- a/access/grpc/convert/convert.go +++ b/access/grpc/convert/convert.go @@ -268,7 +268,10 @@ func MessageToBlockHeader(m *entities.BlockHeader) (flow.BlockHeader, error) { timestamp = m.GetTimestamp().AsTime() } - timeoutCertificate, _ := MessageToTimeoutCertificate(m.GetLastViewTc()) + timeoutCertificate, err := MessageToTimeoutCertificate(m.GetLastViewTc()) + if err != nil { + return flow.BlockHeader{}, fmt.Errorf("error converting timeout certificate: %w", err) + } return flow.BlockHeader{ ID: flow.HashToID(m.GetId()), From 1221b62145440b8ae53747ee30b4ed4a338dbb6c Mon Sep 17 00:00:00 2001 From: Illia Malachyn Date: Tue, 22 Oct 2024 17:26:29 +0300 Subject: [PATCH 3/3] add context for error --- access/grpc/convert/convert.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/access/grpc/convert/convert.go b/access/grpc/convert/convert.go index 7b94ab871..b93003231 100644 --- a/access/grpc/convert/convert.go +++ b/access/grpc/convert/convert.go @@ -327,7 +327,7 @@ func TimeoutCertificateToMessage(tc flow.TimeoutCertificate) (*entities.TimeoutC func MessageToQuorumCertificate(m *entities.QuorumCertificate) (flow.QuorumCertificate, error) { if m == nil { - return flow.QuorumCertificate{}, ErrEmptyMessage + return flow.QuorumCertificate{}, fmt.Errorf("quourum certificate is empty: %w", ErrEmptyMessage) } return flow.QuorumCertificate{