From 707f52b00bda58a3eba295b388bc981710d3e736 Mon Sep 17 00:00:00 2001 From: Peter Argue <89119817+peterargue@users.noreply.github.com> Date: Wed, 6 Sep 2023 12:35:01 -0700 Subject: [PATCH 1/4] [Access] Add spork and node root block heights to GetNodeVersionInfo --- access/api.go | 10 +- access/handler.go | 10 +- engine/access/access_test.go | 1 + .../integration_unsecure_grpc_server_test.go | 5 + engine/access/rest_api_test.go | 6 ++ engine/access/rpc/backend/backend.go | 37 +++++-- engine/access/rpc/backend/backend_test.go | 98 ++++++++++++++++++- engine/access/rpc/rate_limit_test.go | 6 ++ engine/access/secure_grpcr_test.go | 6 ++ go.mod | 2 +- go.sum | 4 +- insecure/go.mod | 2 +- insecure/go.sum | 4 +- integration/go.mod | 2 +- integration/go.sum | 4 +- 15 files changed, 166 insertions(+), 31 deletions(-) diff --git a/access/api.go b/access/api.go index 4188c04c1c4..933dbe3cd05 100644 --- a/access/api.go +++ b/access/api.go @@ -107,8 +107,10 @@ type NetworkParameters struct { // NodeVersionInfo contains information about node, such as semver, commit, sporkID, protocolVersion, etc type NodeVersionInfo struct { - Semver string - Commit string - SporkId flow.Identifier - ProtocolVersion uint64 + Semver string + Commit string + SporkId flow.Identifier + ProtocolVersion uint64 + SporkRootBlockHeight uint64 + NodeRootBlockHeight uint64 } diff --git a/access/handler.go b/access/handler.go index 11e47dd3521..80f7a96fdf3 100644 --- a/access/handler.go +++ b/access/handler.go @@ -65,10 +65,12 @@ func (h *Handler) GetNodeVersionInfo( return &access.GetNodeVersionInfoResponse{ Info: &entities.NodeVersionInfo{ - Semver: nodeVersionInfo.Semver, - Commit: nodeVersionInfo.Commit, - SporkId: nodeVersionInfo.SporkId[:], - ProtocolVersion: nodeVersionInfo.ProtocolVersion, + Semver: nodeVersionInfo.Semver, + Commit: nodeVersionInfo.Commit, + SporkId: nodeVersionInfo.SporkId[:], + ProtocolVersion: nodeVersionInfo.ProtocolVersion, + SporkRootBlockHeight: nodeVersionInfo.SporkRootBlockHeight, + NodeRootBlockHeight: nodeVersionInfo.NodeRootBlockHeight, }, }, nil } diff --git a/engine/access/access_test.go b/engine/access/access_test.go index ee6317cebef..592b33dbf3d 100644 --- a/engine/access/access_test.go +++ b/engine/access/access_test.go @@ -109,6 +109,7 @@ func (suite *Suite) SetupTest() { suite.params = new(protocol.Params) suite.params.On("FinalizedRoot").Return(suite.rootBlock, nil) suite.params.On("SporkRootBlockHeight").Return(suite.rootBlock.Height, nil) + suite.params.On("SealedRoot").Return(suite.rootBlock, nil) suite.state.On("Params").Return(suite.params).Maybe() suite.collClient = new(accessmock.AccessAPIClient) suite.execClient = new(accessmock.ExecutionAPIClient) diff --git a/engine/access/integration_unsecure_grpc_server_test.go b/engine/access/integration_unsecure_grpc_server_test.go index 1703603d11e..058fcae8df2 100644 --- a/engine/access/integration_unsecure_grpc_server_test.go +++ b/engine/access/integration_unsecure_grpc_server_test.go @@ -88,10 +88,12 @@ func (suite *SameGRPCPortTestSuite) SetupTest() { suite.net = new(network.Network) suite.state = new(protocol.State) suite.snapshot = new(protocol.Snapshot) + params := new(protocol.Params) suite.epochQuery = new(protocol.EpochQuery) suite.state.On("Sealed").Return(suite.snapshot, nil).Maybe() suite.state.On("Final").Return(suite.snapshot, nil).Maybe() + suite.state.On("Params").Return(params) suite.snapshot.On("Epochs").Return(suite.epochQuery).Maybe() suite.blocks = new(storagemock.Blocks) suite.headers = new(storagemock.Headers) @@ -141,6 +143,9 @@ func (suite *SameGRPCPortTestSuite) SetupTest() { suite.blockMap[block.Header.Height] = block } + params.On("SporkRootBlockHeight").Return(rootBlock.Header.Height, nil) + params.On("SealedRoot").Return(rootBlock.Header, nil) + // generate a server certificate that will be served by the GRPC server networkingKey := unittest.NetworkingPrivKeyFixture() x509Certificate, err := grpcutils.X509Certificate(networkingKey) diff --git a/engine/access/rest_api_test.go b/engine/access/rest_api_test.go index 95821b92a28..6ba71622e19 100644 --- a/engine/access/rest_api_test.go +++ b/engine/access/rest_api_test.go @@ -83,8 +83,14 @@ func (suite *RestAPITestSuite) SetupTest() { suite.sealedBlock = unittest.BlockHeaderFixture(unittest.WithHeaderHeight(0)) suite.finalizedBlock = unittest.BlockHeaderWithParentFixture(suite.sealedBlock) + rootHeader := unittest.BlockHeaderFixture() + params := new(protocol.Params) + params.On("SporkRootBlockHeight").Return(rootHeader.Height, nil) + params.On("SealedRoot").Return(rootHeader, nil) + suite.state.On("Sealed").Return(suite.sealedSnaphost, nil) suite.state.On("Final").Return(suite.finalizedSnapshot, nil) + suite.state.On("Params").Return(params) suite.sealedSnaphost.On("Head").Return( func() *flow.Header { return suite.sealedBlock diff --git a/engine/access/rpc/backend/backend.go b/engine/access/rpc/backend/backend.go index 4d4e1909b4d..825ef1be3e4 100644 --- a/engine/access/rpc/backend/backend.go +++ b/engine/access/rpc/backend/backend.go @@ -76,6 +76,9 @@ type Backend struct { collections storage.Collections executionReceipts storage.ExecutionReceipts connFactory connection.ConnectionFactory + + sporkRootBlockHeight uint64 + nodeRootBlockHeight uint64 } // Config defines the configurable options for creating Backend @@ -145,6 +148,16 @@ func New(params Params) (*Backend, error) { } } + sporkRootBlockHeight, err := params.State.Params().SporkRootBlockHeight() + if err != nil { + return nil, fmt.Errorf("failed to read spork root block height: %w", err) + } + + nodeRootBlockHeader, err := params.State.Params().SealedRoot() + if err != nil { + return nil, fmt.Errorf("failed to read node root block: %w", err) + } + b := &Backend{ state: params.State, // create the sub-backends @@ -211,10 +224,12 @@ func New(params Params) (*Backend, error) { chainID: params.ChainID, snapshotHistoryLimit: params.SnapshotHistoryLimit, }, - collections: params.Collections, - executionReceipts: params.ExecutionReceipts, - connFactory: params.ConnFactory, - chainID: params.ChainID, + collections: params.Collections, + executionReceipts: params.ExecutionReceipts, + connFactory: params.ConnFactory, + chainID: params.ChainID, + sporkRootBlockHeight: sporkRootBlockHeight, + nodeRootBlockHeight: nodeRootBlockHeader.Height, } retry.SetBackend(b) @@ -303,9 +318,9 @@ func (b *Backend) Ping(ctx context.Context) error { } // GetNodeVersionInfo returns node version information such as semver, commit, sporkID, protocolVersion, etc -func (b *Backend) GetNodeVersionInfo(ctx context.Context) (*access.NodeVersionInfo, error) { +func (b *Backend) GetNodeVersionInfo(_ context.Context) (*access.NodeVersionInfo, error) { stateParams := b.state.Params() - sporkId, err := stateParams.SporkID() + sporkID, err := stateParams.SporkID() if err != nil { return nil, status.Errorf(codes.Internal, "failed to read spork ID: %v", err) } @@ -316,10 +331,12 @@ func (b *Backend) GetNodeVersionInfo(ctx context.Context) (*access.NodeVersionIn } return &access.NodeVersionInfo{ - Semver: build.Version(), - Commit: build.Commit(), - SporkId: sporkId, - ProtocolVersion: uint64(protocolVersion), + Semver: build.Version(), + Commit: build.Commit(), + SporkId: sporkID, + ProtocolVersion: uint64(protocolVersion), + SporkRootBlockHeight: b.sporkRootBlockHeight, + NodeRootBlockHeight: b.nodeRootBlockHeight, }, nil } diff --git a/engine/access/rpc/backend/backend_test.go b/engine/access/rpc/backend/backend_test.go index 78670fa100d..fea3ea9da2d 100644 --- a/engine/access/rpc/backend/backend_test.go +++ b/engine/access/rpc/backend/backend_test.go @@ -18,6 +18,8 @@ import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/status" + accessflow "github.com/onflow/flow-go/access" + "github.com/onflow/flow-go/cmd/build" access "github.com/onflow/flow-go/engine/access/mock" backendmock "github.com/onflow/flow-go/engine/access/rpc/backend/mock" "github.com/onflow/flow-go/engine/access/rpc/connection" @@ -71,7 +73,8 @@ func (suite *Suite) SetupTest() { params := new(protocol.Params) params.On("FinalizedRoot").Return(header, nil) params.On("SporkRootBlockHeight").Return(header.Height, nil) - suite.state.On("Params").Return(params).Maybe() + params.On("SealedRoot").Return(header, nil) + suite.state.On("Params").Return(params) suite.blocks = new(storagemock.Blocks) suite.headers = new(storagemock.Headers) suite.transactions = new(storagemock.Transactions) @@ -1242,9 +1245,9 @@ func (suite *Suite) TestGetEventsForHeightRange() { state.On("Sealed").Return(snapshot, nil) rootHeader := unittest.BlockHeaderFixture() - params := new(protocol.Params) - params.On("FinalizedRoot").Return(rootHeader, nil) - state.On("Params").Return(params).Maybe() + stateParams := new(protocol.Params) + stateParams.On("FinalizedRoot").Return(rootHeader, nil) + state.On("Params").Return(stateParams).Maybe() // mock snapshot to return head backend snapshot.On("Head").Return( @@ -1364,6 +1367,9 @@ func (suite *Suite) TestGetEventsForHeightRange() { expectedResp := setupExecClient() fixedENIdentifiersStr := flow.IdentifierList(nodeIdentities.NodeIDs()).Strings() + stateParams.On("SporkRootBlockHeight").Return(headHeight, nil) + stateParams.On("SealedRoot").Return(head, nil) + params := suite.defaultBackendParams() params.State = state params.ConnFactory = connFactory @@ -1388,6 +1394,9 @@ func (suite *Suite) TestGetEventsForHeightRange() { expectedResp := setupExecClient() fixedENIdentifiersStr := flow.IdentifierList(nodeIdentities.NodeIDs()).Strings() + stateParams.On("SporkRootBlockHeight").Return(headHeight, nil) + stateParams.On("SealedRoot").Return(head, nil) + params := suite.defaultBackendParams() params.State = state params.ConnFactory = connFactory @@ -1577,6 +1586,87 @@ func (suite *Suite) TestGetAccountAtBlockHeight() { }) } +func (suite *Suite) TestGetNodeVersionInfo() { + sporkRootBlock := unittest.BlockHeaderFixture() + nodeRootBlock := unittest.BlockHeaderFixture(unittest.WithHeaderHeight(sporkRootBlock.Height + 100)) + sporkID := unittest.IdentifierFixture() + protocolVersion := uint(1234) + + suite.Run("happy path", func() { + stateParams := protocol.NewParams(suite.T()) + stateParams.On("SporkRootBlockHeight").Return(sporkRootBlock.Height, nil) + stateParams.On("SealedRoot").Return(nodeRootBlock, nil) + stateParams.On("SporkID").Return(sporkID, nil) + stateParams.On("ProtocolVersion").Return(protocolVersion, nil) + + state := protocol.NewState(suite.T()) + state.On("Params").Return(stateParams, nil).Maybe() + + expected := &accessflow.NodeVersionInfo{ + Semver: build.Version(), + Commit: build.Commit(), + SporkId: sporkID, + ProtocolVersion: uint64(protocolVersion), + SporkRootBlockHeight: sporkRootBlock.Height, + NodeRootBlockHeight: nodeRootBlock.Height, + } + + params := suite.defaultBackendParams() + params.State = state + + backend, err := New(params) + suite.Require().NoError(err) + + actual, err := backend.GetNodeVersionInfo(context.Background()) + suite.Require().NoError(err) + + suite.Require().Equal(expected, actual) + }) + + suite.Run("returns Internal error when sporkID lookup fails", func() { + stateParams := protocol.NewParams(suite.T()) + stateParams.On("SporkRootBlockHeight").Return(sporkRootBlock.Height, nil) + stateParams.On("SealedRoot").Return(nodeRootBlock, nil) + stateParams.On("SporkID").Return(flow.ZeroID, fmt.Errorf("fail")) + + state := protocol.NewState(suite.T()) + state.On("Params").Return(stateParams, nil).Maybe() + + params := suite.defaultBackendParams() + params.State = state + + backend, err := New(params) + suite.Require().NoError(err) + + actual, err := backend.GetNodeVersionInfo(context.Background()) + suite.Assert().Error(err) + suite.Assert().Nil(actual) + suite.Assert().Equal(codes.Internal, status.Code(err)) + }) + + suite.Run("returns Internal error when protocolVersion lookup fails", func() { + stateParams := protocol.NewParams(suite.T()) + stateParams.On("SporkRootBlockHeight").Return(sporkRootBlock.Height, nil) + stateParams.On("SealedRoot").Return(nodeRootBlock, nil) + stateParams.On("SporkID").Return(sporkID, nil) + stateParams.On("ProtocolVersion").Return(uint(0), fmt.Errorf("fail")) + + state := protocol.NewState(suite.T()) + state.On("Params").Return(stateParams, nil).Maybe() + + params := suite.defaultBackendParams() + params.State = state + + backend, err := New(params) + suite.Require().NoError(err) + + actual, err := backend.GetNodeVersionInfo(context.Background()) + suite.Assert().Error(err) + suite.Assert().Nil(actual) + suite.Assert().Equal(codes.Internal, status.Code(err)) + }) +} + func (suite *Suite) TestGetNetworkParameters() { suite.state.On("Sealed").Return(suite.snapshot, nil).Maybe() diff --git a/engine/access/rpc/rate_limit_test.go b/engine/access/rpc/rate_limit_test.go index bba1998faf6..921a6affab5 100644 --- a/engine/access/rpc/rate_limit_test.go +++ b/engine/access/rpc/rate_limit_test.go @@ -76,9 +76,15 @@ func (suite *RateLimitTestSuite) SetupTest() { suite.state = new(protocol.State) suite.snapshot = new(protocol.Snapshot) + rootHeader := unittest.BlockHeaderFixture() + params := new(protocol.Params) + params.On("SporkRootBlockHeight").Return(rootHeader.Height, nil) + params.On("SealedRoot").Return(rootHeader, nil) + suite.epochQuery = new(protocol.EpochQuery) suite.state.On("Sealed").Return(suite.snapshot, nil).Maybe() suite.state.On("Final").Return(suite.snapshot, nil).Maybe() + suite.state.On("Params").Return(params, nil).Maybe() suite.snapshot.On("Epochs").Return(suite.epochQuery).Maybe() suite.blocks = new(storagemock.Blocks) suite.headers = new(storagemock.Headers) diff --git a/engine/access/secure_grpcr_test.go b/engine/access/secure_grpcr_test.go index 97d7ca0a4b7..50feeb55f1e 100644 --- a/engine/access/secure_grpcr_test.go +++ b/engine/access/secure_grpcr_test.go @@ -70,9 +70,15 @@ func (suite *SecureGRPCTestSuite) SetupTest() { suite.state = new(protocol.State) suite.snapshot = new(protocol.Snapshot) + rootHeader := unittest.BlockHeaderFixture() + params := new(protocol.Params) + params.On("SporkRootBlockHeight").Return(rootHeader.Height, nil) + params.On("SealedRoot").Return(rootHeader, nil) + suite.epochQuery = new(protocol.EpochQuery) suite.state.On("Sealed").Return(suite.snapshot, nil).Maybe() suite.state.On("Final").Return(suite.snapshot, nil).Maybe() + suite.state.On("Params").Return(params, nil).Maybe() suite.snapshot.On("Epochs").Return(suite.epochQuery).Maybe() suite.blocks = new(storagemock.Blocks) suite.headers = new(storagemock.Headers) diff --git a/go.mod b/go.mod index 05ab2e0ea2e..a66f9422293 100644 --- a/go.mod +++ b/go.mod @@ -57,7 +57,7 @@ require ( github.com/onflow/flow-core-contracts/lib/go/templates v1.2.3 github.com/onflow/flow-go-sdk v0.41.10 github.com/onflow/flow-go/crypto v0.24.9 - github.com/onflow/flow/protobuf/go/flow v0.3.2-0.20230628215638-83439d22e0ce + github.com/onflow/flow/protobuf/go/flow v0.3.2-0.20230905234123-092cc8fc339f github.com/onflow/go-bitswap v0.0.0-20230703214630-6d3db958c73d github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 github.com/pierrec/lz4 v2.6.1+incompatible diff --git a/go.sum b/go.sum index a2abc8cef6b..b9c654ef667 100644 --- a/go.sum +++ b/go.sum @@ -1259,8 +1259,8 @@ github.com/onflow/flow-go/crypto v0.24.9/go.mod h1:fqCzkIBBMRRkciVrvW21rECKq1oD7 github.com/onflow/flow-nft/lib/go/contracts v1.1.0 h1:rhUDeD27jhLwOqQKI/23008CYfnqXErrJvc4EFRP2a0= github.com/onflow/flow-nft/lib/go/contracts v1.1.0/go.mod h1:YsvzYng4htDgRB9sa9jxdwoTuuhjK8WYWXTyLkIigZY= github.com/onflow/flow/protobuf/go/flow v0.2.2/go.mod h1:gQxYqCfkI8lpnKsmIjwtN2mV/N2PIwc1I+RUK4HPIc8= -github.com/onflow/flow/protobuf/go/flow v0.3.2-0.20230628215638-83439d22e0ce h1:YQKijiQaq8SF1ayNqp3VVcwbBGXSnuHNHq4GQmVGybE= -github.com/onflow/flow/protobuf/go/flow v0.3.2-0.20230628215638-83439d22e0ce/go.mod h1:NA2pX2nw8zuaxfKphhKsk00kWLwfd+tv8mS23YXO4Sk= +github.com/onflow/flow/protobuf/go/flow v0.3.2-0.20230905234123-092cc8fc339f h1:wpjOjWWOYq09CnabnjGN7IdtPNcB60JvMpdhtpoFi6w= +github.com/onflow/flow/protobuf/go/flow v0.3.2-0.20230905234123-092cc8fc339f/go.mod h1:NA2pX2nw8zuaxfKphhKsk00kWLwfd+tv8mS23YXO4Sk= github.com/onflow/go-bitswap v0.0.0-20230703214630-6d3db958c73d h1:QcOAeEyF3iAUHv21LQ12sdcsr0yFrJGoGLyCAzYYtvI= github.com/onflow/go-bitswap v0.0.0-20230703214630-6d3db958c73d/go.mod h1:GCPpiyRoHncdqPj++zPr9ZOYBX4hpJ0pYZRYqSE8VKk= github.com/onflow/sdks v0.5.0 h1:2HCRibwqDaQ1c9oUApnkZtEAhWiNY2GTpRD5+ftdkN8= diff --git a/insecure/go.mod b/insecure/go.mod index c0f8048ecbe..55939ca77a2 100644 --- a/insecure/go.mod +++ b/insecure/go.mod @@ -186,7 +186,7 @@ require ( github.com/onflow/flow-ft/lib/go/contracts v0.7.0 // indirect github.com/onflow/flow-go-sdk v0.41.10 // indirect github.com/onflow/flow-nft/lib/go/contracts v1.1.0 // indirect - github.com/onflow/flow/protobuf/go/flow v0.3.2-0.20230628215638-83439d22e0ce // indirect + github.com/onflow/flow/protobuf/go/flow v0.3.2-0.20230905234123-092cc8fc339f // indirect github.com/onflow/go-bitswap v0.0.0-20230703214630-6d3db958c73d // indirect github.com/onflow/sdks v0.5.0 // indirect github.com/onflow/wal v0.0.0-20230529184820-bc9f8244608d // indirect diff --git a/insecure/go.sum b/insecure/go.sum index 376c5d1543e..bdf0ec64fc8 100644 --- a/insecure/go.sum +++ b/insecure/go.sum @@ -1233,8 +1233,8 @@ github.com/onflow/flow-go/crypto v0.24.9/go.mod h1:fqCzkIBBMRRkciVrvW21rECKq1oD7 github.com/onflow/flow-nft/lib/go/contracts v1.1.0 h1:rhUDeD27jhLwOqQKI/23008CYfnqXErrJvc4EFRP2a0= github.com/onflow/flow-nft/lib/go/contracts v1.1.0/go.mod h1:YsvzYng4htDgRB9sa9jxdwoTuuhjK8WYWXTyLkIigZY= github.com/onflow/flow/protobuf/go/flow v0.2.2/go.mod h1:gQxYqCfkI8lpnKsmIjwtN2mV/N2PIwc1I+RUK4HPIc8= -github.com/onflow/flow/protobuf/go/flow v0.3.2-0.20230628215638-83439d22e0ce h1:YQKijiQaq8SF1ayNqp3VVcwbBGXSnuHNHq4GQmVGybE= -github.com/onflow/flow/protobuf/go/flow v0.3.2-0.20230628215638-83439d22e0ce/go.mod h1:NA2pX2nw8zuaxfKphhKsk00kWLwfd+tv8mS23YXO4Sk= +github.com/onflow/flow/protobuf/go/flow v0.3.2-0.20230905234123-092cc8fc339f h1:wpjOjWWOYq09CnabnjGN7IdtPNcB60JvMpdhtpoFi6w= +github.com/onflow/flow/protobuf/go/flow v0.3.2-0.20230905234123-092cc8fc339f/go.mod h1:NA2pX2nw8zuaxfKphhKsk00kWLwfd+tv8mS23YXO4Sk= github.com/onflow/go-bitswap v0.0.0-20230703214630-6d3db958c73d h1:QcOAeEyF3iAUHv21LQ12sdcsr0yFrJGoGLyCAzYYtvI= github.com/onflow/go-bitswap v0.0.0-20230703214630-6d3db958c73d/go.mod h1:GCPpiyRoHncdqPj++zPr9ZOYBX4hpJ0pYZRYqSE8VKk= github.com/onflow/sdks v0.5.0 h1:2HCRibwqDaQ1c9oUApnkZtEAhWiNY2GTpRD5+ftdkN8= diff --git a/integration/go.mod b/integration/go.mod index affeae7bc11..7be56bbf20f 100644 --- a/integration/go.mod +++ b/integration/go.mod @@ -25,7 +25,7 @@ require ( github.com/onflow/flow-go-sdk v0.41.10 github.com/onflow/flow-go/crypto v0.24.9 github.com/onflow/flow-go/insecure v0.0.0-00010101000000-000000000000 - github.com/onflow/flow/protobuf/go/flow v0.3.2-0.20230628215638-83439d22e0ce + github.com/onflow/flow/protobuf/go/flow v0.3.2-0.20230905234123-092cc8fc339f github.com/plus3it/gorecurcopy v0.0.1 github.com/prometheus/client_golang v1.14.0 github.com/prometheus/client_model v0.4.0 diff --git a/integration/go.sum b/integration/go.sum index 540ba104a09..fc6e0623811 100644 --- a/integration/go.sum +++ b/integration/go.sum @@ -1373,8 +1373,8 @@ github.com/onflow/flow-go/crypto v0.24.9/go.mod h1:fqCzkIBBMRRkciVrvW21rECKq1oD7 github.com/onflow/flow-nft/lib/go/contracts v1.1.0 h1:rhUDeD27jhLwOqQKI/23008CYfnqXErrJvc4EFRP2a0= github.com/onflow/flow-nft/lib/go/contracts v1.1.0/go.mod h1:YsvzYng4htDgRB9sa9jxdwoTuuhjK8WYWXTyLkIigZY= github.com/onflow/flow/protobuf/go/flow v0.2.2/go.mod h1:gQxYqCfkI8lpnKsmIjwtN2mV/N2PIwc1I+RUK4HPIc8= -github.com/onflow/flow/protobuf/go/flow v0.3.2-0.20230628215638-83439d22e0ce h1:YQKijiQaq8SF1ayNqp3VVcwbBGXSnuHNHq4GQmVGybE= -github.com/onflow/flow/protobuf/go/flow v0.3.2-0.20230628215638-83439d22e0ce/go.mod h1:NA2pX2nw8zuaxfKphhKsk00kWLwfd+tv8mS23YXO4Sk= +github.com/onflow/flow/protobuf/go/flow v0.3.2-0.20230905234123-092cc8fc339f h1:wpjOjWWOYq09CnabnjGN7IdtPNcB60JvMpdhtpoFi6w= +github.com/onflow/flow/protobuf/go/flow v0.3.2-0.20230905234123-092cc8fc339f/go.mod h1:NA2pX2nw8zuaxfKphhKsk00kWLwfd+tv8mS23YXO4Sk= github.com/onflow/go-bitswap v0.0.0-20230703214630-6d3db958c73d h1:QcOAeEyF3iAUHv21LQ12sdcsr0yFrJGoGLyCAzYYtvI= github.com/onflow/go-bitswap v0.0.0-20230703214630-6d3db958c73d/go.mod h1:GCPpiyRoHncdqPj++zPr9ZOYBX4hpJ0pYZRYqSE8VKk= github.com/onflow/nft-storefront/lib/go/contracts v0.0.0-20221222181731-14b90207cead h1:2j1Unqs76Z1b95Gu4C3Y28hzNUHBix7wL490e61SMSw= From eb353e4ac5031dd5d73bd87d5b54391f430b9bf7 Mon Sep 17 00:00:00 2001 From: Peter Argue <89119817+peterargue@users.noreply.github.com> Date: Wed, 6 Sep 2023 12:36:05 -0700 Subject: [PATCH 2/4] update rest API and tests --- .../rest/models/model_node_version_info.go | 10 ++++---- .../access/rest/models/node_version_info.go | 2 ++ .../rest/routes/node_version_info_test.go | 23 ++++++++++++++----- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/engine/access/rest/models/model_node_version_info.go b/engine/access/rest/models/model_node_version_info.go index 0e29f8d480a..5a53e468996 100644 --- a/engine/access/rest/models/model_node_version_info.go +++ b/engine/access/rest/models/model_node_version_info.go @@ -9,8 +9,10 @@ package models type NodeVersionInfo struct { - Semver string `json:"semver"` - Commit string `json:"commit"` - SporkId string `json:"spork_id"` - ProtocolVersion string `json:"protocol_version"` + Semver string `json:"semver"` + Commit string `json:"commit"` + SporkId string `json:"spork_id"` + ProtocolVersion string `json:"protocol_version"` + SporkRootBlockHeight string `json:"spork_root_block_height"` + NodeRootBlockHeight string `json:"node_root_block_height"` } diff --git a/engine/access/rest/models/node_version_info.go b/engine/access/rest/models/node_version_info.go index 6a85e9f8d42..4d1fba8dad1 100644 --- a/engine/access/rest/models/node_version_info.go +++ b/engine/access/rest/models/node_version_info.go @@ -10,4 +10,6 @@ func (t *NodeVersionInfo) Build(params *access.NodeVersionInfo) { t.Commit = params.Commit t.SporkId = params.SporkId.String() t.ProtocolVersion = util.FromUint64(params.ProtocolVersion) + t.SporkRootBlockHeight = util.FromUint64(params.SporkRootBlockHeight) + t.NodeRootBlockHeight = util.FromUint64(params.NodeRootBlockHeight) } diff --git a/engine/access/rest/routes/node_version_info_test.go b/engine/access/rest/routes/node_version_info_test.go index 179d339f94f..0bce5c83c13 100644 --- a/engine/access/rest/routes/node_version_info_test.go +++ b/engine/access/rest/routes/node_version_info_test.go @@ -29,10 +29,12 @@ func TestGetNodeVersionInfo(t *testing.T) { req := getNodeVersionInfoRequest(t) params := &access.NodeVersionInfo{ - Semver: build.Version(), - Commit: build.Commit(), - SporkId: unittest.IdentifierFixture(), - ProtocolVersion: unittest.Uint64InRange(10, 30), + Semver: build.Version(), + Commit: build.Commit(), + SporkId: unittest.IdentifierFixture(), + ProtocolVersion: unittest.Uint64InRange(10, 30), + SporkRootBlockHeight: unittest.Uint64InRange(1000, 10_000), + NodeRootBlockHeight: unittest.Uint64InRange(10_000, 100_000), } backend.Mock. @@ -51,8 +53,17 @@ func nodeVersionInfoExpectedStr(nodeVersionInfo *access.NodeVersionInfo) string "semver": "%s", "commit": "%s", "spork_id": "%s", - "protocol_version": "%d" - }`, nodeVersionInfo.Semver, nodeVersionInfo.Commit, nodeVersionInfo.SporkId.String(), nodeVersionInfo.ProtocolVersion) + "protocol_version": "%d", + "spork_root_block_height": "%d", + "node_root_block_height": "%d" + }`, + nodeVersionInfo.Semver, + nodeVersionInfo.Commit, + nodeVersionInfo.SporkId.String(), + nodeVersionInfo.ProtocolVersion, + nodeVersionInfo.SporkRootBlockHeight, + nodeVersionInfo.NodeRootBlockHeight, + ) } func getNodeVersionInfoRequest(t *testing.T) *http.Request { From b366988bf9caa5148c575fcca5f5080b1c84459f Mon Sep 17 00:00:00 2001 From: Peter Argue <89119817+peterargue@users.noreply.github.com> Date: Tue, 12 Sep 2023 14:43:24 -0700 Subject: [PATCH 3/4] update protobuf module version --- go.mod | 2 +- go.sum | 4 ++-- insecure/go.mod | 2 +- insecure/go.sum | 4 ++-- integration/go.mod | 2 +- integration/go.sum | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index a66f9422293..9dcb2dfe045 100644 --- a/go.mod +++ b/go.mod @@ -57,7 +57,7 @@ require ( github.com/onflow/flow-core-contracts/lib/go/templates v1.2.3 github.com/onflow/flow-go-sdk v0.41.10 github.com/onflow/flow-go/crypto v0.24.9 - github.com/onflow/flow/protobuf/go/flow v0.3.2-0.20230905234123-092cc8fc339f + github.com/onflow/flow/protobuf/go/flow v0.3.2-0.20230912213857-614a2a0c0128 github.com/onflow/go-bitswap v0.0.0-20230703214630-6d3db958c73d github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 github.com/pierrec/lz4 v2.6.1+incompatible diff --git a/go.sum b/go.sum index b9c654ef667..67d6da9adcd 100644 --- a/go.sum +++ b/go.sum @@ -1259,8 +1259,8 @@ github.com/onflow/flow-go/crypto v0.24.9/go.mod h1:fqCzkIBBMRRkciVrvW21rECKq1oD7 github.com/onflow/flow-nft/lib/go/contracts v1.1.0 h1:rhUDeD27jhLwOqQKI/23008CYfnqXErrJvc4EFRP2a0= github.com/onflow/flow-nft/lib/go/contracts v1.1.0/go.mod h1:YsvzYng4htDgRB9sa9jxdwoTuuhjK8WYWXTyLkIigZY= github.com/onflow/flow/protobuf/go/flow v0.2.2/go.mod h1:gQxYqCfkI8lpnKsmIjwtN2mV/N2PIwc1I+RUK4HPIc8= -github.com/onflow/flow/protobuf/go/flow v0.3.2-0.20230905234123-092cc8fc339f h1:wpjOjWWOYq09CnabnjGN7IdtPNcB60JvMpdhtpoFi6w= -github.com/onflow/flow/protobuf/go/flow v0.3.2-0.20230905234123-092cc8fc339f/go.mod h1:NA2pX2nw8zuaxfKphhKsk00kWLwfd+tv8mS23YXO4Sk= +github.com/onflow/flow/protobuf/go/flow v0.3.2-0.20230912213857-614a2a0c0128 h1:e6wRlUtaBoydv0hY44HJeUMm0KdeqCI9cYzMvNB/tAk= +github.com/onflow/flow/protobuf/go/flow v0.3.2-0.20230912213857-614a2a0c0128/go.mod h1:NA2pX2nw8zuaxfKphhKsk00kWLwfd+tv8mS23YXO4Sk= github.com/onflow/go-bitswap v0.0.0-20230703214630-6d3db958c73d h1:QcOAeEyF3iAUHv21LQ12sdcsr0yFrJGoGLyCAzYYtvI= github.com/onflow/go-bitswap v0.0.0-20230703214630-6d3db958c73d/go.mod h1:GCPpiyRoHncdqPj++zPr9ZOYBX4hpJ0pYZRYqSE8VKk= github.com/onflow/sdks v0.5.0 h1:2HCRibwqDaQ1c9oUApnkZtEAhWiNY2GTpRD5+ftdkN8= diff --git a/insecure/go.mod b/insecure/go.mod index 55939ca77a2..27968d27596 100644 --- a/insecure/go.mod +++ b/insecure/go.mod @@ -186,7 +186,7 @@ require ( github.com/onflow/flow-ft/lib/go/contracts v0.7.0 // indirect github.com/onflow/flow-go-sdk v0.41.10 // indirect github.com/onflow/flow-nft/lib/go/contracts v1.1.0 // indirect - github.com/onflow/flow/protobuf/go/flow v0.3.2-0.20230905234123-092cc8fc339f // indirect + github.com/onflow/flow/protobuf/go/flow v0.3.2-0.20230912213857-614a2a0c0128 // indirect github.com/onflow/go-bitswap v0.0.0-20230703214630-6d3db958c73d // indirect github.com/onflow/sdks v0.5.0 // indirect github.com/onflow/wal v0.0.0-20230529184820-bc9f8244608d // indirect diff --git a/insecure/go.sum b/insecure/go.sum index bdf0ec64fc8..4a564cc216e 100644 --- a/insecure/go.sum +++ b/insecure/go.sum @@ -1233,8 +1233,8 @@ github.com/onflow/flow-go/crypto v0.24.9/go.mod h1:fqCzkIBBMRRkciVrvW21rECKq1oD7 github.com/onflow/flow-nft/lib/go/contracts v1.1.0 h1:rhUDeD27jhLwOqQKI/23008CYfnqXErrJvc4EFRP2a0= github.com/onflow/flow-nft/lib/go/contracts v1.1.0/go.mod h1:YsvzYng4htDgRB9sa9jxdwoTuuhjK8WYWXTyLkIigZY= github.com/onflow/flow/protobuf/go/flow v0.2.2/go.mod h1:gQxYqCfkI8lpnKsmIjwtN2mV/N2PIwc1I+RUK4HPIc8= -github.com/onflow/flow/protobuf/go/flow v0.3.2-0.20230905234123-092cc8fc339f h1:wpjOjWWOYq09CnabnjGN7IdtPNcB60JvMpdhtpoFi6w= -github.com/onflow/flow/protobuf/go/flow v0.3.2-0.20230905234123-092cc8fc339f/go.mod h1:NA2pX2nw8zuaxfKphhKsk00kWLwfd+tv8mS23YXO4Sk= +github.com/onflow/flow/protobuf/go/flow v0.3.2-0.20230912213857-614a2a0c0128 h1:e6wRlUtaBoydv0hY44HJeUMm0KdeqCI9cYzMvNB/tAk= +github.com/onflow/flow/protobuf/go/flow v0.3.2-0.20230912213857-614a2a0c0128/go.mod h1:NA2pX2nw8zuaxfKphhKsk00kWLwfd+tv8mS23YXO4Sk= github.com/onflow/go-bitswap v0.0.0-20230703214630-6d3db958c73d h1:QcOAeEyF3iAUHv21LQ12sdcsr0yFrJGoGLyCAzYYtvI= github.com/onflow/go-bitswap v0.0.0-20230703214630-6d3db958c73d/go.mod h1:GCPpiyRoHncdqPj++zPr9ZOYBX4hpJ0pYZRYqSE8VKk= github.com/onflow/sdks v0.5.0 h1:2HCRibwqDaQ1c9oUApnkZtEAhWiNY2GTpRD5+ftdkN8= diff --git a/integration/go.mod b/integration/go.mod index 7be56bbf20f..2c503324bff 100644 --- a/integration/go.mod +++ b/integration/go.mod @@ -25,7 +25,7 @@ require ( github.com/onflow/flow-go-sdk v0.41.10 github.com/onflow/flow-go/crypto v0.24.9 github.com/onflow/flow-go/insecure v0.0.0-00010101000000-000000000000 - github.com/onflow/flow/protobuf/go/flow v0.3.2-0.20230905234123-092cc8fc339f + github.com/onflow/flow/protobuf/go/flow v0.3.2-0.20230912213857-614a2a0c0128 github.com/plus3it/gorecurcopy v0.0.1 github.com/prometheus/client_golang v1.14.0 github.com/prometheus/client_model v0.4.0 diff --git a/integration/go.sum b/integration/go.sum index fc6e0623811..5b1ec0f518f 100644 --- a/integration/go.sum +++ b/integration/go.sum @@ -1373,8 +1373,8 @@ github.com/onflow/flow-go/crypto v0.24.9/go.mod h1:fqCzkIBBMRRkciVrvW21rECKq1oD7 github.com/onflow/flow-nft/lib/go/contracts v1.1.0 h1:rhUDeD27jhLwOqQKI/23008CYfnqXErrJvc4EFRP2a0= github.com/onflow/flow-nft/lib/go/contracts v1.1.0/go.mod h1:YsvzYng4htDgRB9sa9jxdwoTuuhjK8WYWXTyLkIigZY= github.com/onflow/flow/protobuf/go/flow v0.2.2/go.mod h1:gQxYqCfkI8lpnKsmIjwtN2mV/N2PIwc1I+RUK4HPIc8= -github.com/onflow/flow/protobuf/go/flow v0.3.2-0.20230905234123-092cc8fc339f h1:wpjOjWWOYq09CnabnjGN7IdtPNcB60JvMpdhtpoFi6w= -github.com/onflow/flow/protobuf/go/flow v0.3.2-0.20230905234123-092cc8fc339f/go.mod h1:NA2pX2nw8zuaxfKphhKsk00kWLwfd+tv8mS23YXO4Sk= +github.com/onflow/flow/protobuf/go/flow v0.3.2-0.20230912213857-614a2a0c0128 h1:e6wRlUtaBoydv0hY44HJeUMm0KdeqCI9cYzMvNB/tAk= +github.com/onflow/flow/protobuf/go/flow v0.3.2-0.20230912213857-614a2a0c0128/go.mod h1:NA2pX2nw8zuaxfKphhKsk00kWLwfd+tv8mS23YXO4Sk= github.com/onflow/go-bitswap v0.0.0-20230703214630-6d3db958c73d h1:QcOAeEyF3iAUHv21LQ12sdcsr0yFrJGoGLyCAzYYtvI= github.com/onflow/go-bitswap v0.0.0-20230703214630-6d3db958c73d/go.mod h1:GCPpiyRoHncdqPj++zPr9ZOYBX4hpJ0pYZRYqSE8VKk= github.com/onflow/nft-storefront/lib/go/contracts v0.0.0-20221222181731-14b90207cead h1:2j1Unqs76Z1b95Gu4C3Y28hzNUHBix7wL490e61SMSw= From 24898eb809fa2b5b669b716a784d3bf6aba348d5 Mon Sep 17 00:00:00 2001 From: Peter Argue <89119817+peterargue@users.noreply.github.com> Date: Thu, 14 Sep 2023 13:29:16 -0700 Subject: [PATCH 4/4] cache whole node version info response --- engine/access/access_test.go | 16 ++--- .../integration_unsecure_grpc_server_test.go | 2 + engine/access/rest_api_test.go | 12 ++-- engine/access/rpc/backend/backend.go | 58 +++++++++------- engine/access/rpc/backend/backend_test.go | 68 +++++++++++++------ engine/access/rpc/rate_limit_test.go | 2 + engine/access/secure_grpcr_test.go | 2 + 7 files changed, 105 insertions(+), 55 deletions(-) diff --git a/engine/access/access_test.go b/engine/access/access_test.go index 592b33dbf3d..9c09bb197ec 100644 --- a/engine/access/access_test.go +++ b/engine/access/access_test.go @@ -70,6 +70,8 @@ type Suite struct { metrics *metrics.NoopCollector finalizedHeaderCache module.FinalizedHeaderCache backend *backend.Backend + sporkID flow.Identifier + protocolVersion uint } // TestAccess tests scenarios which exercise multiple API calls using both the RPC handler and the ingest engine @@ -84,6 +86,8 @@ func (suite *Suite) SetupTest() { suite.state = new(protocol.State) suite.finalSnapshot = new(protocol.Snapshot) suite.sealedSnapshot = new(protocol.Snapshot) + suite.sporkID = unittest.IdentifierFixture() + suite.protocolVersion = uint(unittest.Uint64InRange(10, 30)) suite.rootBlock = unittest.BlockHeaderFixture(unittest.WithHeaderHeight(0)) suite.sealedBlock = suite.rootBlock @@ -108,6 +112,8 @@ func (suite *Suite) SetupTest() { suite.params = new(protocol.Params) suite.params.On("FinalizedRoot").Return(suite.rootBlock, nil) + suite.params.On("SporkID").Return(suite.sporkID, nil) + suite.params.On("ProtocolVersion").Return(suite.protocolVersion, nil) suite.params.On("SporkRootBlockHeight").Return(suite.rootBlock.Height, nil) suite.params.On("SealedRoot").Return(suite.rootBlock, nil) suite.state.On("Params").Return(suite.params).Maybe() @@ -1111,12 +1117,6 @@ func (suite *Suite) TestExecuteScript() { // information func (suite *Suite) TestAPICallNodeVersionInfo() { suite.RunTest(func(handler *access.Handler, db *badger.DB, all *storage.All) { - sporkId := unittest.IdentifierFixture() - protocolVersion := uint(unittest.Uint64InRange(10, 30)) - - suite.params.On("SporkID").Return(sporkId, nil) - suite.params.On("ProtocolVersion").Return(protocolVersion, nil) - req := &accessproto.GetNodeVersionInfoRequest{} resp, err := handler.GetNodeVersionInfo(context.Background(), req) require.NoError(suite.T(), err) @@ -1126,8 +1126,8 @@ func (suite *Suite) TestAPICallNodeVersionInfo() { suite.Require().Equal(respNodeVersionInfo, &entitiesproto.NodeVersionInfo{ Semver: build.Version(), Commit: build.Commit(), - SporkId: sporkId[:], - ProtocolVersion: uint64(protocolVersion), + SporkId: suite.sporkID[:], + ProtocolVersion: uint64(suite.protocolVersion), }) }) } diff --git a/engine/access/integration_unsecure_grpc_server_test.go b/engine/access/integration_unsecure_grpc_server_test.go index 16024ea60f6..74a3ab3c819 100644 --- a/engine/access/integration_unsecure_grpc_server_test.go +++ b/engine/access/integration_unsecure_grpc_server_test.go @@ -143,6 +143,8 @@ func (suite *SameGRPCPortTestSuite) SetupTest() { suite.blockMap[block.Header.Height] = block } + params.On("SporkID").Return(unittest.IdentifierFixture(), nil) + params.On("ProtocolVersion").Return(uint(unittest.Uint64InRange(10, 30)), nil) params.On("SporkRootBlockHeight").Return(rootBlock.Header.Height, nil) params.On("SealedRoot").Return(rootBlock.Header, nil) diff --git a/engine/access/rest_api_test.go b/engine/access/rest_api_test.go index 9aa4d35f58f..37d42d3de97 100644 --- a/engine/access/rest_api_test.go +++ b/engine/access/rest_api_test.go @@ -85,6 +85,8 @@ func (suite *RestAPITestSuite) SetupTest() { rootHeader := unittest.BlockHeaderFixture() params := new(protocol.Params) + params.On("SporkID").Return(unittest.IdentifierFixture(), nil) + params.On("ProtocolVersion").Return(uint(unittest.Uint64InRange(10, 30)), nil) params.On("SporkRootBlockHeight").Return(rootHeader.Height, nil) params.On("SealedRoot").Return(rootHeader, nil) @@ -208,10 +210,12 @@ func (suite *RestAPITestSuite) SetupTest() { } func (suite *RestAPITestSuite) TearDownTest() { - suite.cancel() - unittest.AssertClosesBefore(suite.T(), suite.secureGrpcServer.Done(), 2*time.Second) - unittest.AssertClosesBefore(suite.T(), suite.unsecureGrpcServer.Done(), 2*time.Second) - unittest.AssertClosesBefore(suite.T(), suite.rpcEng.Done(), 2*time.Second) + if suite.cancel != nil { + suite.cancel() + unittest.AssertClosesBefore(suite.T(), suite.secureGrpcServer.Done(), 2*time.Second) + unittest.AssertClosesBefore(suite.T(), suite.unsecureGrpcServer.Done(), 2*time.Second) + unittest.AssertClosesBefore(suite.T(), suite.rpcEng.Done(), 2*time.Second) + } } func TestRestAPI(t *testing.T) { diff --git a/engine/access/rpc/backend/backend.go b/engine/access/rpc/backend/backend.go index 825ef1be3e4..9f76a665769 100644 --- a/engine/access/rpc/backend/backend.go +++ b/engine/access/rpc/backend/backend.go @@ -11,8 +11,6 @@ import ( lru2 "github.com/hashicorp/golang-lru/v2" accessproto "github.com/onflow/flow/protobuf/go/flow/access" "github.com/rs/zerolog" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" "github.com/onflow/flow-go/access" "github.com/onflow/flow-go/cmd/build" @@ -77,8 +75,8 @@ type Backend struct { executionReceipts storage.ExecutionReceipts connFactory connection.ConnectionFactory - sporkRootBlockHeight uint64 - nodeRootBlockHeight uint64 + // cache the response to GetNodeVersionInfo since it doesn't change + nodeInfo *access.NodeVersionInfo } // Config defines the configurable options for creating Backend @@ -148,14 +146,10 @@ func New(params Params) (*Backend, error) { } } - sporkRootBlockHeight, err := params.State.Params().SporkRootBlockHeight() + // initialize node version info + nodeInfo, err := getNodeVersionInfo(params.State.Params()) if err != nil { - return nil, fmt.Errorf("failed to read spork root block height: %w", err) - } - - nodeRootBlockHeader, err := params.State.Params().SealedRoot() - if err != nil { - return nil, fmt.Errorf("failed to read node root block: %w", err) + return nil, fmt.Errorf("failed to initialize node version info: %w", err) } b := &Backend{ @@ -224,12 +218,11 @@ func New(params Params) (*Backend, error) { chainID: params.ChainID, snapshotHistoryLimit: params.SnapshotHistoryLimit, }, - collections: params.Collections, - executionReceipts: params.ExecutionReceipts, - connFactory: params.ConnFactory, - chainID: params.ChainID, - sporkRootBlockHeight: sporkRootBlockHeight, - nodeRootBlockHeight: nodeRootBlockHeader.Height, + collections: params.Collections, + executionReceipts: params.ExecutionReceipts, + connFactory: params.ConnFactory, + chainID: params.ChainID, + nodeInfo: nodeInfo, } retry.SetBackend(b) @@ -319,25 +312,42 @@ func (b *Backend) Ping(ctx context.Context) error { // GetNodeVersionInfo returns node version information such as semver, commit, sporkID, protocolVersion, etc func (b *Backend) GetNodeVersionInfo(_ context.Context) (*access.NodeVersionInfo, error) { - stateParams := b.state.Params() + return b.nodeInfo, nil +} + +// getNodeVersionInfo returns the NodeVersionInfo for the node. +// Since these values are static while the node is running, it is safe to cache. +func getNodeVersionInfo(stateParams protocol.Params) (*access.NodeVersionInfo, error) { sporkID, err := stateParams.SporkID() if err != nil { - return nil, status.Errorf(codes.Internal, "failed to read spork ID: %v", err) + return nil, fmt.Errorf("failed to read spork ID: %v", err) } protocolVersion, err := stateParams.ProtocolVersion() if err != nil { - return nil, status.Errorf(codes.Internal, "failed to read protocol version: %v", err) + return nil, fmt.Errorf("failed to read protocol version: %v", err) } - return &access.NodeVersionInfo{ + sporkRootBlockHeight, err := stateParams.SporkRootBlockHeight() + if err != nil { + return nil, fmt.Errorf("failed to read spork root block height: %w", err) + } + + nodeRootBlockHeader, err := stateParams.SealedRoot() + if err != nil { + return nil, fmt.Errorf("failed to read node root block: %w", err) + } + + nodeInfo := &access.NodeVersionInfo{ Semver: build.Version(), Commit: build.Commit(), SporkId: sporkID, ProtocolVersion: uint64(protocolVersion), - SporkRootBlockHeight: b.sporkRootBlockHeight, - NodeRootBlockHeight: b.nodeRootBlockHeight, - }, nil + SporkRootBlockHeight: sporkRootBlockHeight, + NodeRootBlockHeight: nodeRootBlockHeader.Height, + } + + return nodeInfo, nil } func (b *Backend) GetCollectionByID(_ context.Context, colID flow.Identifier) (*flow.LightCollection, error) { diff --git a/engine/access/rpc/backend/backend_test.go b/engine/access/rpc/backend/backend_test.go index fea3ea9da2d..87ecc08f715 100644 --- a/engine/access/rpc/backend/backend_test.go +++ b/engine/access/rpc/backend/backend_test.go @@ -72,9 +72,12 @@ func (suite *Suite) SetupTest() { header := unittest.BlockHeaderFixture() params := new(protocol.Params) params.On("FinalizedRoot").Return(header, nil) + params.On("SporkID").Return(unittest.IdentifierFixture(), nil) + params.On("ProtocolVersion").Return(uint(unittest.Uint64InRange(10, 30)), nil) params.On("SporkRootBlockHeight").Return(header.Height, nil) params.On("SealedRoot").Return(header, nil) suite.state.On("Params").Return(params) + suite.blocks = new(storagemock.Blocks) suite.headers = new(storagemock.Headers) suite.transactions = new(storagemock.Transactions) @@ -1367,6 +1370,8 @@ func (suite *Suite) TestGetEventsForHeightRange() { expectedResp := setupExecClient() fixedENIdentifiersStr := flow.IdentifierList(nodeIdentities.NodeIDs()).Strings() + stateParams.On("SporkID").Return(unittest.IdentifierFixture(), nil) + stateParams.On("ProtocolVersion").Return(uint(unittest.Uint64InRange(10, 30)), nil) stateParams.On("SporkRootBlockHeight").Return(headHeight, nil) stateParams.On("SealedRoot").Return(head, nil) @@ -1394,6 +1399,8 @@ func (suite *Suite) TestGetEventsForHeightRange() { expectedResp := setupExecClient() fixedENIdentifiersStr := flow.IdentifierList(nodeIdentities.NodeIDs()).Strings() + stateParams.On("SporkID").Return(unittest.IdentifierFixture(), nil) + stateParams.On("ProtocolVersion").Return(uint(unittest.Uint64InRange(10, 30)), nil) stateParams.On("SporkRootBlockHeight").Return(headHeight, nil) stateParams.On("SealedRoot").Return(head, nil) @@ -1594,10 +1601,10 @@ func (suite *Suite) TestGetNodeVersionInfo() { suite.Run("happy path", func() { stateParams := protocol.NewParams(suite.T()) - stateParams.On("SporkRootBlockHeight").Return(sporkRootBlock.Height, nil) - stateParams.On("SealedRoot").Return(nodeRootBlock, nil) stateParams.On("SporkID").Return(sporkID, nil) stateParams.On("ProtocolVersion").Return(protocolVersion, nil) + stateParams.On("SporkRootBlockHeight").Return(sporkRootBlock.Height, nil) + stateParams.On("SealedRoot").Return(nodeRootBlock, nil) state := protocol.NewState(suite.T()) state.On("Params").Return(stateParams, nil).Maybe() @@ -1623,10 +1630,8 @@ func (suite *Suite) TestGetNodeVersionInfo() { suite.Require().Equal(expected, actual) }) - suite.Run("returns Internal error when sporkID lookup fails", func() { + suite.Run("backend construct fails when SporkID lookup fails", func() { stateParams := protocol.NewParams(suite.T()) - stateParams.On("SporkRootBlockHeight").Return(sporkRootBlock.Height, nil) - stateParams.On("SealedRoot").Return(nodeRootBlock, nil) stateParams.On("SporkID").Return(flow.ZeroID, fmt.Errorf("fail")) state := protocol.NewState(suite.T()) @@ -1636,18 +1641,12 @@ func (suite *Suite) TestGetNodeVersionInfo() { params.State = state backend, err := New(params) - suite.Require().NoError(err) - - actual, err := backend.GetNodeVersionInfo(context.Background()) - suite.Assert().Error(err) - suite.Assert().Nil(actual) - suite.Assert().Equal(codes.Internal, status.Code(err)) + suite.Require().Error(err) + suite.Require().Nil(backend) }) - suite.Run("returns Internal error when protocolVersion lookup fails", func() { + suite.Run("backend construct fails when ProtocolVersion lookup fails", func() { stateParams := protocol.NewParams(suite.T()) - stateParams.On("SporkRootBlockHeight").Return(sporkRootBlock.Height, nil) - stateParams.On("SealedRoot").Return(nodeRootBlock, nil) stateParams.On("SporkID").Return(sporkID, nil) stateParams.On("ProtocolVersion").Return(uint(0), fmt.Errorf("fail")) @@ -1658,12 +1657,43 @@ func (suite *Suite) TestGetNodeVersionInfo() { params.State = state backend, err := New(params) - suite.Require().NoError(err) + suite.Require().Error(err) + suite.Require().Nil(backend) + }) - actual, err := backend.GetNodeVersionInfo(context.Background()) - suite.Assert().Error(err) - suite.Assert().Nil(actual) - suite.Assert().Equal(codes.Internal, status.Code(err)) + suite.Run("backend construct fails when SporkRootBlockHeight lookup fails", func() { + stateParams := protocol.NewParams(suite.T()) + stateParams.On("SporkID").Return(sporkID, nil) + stateParams.On("ProtocolVersion").Return(protocolVersion, nil) + stateParams.On("SporkRootBlockHeight").Return(uint64(0), fmt.Errorf("fail")) + + state := protocol.NewState(suite.T()) + state.On("Params").Return(stateParams, nil).Maybe() + + params := suite.defaultBackendParams() + params.State = state + + backend, err := New(params) + suite.Require().Error(err) + suite.Require().Nil(backend) + }) + + suite.Run("backend construct fails when SealedRoot lookup fails", func() { + stateParams := protocol.NewParams(suite.T()) + stateParams.On("SporkID").Return(sporkID, nil) + stateParams.On("ProtocolVersion").Return(protocolVersion, nil) + stateParams.On("SporkRootBlockHeight").Return(sporkRootBlock.Height, nil) + stateParams.On("SealedRoot").Return(nil, fmt.Errorf("fail")) + + state := protocol.NewState(suite.T()) + state.On("Params").Return(stateParams, nil).Maybe() + + params := suite.defaultBackendParams() + params.State = state + + backend, err := New(params) + suite.Require().Error(err) + suite.Require().Nil(backend) }) } diff --git a/engine/access/rpc/rate_limit_test.go b/engine/access/rpc/rate_limit_test.go index 50968b7e42c..ce11e556ecb 100644 --- a/engine/access/rpc/rate_limit_test.go +++ b/engine/access/rpc/rate_limit_test.go @@ -78,6 +78,8 @@ func (suite *RateLimitTestSuite) SetupTest() { rootHeader := unittest.BlockHeaderFixture() params := new(protocol.Params) + params.On("SporkID").Return(unittest.IdentifierFixture(), nil) + params.On("ProtocolVersion").Return(uint(unittest.Uint64InRange(10, 30)), nil) params.On("SporkRootBlockHeight").Return(rootHeader.Height, nil) params.On("SealedRoot").Return(rootHeader, nil) diff --git a/engine/access/secure_grpcr_test.go b/engine/access/secure_grpcr_test.go index 664e7e040d0..a5f2ab279cf 100644 --- a/engine/access/secure_grpcr_test.go +++ b/engine/access/secure_grpcr_test.go @@ -72,6 +72,8 @@ func (suite *SecureGRPCTestSuite) SetupTest() { rootHeader := unittest.BlockHeaderFixture() params := new(protocol.Params) + params.On("SporkID").Return(unittest.IdentifierFixture(), nil) + params.On("ProtocolVersion").Return(uint(unittest.Uint64InRange(10, 30)), nil) params.On("SporkRootBlockHeight").Return(rootHeader.Height, nil) params.On("SealedRoot").Return(rootHeader, nil)