Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Access] Add compatible range to Node Version Info endpoint #6294

Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
1b29583
Updated protobuf version, added compatible range to rpc NodeVersionIn…
UlyanaAndrukhiv Aug 5, 2024
030fdb9
Updated backend for NodeVersionInfo, updated rpc handler
UlyanaAndrukhiv Aug 5, 2024
b3d9086
Updated REST endpoint
UlyanaAndrukhiv Aug 5, 2024
afbdcc0
Updated functional test for REST endpoint
UlyanaAndrukhiv Aug 5, 2024
0578781
Updated test
UlyanaAndrukhiv Aug 5, 2024
7d91f26
Updated backend stream transaction test according to changes
UlyanaAndrukhiv Aug 5, 2024
cfcbe4a
Added additional test case for NodeVersionInfo endpoint
UlyanaAndrukhiv Aug 5, 2024
ce0af54
Merge branch 'master' into UlyanaAndrukhiv/6248-compatible-range-to-n…
UlyanaAndrukhiv Aug 6, 2024
1cb26f9
Updated naming according to comment
UlyanaAndrukhiv Aug 6, 2024
9d1648a
Merge branch 'UlyanaAndrukhiv/6248-compatible-range-to-node-version' …
UlyanaAndrukhiv Aug 6, 2024
d88140d
Merge branch 'master' into UlyanaAndrukhiv/6248-compatible-range-to-n…
UlyanaAndrukhiv Aug 8, 2024
69e5d4d
Merge branch 'master' into UlyanaAndrukhiv/6248-compatible-range-to-n…
UlyanaAndrukhiv Aug 9, 2024
e465fdf
Merge branch 'master' into UlyanaAndrukhiv/6248-compatible-range-to-n…
UlyanaAndrukhiv Aug 9, 2024
f7ac659
Updated protobuf and REST versions, moved NodeVersionInfo to model/fl…
UlyanaAndrukhiv Aug 12, 2024
b3fafd3
Merge branch 'UlyanaAndrukhiv/6248-compatible-range-to-node-version' …
UlyanaAndrukhiv Aug 12, 2024
d617224
Merge branch 'master' into UlyanaAndrukhiv/6248-compatible-range-to-n…
UlyanaAndrukhiv Aug 12, 2024
b8471a6
Added lint to integration makefile
UlyanaAndrukhiv Aug 12, 2024
3df9a49
Updated flow-emulator version
UlyanaAndrukhiv Aug 12, 2024
e236969
Merge branch 'master' into UlyanaAndrukhiv/6248-compatible-range-to-n…
UlyanaAndrukhiv Aug 12, 2024
f8a6fc0
Merged with master
UlyanaAndrukhiv Aug 13, 2024
e62d36a
Merge branch 'UlyanaAndrukhiv/6248-compatible-range-to-node-version' …
UlyanaAndrukhiv Aug 13, 2024
0534243
Merge branch 'master' into UlyanaAndrukhiv/6248-compatible-range-to-n…
UlyanaAndrukhiv Aug 15, 2024
b62c43e
Merge branch 'master' into UlyanaAndrukhiv/6248-compatible-range-to-n…
UlyanaAndrukhiv Aug 16, 2024
6155655
Updated protobuf version
UlyanaAndrukhiv Aug 16, 2024
55d2c54
Merge branch 'UlyanaAndrukhiv/6248-compatible-range-to-node-version' …
UlyanaAndrukhiv Aug 16, 2024
22e8b04
Fixed convertion from CompatibleRange to protobuf message
UlyanaAndrukhiv Aug 16, 2024
cc044be
Updated flow-emulator version
UlyanaAndrukhiv Aug 16, 2024
88f3ffe
Updated start height getter logic
UlyanaAndrukhiv Aug 19, 2024
532189e
Merged 2 methods
UlyanaAndrukhiv Aug 19, 2024
5c65f14
Updated EndHeight according to comment
UlyanaAndrukhiv Aug 19, 2024
f0e08af
Removed duplicate implementation
UlyanaAndrukhiv Aug 19, 2024
84ec98e
Added test for CompatibleRangeToMessage
UlyanaAndrukhiv Aug 19, 2024
1304a20
Merge branch 'master' into UlyanaAndrukhiv/6248-compatible-range-to-n…
UlyanaAndrukhiv Aug 20, 2024
0200350
Merge branch 'master' into UlyanaAndrukhiv/6248-compatible-range-to-n…
UlyanaAndrukhiv Aug 21, 2024
e7bf591
Merge branch 'master' of github.com:The-K-R-O-K/flow-go into UlyanaAn…
UlyanaAndrukhiv Aug 26, 2024
b2cb768
Mergerd with master
UlyanaAndrukhiv Aug 26, 2024
834529e
Updated flow-emulator version
UlyanaAndrukhiv Aug 26, 2024
3187556
Merge branch 'master' into UlyanaAndrukhiv/6248-compatible-range-to-n…
UlyanaAndrukhiv Aug 27, 2024
50dcd73
Moved NodeVersionInfo to access module
UlyanaAndrukhiv Aug 27, 2024
7fee253
Updated flow-emulator version
UlyanaAndrukhiv Aug 27, 2024
7b26083
Removed replace for flow-emulator
UlyanaAndrukhiv Aug 28, 2024
28604da
Merge branch 'master' into UlyanaAndrukhiv/6248-compatible-range-to-n…
UlyanaAndrukhiv Aug 28, 2024
00eae08
Merged with master
UlyanaAndrukhiv Aug 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions access/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,14 @@ type NetworkParameters struct {
ChainID flow.ChainID
}

