Skip to content

Commit a5f43fb

Browse files
committed
Merge branch 'master' into leo/refactor-storage-collections-for-an
2 parents 208fb81 + 93369df commit a5f43fb

File tree

546 files changed

+16383
-7444
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

546 files changed

+16383
-7444
lines changed

.github/workflows/flaky-test-monitor.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobs:
5555
matrix:
5656
targets: ${{ fromJSON(needs.create-dynamic-test-matrix.outputs.dynamic-matrix)}}
5757
# need to set image explicitly due to GitHub logging issue as described in https://github.com/onflow/flow-go/pull/3087#issuecomment-1234383202
58-
runs-on: ubuntu-20.04
58+
runs-on: ubuntu-latest
5959
steps:
6060
- name: Checkout repo
6161
uses: actions/checkout@v4

access/api.go

+28-34
Original file line numberDiff line numberDiff line change
@@ -203,41 +203,20 @@ type API interface {
203203
//
204204
// If invalid parameters will be supplied SubscribeBlockDigestsFromLatest will return a failed subscription.
205205
SubscribeBlockDigestsFromLatest(ctx context.Context, blockStatus flow.BlockStatus) subscription.Subscription
206-
// SubscribeTransactionStatusesFromStartBlockID subscribes to transaction status updates for a given transaction ID.
207-
// Monitoring begins from the specified block ID. The subscription streams status updates until the transaction
208-
// reaches a final state (TransactionStatusSealed or TransactionStatusExpired). When the transaction reaches one of
209-
// these final statuses, the subscription will automatically terminate.
206+
// SubscribeTransactionStatuses subscribes to transaction status updates for a given transaction ID. Monitoring starts
207+
// from the latest block to obtain the current transaction status. If the transaction is already in the final state
208+
// ([flow.TransactionStatusSealed] or [flow.TransactionStatusExpired]), all statuses will be prepared and sent to the client
209+
// sequentially. If the transaction is not in the final state, the subscription will stream status updates until the transaction
210+
// reaches the final state. Once a final state is reached, the subscription will automatically terminate.
210211
//
211212
// Parameters:
212-
// - ctx: The context to manage the subscription's lifecycle, including cancellation.
213-
// - txID: The identifier of the transaction to monitor.
214-
// - startBlockID: The block ID from which to start monitoring.
215-
// - requiredEventEncodingVersion: The version of event encoding required for the subscription.
216-
SubscribeTransactionStatusesFromStartBlockID(ctx context.Context, txID flow.Identifier, startBlockID flow.Identifier, requiredEventEncodingVersion entities.EventEncodingVersion) subscription.Subscription
217-
// SubscribeTransactionStatusesFromStartHeight subscribes to transaction status updates for a given transaction ID.
218-
// Monitoring begins from the specified block height. The subscription streams status updates until the transaction
219-
// reaches a final state (TransactionStatusSealed or TransactionStatusExpired). When the transaction reaches one of
220-
// these final statuses, the subscription will automatically terminate.
221-
//
222-
// Parameters:
223-
// - ctx: The context to manage the subscription's lifecycle, including cancellation.
213+
// - ctx: Context to manage the subscription's lifecycle, including cancellation.
224214
// - txID: The unique identifier of the transaction to monitor.
225-
// - startHeight: The block height from which to start monitoring.
226215
// - requiredEventEncodingVersion: The version of event encoding required for the subscription.
227-
SubscribeTransactionStatusesFromStartHeight(ctx context.Context, txID flow.Identifier, startHeight uint64, requiredEventEncodingVersion entities.EventEncodingVersion) subscription.Subscription
228-
// SubscribeTransactionStatusesFromLatest subscribes to transaction status updates for a given transaction ID.
229-
// Monitoring begins from the latest block. The subscription streams status updates until the transaction
230-
// reaches a final state (TransactionStatusSealed or TransactionStatusExpired). When the transaction reaches one of
231-
// these final statuses, the subscription will automatically terminate.
232-
//
233-
// Parameters:
234-
// - ctx: The context to manage the subscription's lifecycle, including cancellation.
235-
// - txID: The unique identifier of the transaction to monitor.
236-
// - requiredEventEncodingVersion: The version of event encoding required for the subscription.
237-
SubscribeTransactionStatusesFromLatest(ctx context.Context, txID flow.Identifier, requiredEventEncodingVersion entities.EventEncodingVersion) subscription.Subscription
238-
// SendAndSubscribeTransactionStatuses sends a transaction to the network and subscribes to its status updates.
216+
SubscribeTransactionStatuses(ctx context.Context, txID flow.Identifier, requiredEventEncodingVersion entities.EventEncodingVersion) subscription.Subscription
217+
// SendAndSubscribeTransactionStatuses sends a transaction to the execution node and subscribes to its status updates.
239218
// Monitoring begins from the reference block saved in the transaction itself and streams status updates until the transaction
240-
// reaches a final state (TransactionStatusSealed or TransactionStatusExpired). Once a final status is reached, the subscription
219+
// reaches the final state ([flow.TransactionStatusSealed] or [flow.TransactionStatusExpired]). Once the final status has been reached, the subscription
241220
// automatically terminates.
242221
//
243222
// Parameters:
@@ -261,6 +240,14 @@ type TransactionResult struct {
261240
BlockHeight uint64
262241
}
263242

243+
func (r *TransactionResult) IsExecuted() bool {
244+
return r.Status == flow.TransactionStatusExecuted || r.Status == flow.TransactionStatusSealed
245+
}
246+
247+
func (r *TransactionResult) IsFinal() bool {
248+
return r.Status == flow.TransactionStatusSealed || r.Status == flow.TransactionStatusExpired
249+
}
250+
264251
func TransactionResultToMessage(result *TransactionResult) *access.TransactionResultResponse {
265252
return &access.TransactionResultResponse{
266253
Status: entities.TransactionStatus(result.Status),
@@ -314,10 +301,17 @@ type CompatibleRange struct {
314301

315302
// NodeVersionInfo contains information about node, such as semver, commit, sporkID, protocolVersion, etc
316303
type NodeVersionInfo struct {
317-
Semver string
318-
Commit string
319-
SporkId flow.Identifier
320-
ProtocolVersion uint64
304+
Semver string
305+
Commit string
306+
SporkId flow.Identifier
307+
// ProtocolVersion is the deprecated protocol version number.
308+
// Deprecated: Previously this referred to the major software version as of the most recent spork.
309+
// Replaced by protocol_state_version.
310+
ProtocolVersion uint64
311+
// ProtocolStateVersion is the Protocol State version as of the latest finalized block.
312+
// This tracks the schema version of the Protocol State and is used to coordinate breaking changes in the Protocol.
313+
// Version numbers are monotonically increasing.
314+
ProtocolStateVersion uint64
321315
SporkRootBlockHeight uint64
322316
NodeRootBlockHeight uint64
323317
CompatibleRange *CompatibleRange

access/handler.go

+1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ func (h *Handler) GetNodeVersionInfo(
9898
Commit: nodeVersionInfo.Commit,
9999
SporkId: nodeVersionInfo.SporkId[:],
100100
ProtocolVersion: nodeVersionInfo.ProtocolVersion,
101+
ProtocolStateVersion: nodeVersionInfo.ProtocolStateVersion,
101102
SporkRootBlockHeight: nodeVersionInfo.SporkRootBlockHeight,
102103
NodeRootBlockHeight: nodeVersionInfo.NodeRootBlockHeight,
103104
CompatibleRange: CompatibleRangeToMessage(nodeVersionInfo.CompatibleRange),

access/mock/api.go

+3-43
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

admin/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,8 @@ curl localhost:9002/admin/run_command -H 'Content-Type: application/json' -d '{"
120120
```
121121
curl localhost:9002/admin/run_command -H 'Content-Type: application/json' -d '{"commandName": "backfill-tx-error-messages", "data": { "start-height": 340, "end-height": 343, "execution-node-ids":["ec7b934df29248d574ae1cc33ae77f22f0fcf96a79e009224c46374d1837824e", "8cbdc8d24a28899a33140cb68d4146cd6f2f6c18c57f54c299f26351d126919e"] }}'
122122
```
123+
124+
### Trigger chunk data pack pebble database checkpoint
125+
```
126+
curl localhost:9002/admin/run_command -H 'Content-Type: application/json' -d '{"commandName": "create-chunk-data-packs-checkpoint" }'
127+
```

admin/commands/storage/backfill_tx_error_messages.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"github.com/onflow/flow-go/admin"
88
"github.com/onflow/flow-go/admin/commands"
99
"github.com/onflow/flow-go/engine/access/ingestion/tx_error_messages"
10-
commonrpc "github.com/onflow/flow-go/engine/common/rpc"
1110
"github.com/onflow/flow-go/model/flow"
1211
"github.com/onflow/flow-go/model/flow/filter"
1312
"github.com/onflow/flow-go/state/protocol"
@@ -177,7 +176,7 @@ func (b *BackfillTxErrorMessagesCommand) parseExecutionNodeIds(executionNodeIdsI
177176
if len(executionNodeIds) == 0 {
178177
return nil, admin.NewInvalidAdminReqParameterError("execution-node-ids", "must be a non empty list of strings", executionNodeIdsIn)
179178
}
180-
requestedENIdentifiers, err := commonrpc.IdentifierList(executionNodeIds)
179+
requestedENIdentifiers, err := flow.IdentifierListFromHex(executionNodeIds)
181180
if err != nil {
182181
return nil, admin.NewInvalidAdminReqParameterError("execution-node-ids", err.Error(), executionNodeIdsIn)
183182
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package storage
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"path"
7+
"time"
8+
9+
"github.com/cockroachdb/pebble"
10+
"github.com/rs/zerolog/log"
11+
12+
"github.com/onflow/flow-go/admin"
13+
"github.com/onflow/flow-go/admin/commands"
14+
)
15+
16+
var _ commands.AdminCommand = (*ChunksCheckpointCommand)(nil)
17+
18+
// ChunksCheckpointCommand creates a checkpoint for pebble database for querying the data
19+
// while keeping the node alive.
20+
type ChunksCheckpointCommand struct {
21+
checkpointDir string
22+
chunkDataPacks *pebble.DB
23+
}
24+
25+
func NewChunksCheckpointCommand(dir string, chunkDataPacks *pebble.DB) commands.AdminCommand {
26+
return &ChunksCheckpointCommand{
27+
checkpointDir: dir,
28+
chunkDataPacks: chunkDataPacks,
29+
}
30+
}
31+
32+
func (c *ChunksCheckpointCommand) Handler(ctx context.Context, req *admin.CommandRequest) (interface{}, error) {
33+
log.Info().Msgf("admintool: creating chunkDataPacks database checkpoint")
34+
35+
targetDir := nextTmpFolder(c.checkpointDir)
36+
37+
log.Info().Msgf("admintool: creating chunkDataPacks database checkpoint at: %v", targetDir)
38+
39+
err := c.chunkDataPacks.Checkpoint(targetDir)
40+
if err != nil {
41+
return nil, admin.NewInvalidAdminReqErrorf("failed to create checkpoint at %v: %w", targetDir, err)
42+
}
43+
44+
log.Info().Msgf("admintool: successfully created chunkDataPacks database checkpoint at: %v", targetDir)
45+
46+
return fmt.Sprintf("successfully created chunkDataPacks db checkpoint at %v", targetDir), nil
47+
}
48+
49+
func (c *ChunksCheckpointCommand) Validator(req *admin.CommandRequest) error {
50+
return nil
51+
}
52+
53+
func nextTmpFolder(dir string) string {
54+
// use timestamp as folder name
55+
folderName := time.Now().Format("2006-01-02_15-04-05")
56+
return path.Join(dir, folderName)
57+
}

cmd/access/node_builder/access_node_builder.go

+23-14
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,11 @@ type FlowAccessNodeBuilder struct {
349349
Transactions storage.Transactions
350350
Collections storage.Collections
351351

352+
// storage
353+
events storage.Events
354+
lightTransactionResults storage.LightTransactionResults
355+
transactionResultErrorMessages storage.TransactionResultErrorMessages
356+
352357
// The sync engine participants provider is the libp2p peer store for the access node
353358
// which is not available until after the network has started.
354359
// Hence, a factory function that needs to be called just before creating the sync engine
@@ -597,7 +602,9 @@ func (builder *FlowAccessNodeBuilder) BuildExecutionSyncComponents() *FlowAccess
597602
}
598603

599604
if executionDataDBMode == execution_data.ExecutionDataDBModePebble {
600-
builder.ExecutionDatastoreManager, err = edstorage.NewPebbleDatastoreManager(datastoreDir, nil)
605+
builder.ExecutionDatastoreManager, err = edstorage.NewPebbleDatastoreManager(
606+
node.Logger.With().Str("pebbledb", "endata").Logger(),
607+
datastoreDir, nil)
601608
if err != nil {
602609
return fmt.Errorf("could not create PebbleDatastoreManager for execution data: %w", err)
603610
}
@@ -883,15 +890,17 @@ func (builder *FlowAccessNodeBuilder) BuildExecutionSyncComponents() *FlowAccess
883890
return nil
884891
}).
885892
Module("transaction results storage", func(node *cmd.NodeConfig) error {
886-
builder.Storage.LightTransactionResults = bstorage.NewLightTransactionResults(node.Metrics.Cache, node.DB, bstorage.DefaultCacheSize)
893+
builder.lightTransactionResults = store.NewLightTransactionResults(node.Metrics.Cache, node.ProtocolDB, bstorage.DefaultCacheSize)
887894
return nil
888895
}).
889896
DependableComponent("execution data indexer", func(node *cmd.NodeConfig) (module.ReadyDoneAware, error) {
890897
// Note: using a DependableComponent here to ensure that the indexer does not block
891898
// other components from starting while bootstrapping the register db since it may
892899
// take hours to complete.
893900

894-
pdb, err := pstorage.OpenRegisterPebbleDB(builder.registersDBPath)
901+
pdb, err := pstorage.OpenRegisterPebbleDB(
902+
node.Logger.With().Str("pebbledb", "registers").Logger(),
903+
builder.registersDBPath)
895904
if err != nil {
896905
return nil, fmt.Errorf("could not open registers db: %w", err)
897906
}
@@ -972,13 +981,13 @@ func (builder *FlowAccessNodeBuilder) BuildExecutionSyncComponents() *FlowAccess
972981
indexerCore, err := indexer.New(
973982
builder.Logger,
974983
metrics.NewExecutionStateIndexerCollector(),
975-
builder.DB,
984+
builder.ProtocolDB,
976985
builder.Storage.RegisterIndex,
977986
builder.Storage.Headers,
978-
builder.Storage.Events,
987+
notNil(builder.events),
979988
notNil(builder.Collections),
980989
notNil(builder.Transactions),
981-
builder.Storage.LightTransactionResults,
990+
notNil(builder.lightTransactionResults),
982991
builder.RootChainID.Chain(),
983992
indexerDerivedChainData,
984993
builder.collectionExecutedMetric,
@@ -1852,19 +1861,19 @@ func (builder *FlowAccessNodeBuilder) Build() (cmd.Node, error) {
18521861
return nil
18531862
}).
18541863
Module("events storage", func(node *cmd.NodeConfig) error {
1855-
builder.Storage.Events = bstorage.NewEvents(node.Metrics.Cache, node.DB)
1864+
builder.events = store.NewEvents(node.Metrics.Cache, node.ProtocolDB)
18561865
return nil
18571866
}).
18581867
Module("reporter", func(node *cmd.NodeConfig) error {
18591868
builder.Reporter = index.NewReporter()
18601869
return nil
18611870
}).
18621871
Module("events index", func(node *cmd.NodeConfig) error {
1863-
builder.EventsIndex = index.NewEventsIndex(builder.Reporter, builder.Storage.Events)
1872+
builder.EventsIndex = index.NewEventsIndex(builder.Reporter, builder.events)
18641873
return nil
18651874
}).
18661875
Module("transaction result index", func(node *cmd.NodeConfig) error {
1867-
builder.TxResultsIndex = index.NewTransactionResultsIndex(builder.Reporter, builder.Storage.LightTransactionResults)
1876+
builder.TxResultsIndex = index.NewTransactionResultsIndex(builder.Reporter, builder.lightTransactionResults)
18681877
return nil
18691878
}).
18701879
Module("processed finalized block height consumer progress", func(node *cmd.NodeConfig) error {
@@ -1888,7 +1897,7 @@ func (builder *FlowAccessNodeBuilder) Build() (cmd.Node, error) {
18881897
}).
18891898
Module("transaction result error messages storage", func(node *cmd.NodeConfig) error {
18901899
if builder.storeTxResultErrorMessages {
1891-
builder.Storage.TransactionResultErrorMessages = bstorage.NewTransactionResultErrorMessages(node.Metrics.Cache, node.DB, bstorage.DefaultCacheSize)
1900+
builder.transactionResultErrorMessages = store.NewTransactionResultErrorMessages(node.Metrics.Cache, node.ProtocolDB, bstorage.DefaultCacheSize)
18921901
}
18931902

18941903
return nil
@@ -2020,12 +2029,12 @@ func (builder *FlowAccessNodeBuilder) Build() (cmd.Node, error) {
20202029

20212030
}
20222031

2023-
preferredENIdentifiers, err := commonrpc.IdentifierList(backendConfig.PreferredExecutionNodeIDs)
2032+
preferredENIdentifiers, err := flow.IdentifierListFromHex(backendConfig.PreferredExecutionNodeIDs)
20242033
if err != nil {
20252034
return nil, fmt.Errorf("failed to convert node id string to Flow Identifier for preferred EN map: %w", err)
20262035
}
20272036

2028-
fixedENIdentifiers, err := commonrpc.IdentifierList(backendConfig.FixedExecutionNodeIDs)
2037+
fixedENIdentifiers, err := flow.IdentifierListFromHex(backendConfig.FixedExecutionNodeIDs)
20292038
if err != nil {
20302039
return nil, fmt.Errorf("failed to convert node id string to Flow Identifier for fixed EN map: %w", err)
20312040
}
@@ -2048,7 +2057,7 @@ func (builder *FlowAccessNodeBuilder) Build() (cmd.Node, error) {
20482057
Transactions: notNil(builder.Transactions),
20492058
ExecutionReceipts: node.Storage.Receipts,
20502059
ExecutionResults: node.Storage.Results,
2051-
TxResultErrorMessages: node.Storage.TransactionResultErrorMessages,
2060+
TxResultErrorMessages: builder.transactionResultErrorMessages,
20522061
ChainID: node.RootChainID,
20532062
AccessMetrics: builder.AccessMetrics,
20542063
ConnFactory: connFactory,
@@ -2134,7 +2143,7 @@ func (builder *FlowAccessNodeBuilder) Build() (cmd.Node, error) {
21342143
builder.TxResultErrorMessagesCore = tx_error_messages.NewTxErrorMessagesCore(
21352144
node.Logger,
21362145
builder.nodeBackend,
2137-
node.Storage.TransactionResultErrorMessages,
2146+
builder.transactionResultErrorMessages,
21382147
builder.ExecNodeIdentitiesProvider,
21392148
)
21402149
}

0 commit comments

Comments
 (0)