Skip to content

Commit

Permalink
Merge pull request #6294 from The-K-R-O-K/UlyanaAndrukhiv/6248-compat…
Browse files Browse the repository at this point in the history
…ible-range-to-node-version

 [Access] Add compatible range to Node Version Info endpoint
  • Loading branch information
peterargue authored Aug 29, 2024
2 parents b93c60f + 00eae08 commit 51a9497
Show file tree
Hide file tree
Showing 22 changed files with 289 additions and 77 deletions.
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) {
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
6 changes: 0 additions & 6 deletions engine/access/rpc/backend/backend_stream_transactions_test.go
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

0 comments on commit 51a9497

Please sign in to comment.