Skip to content

[Access] Refactor storage collections for access node #7093

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

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
eca55cd
refactor collections
zhangchiqing Feb 18, 2025
fde54c9
update execution builder to use store.collections
zhangchiqing Feb 18, 2025
a109af6
refactor collection node to read collections
zhangchiqing Feb 19, 2025
f326355
revert collection changes
zhangchiqing Feb 19, 2025
435b991
adding lock to protect indexing collections
zhangchiqing Feb 19, 2025
6cd812c
add concurrent test
zhangchiqing Feb 19, 2025
208fb81
refactor access node's transactions and collections storage module
zhangchiqing Feb 25, 2025
a5f43fb
Merge branch 'master' into leo/refactor-storage-collections-for-an
zhangchiqing Mar 6, 2025
705399d
refactor using protocoldb
zhangchiqing Mar 7, 2025
b70d475
making collections and transactions private
zhangchiqing Mar 7, 2025
5013f21
Merge branch 'master' into leo/refactor-storage-collections-for-an
zhangchiqing Mar 10, 2025
3287ed1
fix lint
zhangchiqing Mar 10, 2025
07288a9
update collections.Remove
zhangchiqing Mar 10, 2025
f38988b
remove collections.StoreLight
zhangchiqing Mar 10, 2025
1a15b10
index collections by txs
zhangchiqing Mar 11, 2025
e4bf8e5
Merge branch 'master' into leo/refactor-storage-collections-for-an
zhangchiqing Mar 13, 2025
99bbf77
update collections operations methods
zhangchiqing Mar 13, 2025
14469d0
refactor collection store and remove methods
zhangchiqing Mar 13, 2025
db502ad
refactor StoreLightAndIndexByTransaction
zhangchiqing Mar 13, 2025
35692d7
remove unused collections operations
zhangchiqing Mar 13, 2025
127859b
update mocks
zhangchiqing Mar 13, 2025
cbb01aa
add UpertCollection methods
zhangchiqing Mar 13, 2025
311b44b
refactor StoreLightAndIndexByTransaction
zhangchiqing Mar 13, 2025
a9c3140
add TODO
zhangchiqing Mar 13, 2025
6ab6b8c
Merge branch 'master' into leo/refactor-storage-collections-for-an
zhangchiqing Apr 1, 2025
7053720
use notNil for modules initialized by access builder
zhangchiqing Apr 4, 2025
2267d64
Merge branch 'master' into leo/refactor-storage-collections-for-an
zhangchiqing Apr 4, 2025
e1455ee
collection rpc might be nil
zhangchiqing Apr 4, 2025
a77dede
fix builder
zhangchiqing Apr 4, 2025
509efe7
update comments for store collections/transactions
zhangchiqing Apr 10, 2025
dab7142
fix access node builder
zhangchiqing Apr 10, 2025
2bd20e8
add TestTransactionRemove tests
zhangchiqing Apr 16, 2025
80a2eaf
add withRemove to store/cache
zhangchiqing Apr 16, 2025
57e4c8e
Merge branch 'master' into leo/refactor-storage-collections-for-an
zhangchiqing Apr 17, 2025
d343b5c
remove collections.StoreLight
zhangchiqing Apr 17, 2025
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
43 changes: 33 additions & 10 deletions cmd/access/node_builder/access_node_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,8 @@ type FlowAccessNodeBuilder struct {
events storage.Events
lightTransactionResults storage.LightTransactionResults
transactionResultErrorMessages storage.TransactionResultErrorMessages
transactions storage.Transactions
collections storage.Collections

// 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 @@ -575,6 +577,15 @@ func (builder *FlowAccessNodeBuilder) BuildExecutionSyncComponents() *FlowAccess
AdminCommand("read-execution-data", func(config *cmd.NodeConfig) commands.AdminCommand {
return stateSyncCommands.NewReadExecutionDataCommand(builder.ExecutionDataStore)
}).
Module("transactions and collections storage", func(node *cmd.NodeConfig) error {
// TODO: needs to be wrapped with ChainedCollections module, otherwise once we switch
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Link the issue as TODO here #6523 (comment) .

Will be addressed separately. We can review and approve this PR, but not merge until the TODO is completed.

cc @fxamacker

// ProtocolDB to pebble based storage, the data previously stored in badger will not be
// accessable.
transactions := store.NewTransactions(node.Metrics.Cache, node.ProtocolDB)
builder.collections = store.NewCollections(node.ProtocolDB, transactions)
builder.transactions = transactions
return nil
}).
Module("execution data datastore and blobstore", func(node *cmd.NodeConfig) error {
datastoreDir := filepath.Join(builder.executionDataDir, "blobstore")
err := os.MkdirAll(datastoreDir, 0700)
Expand Down Expand Up @@ -956,10 +967,10 @@ func (builder *FlowAccessNodeBuilder) BuildExecutionSyncComponents() *FlowAccess
builder.ProtocolDB,
builder.Storage.RegisterIndex,
builder.Storage.Headers,
builder.events,
builder.Storage.Collections,
builder.Storage.Transactions,
builder.lightTransactionResults,
notNil(builder.events),
notNil(builder.collections),
notNil(builder.transactions),
notNil(builder.lightTransactionResults),
builder.RootChainID.Chain(),
indexerDerivedChainData,
builder.collectionExecutedMetric,
Expand Down Expand Up @@ -1618,7 +1629,7 @@ func (builder *FlowAccessNodeBuilder) Initialize() error {
builder.EnqueueNetworkInit()

builder.AdminCommand("get-transactions", func(conf *cmd.NodeConfig) commands.AdminCommand {
return storageCommands.NewGetTransactionsCommand(conf.State, conf.Storage.Payloads, conf.Storage.Collections)
return storageCommands.NewGetTransactionsCommand(conf.State, conf.Storage.Payloads, notNil(builder.collections))
})

// if this is an access node that supports public followers, enqueue the public network
Expand Down Expand Up @@ -1782,7 +1793,7 @@ func (builder *FlowAccessNodeBuilder) Build() (cmd.Node, error) {
builder.CollectionsToMarkFinalized,
builder.CollectionsToMarkExecuted,
builder.BlocksToMarkExecuted,
builder.Storage.Collections,
builder.collections,
builder.Storage.Blocks,
builder.BlockTransactions,
)
Expand Down Expand Up @@ -2039,8 +2050,8 @@ func (builder *FlowAccessNodeBuilder) Build() (cmd.Node, error) {
HistoricalAccessNodes: builder.HistoricalAccessRPCs,
Blocks: node.Storage.Blocks,
Headers: node.Storage.Headers,
Collections: node.Storage.Collections,
Transactions: node.Storage.Transactions,
Collections: notNil(builder.collections),
Transactions: notNil(builder.transactions),
ExecutionReceipts: node.Storage.Receipts,
ExecutionResults: node.Storage.Results,
TxResultErrorMessages: builder.transactionResultErrorMessages,
Expand Down Expand Up @@ -2142,8 +2153,8 @@ func (builder *FlowAccessNodeBuilder) Build() (cmd.Node, error) {
builder.RequestEng,
node.Storage.Blocks,
node.Storage.Headers,
node.Storage.Collections,
node.Storage.Transactions,
notNil(builder.collections),
notNil(builder.transactions),
node.Storage.Results,
node.Storage.Receipts,
builder.collectionExecutedMetric,
Expand Down Expand Up @@ -2389,3 +2400,15 @@ func (builder *FlowAccessNodeBuilder) initPublicLibp2pNode(networkKey crypto.Pri

return libp2pNode, nil
}

// notNil ensures that the input is not nil and returns it
// the usage is to ensure the dependencies are initialized before initializing a module.
// for instance, the IngestionEngine depends on storage.Collections, which is initialized in a
// different function, so we need to ensure that the storage.Collections is initialized before
// creating the IngestionEngine.
func notNil[T any](dep T) T {
if any(dep) == nil {
panic("dependency is nil")
}
return dep
}
2 changes: 1 addition & 1 deletion cmd/execution_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,10 @@ type ExecutionNode struct {
myReceipts storageerr.MyExecutionReceipts
commits storageerr.Commits
commitsReader storageerr.CommitsReader
collections storageerr.Collections

chunkDataPackDB *pebble.DB
chunkDataPacks storageerr.ChunkDataPacks
collections storageerr.Collections
providerEngine exeprovider.ProviderEngine
checkerEng *checker.Engine
syncCore *chainsync.Core
Expand Down
1 change: 1 addition & 0 deletions cmd/observer/node_builder/observer_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1149,6 +1149,7 @@ func (builder *ObserverServiceBuilder) BuildExecutionSyncComponents() *ObserverS
// Note: progress is stored in the datastore's DB since that is where the jobqueue
// writes execution data to.
db := builder.ExecutionDatastoreManager.DB()

processedNotifications = store.NewConsumerProgress(db, module.ConsumeProgressExecutionDataRequesterNotification)
return nil
}).
Expand Down
87 changes: 87 additions & 0 deletions consensus/hotstuff/mocks/persister_reader.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions storage/collections.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ import (
// Collections represents persistent storage for collections.
type Collections interface {

// StoreLight inserts the collection. It does not insert, nor check
// existence of, the constituent transactions.
StoreLight(collection *flow.LightCollection) error

// Store inserts the collection keyed by ID and all constituent
// transactions.
Store(collection *flow.Collection) error
Expand Down
18 changes: 0 additions & 18 deletions storage/mock/collections.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 57 additions & 0 deletions storage/mock/commits_reader.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading