@@ -346,6 +346,8 @@ type FlowAccessNodeBuilder struct {
346
346
ExecutionDataTracker tracker.Storage
347
347
VersionControl * version.VersionControl
348
348
StopControl * stop.StopControl
349
+ Transactions storage.Transactions
350
+ Collections storage.Collections
349
351
350
352
// The sync engine participants provider is the libp2p peer store for the access node
351
353
// which is not available until after the network has started.
@@ -574,6 +576,14 @@ func (builder *FlowAccessNodeBuilder) BuildExecutionSyncComponents() *FlowAccess
574
576
AdminCommand ("read-execution-data" , func (config * cmd.NodeConfig ) commands.AdminCommand {
575
577
return stateSyncCommands .NewReadExecutionDataCommand (builder .ExecutionDataStore )
576
578
}).
579
+ Module ("transactions and collections storage" , func (node * cmd.NodeConfig ) error {
580
+ // TODO: replace with node.ProtocolDB
581
+ db := badgerimpl .ToDB (node .DB )
582
+ transactions := store .NewTransactions (node .Metrics .Cache , db )
583
+ builder .Collections = store .NewCollections (db , transactions )
584
+ builder .Transactions = transactions
585
+ return nil
586
+ }).
577
587
Module ("execution data datastore and blobstore" , func (node * cmd.NodeConfig ) error {
578
588
datastoreDir := filepath .Join (builder .executionDataDir , "blobstore" )
579
589
err := os .MkdirAll (datastoreDir , 0700 )
@@ -966,8 +976,8 @@ func (builder *FlowAccessNodeBuilder) BuildExecutionSyncComponents() *FlowAccess
966
976
builder .Storage .RegisterIndex ,
967
977
builder .Storage .Headers ,
968
978
builder .Storage .Events ,
969
- builder .Storage . Collections ,
970
- builder .Storage . Transactions ,
979
+ notNil ( builder .Collections ) ,
980
+ notNil ( builder .Transactions ) ,
971
981
builder .Storage .LightTransactionResults ,
972
982
builder .RootChainID .Chain (),
973
983
indexerDerivedChainData ,
@@ -1613,7 +1623,7 @@ func (builder *FlowAccessNodeBuilder) Initialize() error {
1613
1623
builder .EnqueueNetworkInit ()
1614
1624
1615
1625
builder .AdminCommand ("get-transactions" , func (conf * cmd.NodeConfig ) commands.AdminCommand {
1616
- return storageCommands .NewGetTransactionsCommand (conf .State , conf .Storage .Payloads , conf . Storage . Collections )
1626
+ return storageCommands .NewGetTransactionsCommand (conf .State , conf .Storage .Payloads , notNil ( builder . Collections ) )
1617
1627
})
1618
1628
1619
1629
// if this is an access node that supports public followers, enqueue the public network
@@ -2034,8 +2044,8 @@ func (builder *FlowAccessNodeBuilder) Build() (cmd.Node, error) {
2034
2044
HistoricalAccessNodes : builder .HistoricalAccessRPCs ,
2035
2045
Blocks : node .Storage .Blocks ,
2036
2046
Headers : node .Storage .Headers ,
2037
- Collections : node . Storage . Collections ,
2038
- Transactions : node . Storage . Transactions ,
2047
+ Collections : notNil ( builder . Collections ) ,
2048
+ Transactions : notNil ( builder . Transactions ) ,
2039
2049
ExecutionReceipts : node .Storage .Receipts ,
2040
2050
ExecutionResults : node .Storage .Results ,
2041
2051
TxResultErrorMessages : node .Storage .TransactionResultErrorMessages ,
@@ -2137,8 +2147,8 @@ func (builder *FlowAccessNodeBuilder) Build() (cmd.Node, error) {
2137
2147
builder .RequestEng ,
2138
2148
node .Storage .Blocks ,
2139
2149
node .Storage .Headers ,
2140
- node . Storage . Collections ,
2141
- node . Storage . Transactions ,
2150
+ notNil ( builder . Collections ) ,
2151
+ notNil ( builder . Transactions ) ,
2142
2152
node .Storage .Results ,
2143
2153
node .Storage .Receipts ,
2144
2154
builder .collectionExecutedMetric ,
@@ -2384,3 +2394,15 @@ func (builder *FlowAccessNodeBuilder) initPublicLibp2pNode(networkKey crypto.Pri
2384
2394
2385
2395
return libp2pNode , nil
2386
2396
}
2397
+
2398
+ // notNil ensures that the input is not nil and returns it
2399
+ // the usage is to ensure the dependencies are initialized before initializing a module.
2400
+ // for instance, the IngestionEngine depends on storage.Collections, which is initialized in a
2401
+ // different function, so we need to ensure that the storage.Collections is initialized before
2402
+ // creating the IngestionEngine.
2403
+ func notNil [T any ](dep T ) T {
2404
+ if any (dep ) == nil {
2405
+ panic ("dependency is nil" )
2406
+ }
2407
+ return dep
2408
+ }
0 commit comments