// CompatibleRange contains the first and the last height that the version supports.
type CompatibleRange struct {
// The first block that the version supports.
StartHeight uint64
// The last block that the version supports.
EndHeight uint64
}

// NodeVersionInfo contains information about node, such as semver, commit, sporkID, protocolVersion, etc
type NodeVersionInfo struct {
Semver string
Expand All @@ -272,4 +280,17 @@ type NodeVersionInfo struct {
ProtocolVersion uint64
SporkRootBlockHeight uint64
NodeRootBlockHeight uint64
CompatibleRange *CompatibleRange
}

// CompatibleRangeToMessage converts a flow.CompatibleRange to a protobuf message
func CompatibleRangeToMessage(c *CompatibleRange) *entities.CompatibleRange {
if c != nil {
return &entities.CompatibleRange{
StartHeight: c.StartHeight,
EndHeight: c.EndHeight,
}
}

return nil
}
1 change: 1 addition & 0 deletions access/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ func (h *Handler) GetNodeVersionInfo(
ProtocolVersion: nodeVersionInfo.ProtocolVersion,
SporkRootBlockHeight: nodeVersionInfo.SporkRootBlockHeight,
NodeRootBlockHeight: nodeVersionInfo.NodeRootBlockHeight,
CompatibleRange: CompatibleRangeToMessage(nodeVersionInfo.CompatibleRange),
},
}, nil
}
Expand Down
9 changes: 5 additions & 4 deletions cmd/access/node_builder/access_node_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ type FlowAccessNodeBuilder struct {
ExecutionDataPruner *pruner.Pruner
ExecutionDatastoreManager edstorage.DatastoreManager
ExecutionDataTracker tracker.Storage
versionControl *version.VersionControl
VersionControl *version.VersionControl

// The sync engine participants provider is the libp2p peer store for the access node
// which is not available until after the network has started.
Expand Down Expand Up @@ -978,7 +978,7 @@ func (builder *FlowAccessNodeBuilder) BuildExecutionSyncComponents() *FlowAccess
builder.programCacheSize > 0,
)

err = builder.ScriptExecutor.Initialize(builder.ExecutionIndexer, scripts, builder.versionControl)
err = builder.ScriptExecutor.Initialize(builder.ExecutionIndexer, scripts, builder.VersionControl)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1813,8 +1813,8 @@ func (builder *FlowAccessNodeBuilder) Build() (cmd.Node, error) {
// VersionControl needs to consume BlockFinalized events.
node.ProtocolEvents.AddConsumer(versionControl)

builder.versionControl = versionControl
versionControlDependable.Init(builder.versionControl)
builder.VersionControl = versionControl
versionControlDependable.Init(builder.VersionControl)

return versionControl, nil
}).
Expand Down Expand Up @@ -1921,6 +1921,7 @@ func (builder *FlowAccessNodeBuilder) Build() (cmd.Node, error) {
TxResultQueryMode: txResultQueryMode,
TxResultsIndex: builder.TxResultsIndex,
LastFullBlockHeight: lastFullBlockHeight,
VersionControl: builder.VersionControl,
})
if err != nil {
return nil, fmt.Errorf("could not initialize backend: %w", err)
Expand Down
9 changes: 5 additions & 4 deletions cmd/observer/node_builder/observer_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ type ObserverServiceBuilder struct {
ExecutionIndexerCore *indexer.IndexerCore
TxResultsIndex *index.TransactionResultsIndex
IndexerDependencies *cmd.DependencyList
versionControl *version.VersionControl
VersionControl *version.VersionControl

ExecutionDataDownloader execution_data.Downloader
ExecutionDataRequester state_synchronization.ExecutionDataRequester
Expand Down Expand Up @@ -1513,7 +1513,7 @@ func (builder *ObserverServiceBuilder) BuildExecutionSyncComponents() *ObserverS
builder.programCacheSize > 0,
)

err = builder.ScriptExecutor.Initialize(builder.ExecutionIndexer, scripts, builder.versionControl)
err = builder.ScriptExecutor.Initialize(builder.ExecutionIndexer, scripts, builder.VersionControl)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1854,8 +1854,8 @@ func (builder *ObserverServiceBuilder) enqueueRPCServer() {
// VersionControl needs to consume BlockFinalized events.
node.ProtocolEvents.AddConsumer(versionControl)

builder.versionControl = versionControl
versionControlDependable.Init(builder.versionControl)
builder.VersionControl = versionControl
versionControlDependable.Init(builder.VersionControl)

return versionControl, nil
})
Expand Down Expand Up @@ -1930,6 +1930,7 @@ func (builder *ObserverServiceBuilder) enqueueRPCServer() {
builder.stateStreamConf.ResponseLimit,
builder.stateStreamConf.ClientSendBufferSize,
),
VersionControl: builder.VersionControl,
}

if builder.localServiceAPIEnabled {
Expand Down
5 changes: 0 additions & 5 deletions engine/access/handle_irrecoverable_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,7 @@ func (suite *IrrecoverableStateTestSuite) SetupTest() {
suite.state = protocol.NewState(suite.T())
suite.snapshot = protocol.NewSnapshot(suite.T())

rootHeader := unittest.BlockHeaderFixture()
params := protocol.NewParams(suite.T())
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)

suite.epochQuery = protocol.NewEpochQuery(suite.T())
suite.state.On("Sealed").Return(suite.snapshot, nil).Maybe()
Expand Down
15 changes: 15 additions & 0 deletions engine/access/rest/models/model_compatible_range.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Access API
*
* No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
*
* API version: 1.0.0
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
*/
package models

// A compatible version range.
type CompatibleRange struct {
StartHeight string `json:"start_height"`
EndHeight string `json:"end_height"`
}
13 changes: 7 additions & 6 deletions engine/access/rest/models/model_node_version_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
package models

type NodeVersionInfo struct {
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"`
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"`
CompatibleRange *CompatibleRange `json:"compatible_range,omitempty"`
}
7 changes: 7 additions & 0 deletions engine/access/rest/models/node_version_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,11 @@ func (t *NodeVersionInfo) Build(params *access.NodeVersionInfo) {
t.ProtocolVersion = util.FromUint(params.ProtocolVersion)
t.SporkRootBlockHeight = util.FromUint(params.SporkRootBlockHeight)
t.NodeRootBlockHeight = util.FromUint(params.NodeRootBlockHeight)

if params.CompatibleRange != nil {
t.CompatibleRange = &CompatibleRange{
StartHeight: util.FromUint(params.CompatibleRange.StartHeight),
EndHeight: util.FromUint(params.CompatibleRange.EndHeight),
}
}
}
20 changes: 18 additions & 2 deletions engine/access/rest/routes/node_version_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,19 @@ func TestGetNodeVersionInfo(t *testing.T) {
t.Run("get node version info", func(t *testing.T) {
req := getNodeVersionInfoRequest(t)

nodeRootBlockHeight := unittest.Uint64InRange(10_000, 100_000)

params := &access.NodeVersionInfo{
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),
NodeRootBlockHeight: nodeRootBlockHeight,
CompatibleRange: &access.CompatibleRange{
StartHeight: nodeRootBlockHeight,
EndHeight: uint64(0),
},
}

backend.Mock.
Expand All @@ -49,20 +55,30 @@ func TestGetNodeVersionInfo(t *testing.T) {
}

func nodeVersionInfoExpectedStr(nodeVersionInfo *access.NodeVersionInfo) string {
compatibleRange := fmt.Sprintf(`"compatible_range": {
"start_height": "%d",
"end_height": "%d"
}`,
nodeVersionInfo.CompatibleRange.StartHeight,
nodeVersionInfo.CompatibleRange.EndHeight,
)

return fmt.Sprintf(`{
"semver": "%s",
"commit": "%s",
"spork_id": "%s",
"protocol_version": "%d",
"spork_root_block_height": "%d",
"node_root_block_height": "%d"
"node_root_block_height": "%d",
%s
}`,
nodeVersionInfo.Semver,
nodeVersionInfo.Commit,
nodeVersionInfo.SporkId.String(),
nodeVersionInfo.ProtocolVersion,
nodeVersionInfo.SporkRootBlockHeight,
nodeVersionInfo.NodeRootBlockHeight,
compatibleRange,
)
}

Expand Down
39 changes: 22 additions & 17 deletions engine/access/rpc/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/onflow/flow-go/engine/access/rpc/connection"
"github.com/onflow/flow-go/engine/access/subscription"
"github.com/onflow/flow-go/engine/common/rpc"
"github.com/onflow/flow-go/engine/common/version"
"github.com/onflow/flow-go/fvm/blueprints"
"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/model/flow/filter"
Expand Down Expand Up @@ -81,9 +82,9 @@ type Backend struct {
executionReceipts storage.ExecutionReceipts
connFactory connection.ConnectionFactory

// cache the response to GetNodeVersionInfo since it doesn't change
nodeInfo *access.NodeVersionInfo
BlockTracker subscription.BlockTracker
BlockTracker subscription.BlockTracker
stateParams protocol.Params
versionControl *version.VersionControl
}

type Params struct {
Expand Down Expand Up @@ -119,6 +120,7 @@ type Params struct {
TxResultQueryMode IndexQueryMode
TxResultsIndex *index.TransactionResultsIndex
LastFullBlockHeight *counters.PersistentStrictMonotonicCounter
VersionControl *version.VersionControl
}

var _ TransactionErrorMessage = (*Backend)(nil)
Expand Down Expand Up @@ -162,9 +164,6 @@ func New(params Params) (*Backend, error) {
}
systemTxID := systemTx.ID()

// initialize node version info
nodeInfo := getNodeVersionInfo(params.State.Params())

transactionsLocalDataProvider := &TransactionsLocalDataProvider{
state: params.State,
collections: params.Collections,
Expand Down Expand Up @@ -243,7 +242,8 @@ func New(params Params) (*Backend, error) {
executionReceipts: params.ExecutionReceipts,
connFactory: params.ConnFactory,
chainID: params.ChainID,
nodeInfo: nodeInfo,
stateParams: params.State.Params(),
versionControl: params.VersionControl,
}

txValidator, err := configureTransactionValidator(params.State, params.ChainID, params.ScriptExecutor, params.CheckPayerBalance)
Expand Down Expand Up @@ -344,17 +344,21 @@ 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) {
return b.nodeInfo, nil
}
sporkID := b.stateParams.SporkID()
protocolVersion := b.stateParams.ProtocolVersion()
sporkRootBlockHeight := b.stateParams.SporkRootBlockHeight()

nodeRootBlockHeader := b.stateParams.SealedRoot()

// 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 {
sporkID := stateParams.SporkID()
protocolVersion := stateParams.ProtocolVersion()
sporkRootBlockHeight := stateParams.SporkRootBlockHeight()
var compatibleRange *access.CompatibleRange

nodeRootBlockHeader := stateParams.SealedRoot()
// Version control feature could be disabled
if b.versionControl != nil {
compatibleRange = &access.CompatibleRange{
StartHeight: b.versionControl.StartHeight(),
EndHeight: b.versionControl.EndHeight(),
}
}

nodeInfo := &access.NodeVersionInfo{
Semver: build.Version(),
Expand All @@ -363,9 +367,10 @@ func getNodeVersionInfo(stateParams protocol.Params) *access.NodeVersionInfo {
ProtocolVersion: uint64(protocolVersion),
SporkRootBlockHeight: sporkRootBlockHeight,
NodeRootBlockHeight: nodeRootBlockHeader.Height,
CompatibleRange: compatibleRange,
}

return nodeInfo
return nodeInfo, nil
}

func (b *Backend) GetCollectionByID(_ context.Context, colID flow.Identifier) (*flow.LightCollection, error) {
Expand Down
14 changes: 0 additions & 14 deletions engine/access/rpc/backend/backend_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"google.golang.org/grpc/status"

"github.com/onflow/flow-go/access"
"github.com/onflow/flow-go/cmd/build"
"github.com/onflow/flow-go/engine/common/rpc/convert"
"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/state/protocol"
Expand Down Expand Up @@ -51,19 +50,6 @@ func (b *backendNetwork) GetNetworkParameters(_ context.Context) access.NetworkP
}
}

func (b *backendNetwork) GetNodeVersionInfo(_ context.Context) (*access.NodeVersionInfo, error) {
UlyanaAndrukhiv marked this conversation as resolved.
Show resolved Hide resolved
stateParams := b.state.Params()
sporkId := stateParams.SporkID()
protocolVersion := stateParams.ProtocolVersion()

return &access.NodeVersionInfo{
Semver: build.Version(),
Commit: build.Commit(),
SporkId: sporkId,
ProtocolVersion: uint64(protocolVersion),
}, nil
}

// GetLatestProtocolStateSnapshot returns the latest finalized snapshot.
func (b *backendNetwork) GetLatestProtocolStateSnapshot(_ context.Context) ([]byte, error) {
snapshot := b.state.Final()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,7 @@ func (s *TransactionStatusSuite) SetupTest() {
s.tempSnapshot = &protocol.Snapshot{}
s.db, s.dbDir = unittest.TempBadgerDB(s.T())

header := unittest.BlockHeaderFixture()

params := protocol.NewParams(s.T())
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)
s.state.On("Params").Return(params)

s.blocks = storagemock.NewBlocks(s.T())
Expand Down
Loading
Loading