-
Notifications
You must be signed in to change notification settings - Fork 183
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
[Storage Refactor] Refactor saving execution results #6906
base: master
Are you sure you want to change the base?
Changes from all commits
0c5345f
f62e8e7
0276508
ae289b8
2be0689
7fee0e6
80b08bf
9c88816
706a76c
56ddcaf
ed6e97d
bb99b85
2fdc19b
23bcaf8
c5c9c9b
e020c45
5c19365
a3aebb1
e20d127
f6fa66b
bd2f97c
f567af3
7bb9546
9251392
ab10668
1ec4e69
eb22e23
1a29adc
1186df0
4ab489d
652756a
185cb28
750bc76
a43a21b
80b7d33
178ec55
9c19a09
2672842
839c717
9297c73
0fbe3a2
e9fe482
b7462c1
dfc9b00
2532b07
598a21a
8eebce7
930aacf
d96a8ce
dedf906
a323c20
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -346,6 +346,11 @@ type FlowAccessNodeBuilder struct { | |
VersionControl *version.VersionControl | ||
StopControl *stop.StopControl | ||
|
||
// storage | ||
events storage.Events | ||
lightTransactionResults storage.LightTransactionResults | ||
transactionResultErrorMessages storage.TransactionResultErrorMessages | ||
|
||
// The sync engine participants provider is the libp2p peer store for the access node | ||
// which is not available until after the network has started. | ||
// Hence, a factory function that needs to be called just before creating the sync engine | ||
|
@@ -872,7 +877,7 @@ func (builder *FlowAccessNodeBuilder) BuildExecutionSyncComponents() *FlowAccess | |
return nil | ||
}). | ||
Module("transaction results storage", func(node *cmd.NodeConfig) error { | ||
builder.Storage.LightTransactionResults = bstorage.NewLightTransactionResults(node.Metrics.Cache, node.DB, bstorage.DefaultCacheSize) | ||
builder.lightTransactionResults = store.NewLightTransactionResults(node.Metrics.Cache, node.ProtocolDB, bstorage.DefaultCacheSize) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
return nil | ||
}). | ||
DependableComponent("execution data indexer", func(node *cmd.NodeConfig) (module.ReadyDoneAware, error) { | ||
|
@@ -961,13 +966,13 @@ func (builder *FlowAccessNodeBuilder) BuildExecutionSyncComponents() *FlowAccess | |
indexerCore, err := indexer.New( | ||
builder.Logger, | ||
metrics.NewExecutionStateIndexerCollector(), | ||
builder.DB, | ||
builder.ProtocolDB, | ||
builder.Storage.RegisterIndex, | ||
builder.Storage.Headers, | ||
builder.Storage.Events, | ||
builder.events, | ||
builder.Storage.Collections, | ||
builder.Storage.Transactions, | ||
builder.Storage.LightTransactionResults, | ||
builder.lightTransactionResults, | ||
builder.RootChainID.Chain(), | ||
indexerDerivedChainData, | ||
builder.collectionExecutedMetric, | ||
|
@@ -1834,19 +1839,19 @@ func (builder *FlowAccessNodeBuilder) Build() (cmd.Node, error) { | |
return nil | ||
}). | ||
Module("events storage", func(node *cmd.NodeConfig) error { | ||
builder.Storage.Events = bstorage.NewEvents(node.Metrics.Cache, node.DB) | ||
builder.events = store.NewEvents(node.Metrics.Cache, node.ProtocolDB) | ||
return nil | ||
}). | ||
Module("reporter", func(node *cmd.NodeConfig) error { | ||
builder.Reporter = index.NewReporter() | ||
return nil | ||
}). | ||
Module("events index", func(node *cmd.NodeConfig) error { | ||
builder.EventsIndex = index.NewEventsIndex(builder.Reporter, builder.Storage.Events) | ||
builder.EventsIndex = index.NewEventsIndex(builder.Reporter, builder.events) | ||
return nil | ||
}). | ||
Module("transaction result index", func(node *cmd.NodeConfig) error { | ||
builder.TxResultsIndex = index.NewTransactionResultsIndex(builder.Reporter, builder.Storage.LightTransactionResults) | ||
builder.TxResultsIndex = index.NewTransactionResultsIndex(builder.Reporter, builder.lightTransactionResults) | ||
return nil | ||
}). | ||
Module("processed finalized block height consumer progress", func(node *cmd.NodeConfig) error { | ||
|
@@ -1870,7 +1875,7 @@ func (builder *FlowAccessNodeBuilder) Build() (cmd.Node, error) { | |
}). | ||
Module("transaction result error messages storage", func(node *cmd.NodeConfig) error { | ||
if builder.storeTxResultErrorMessages { | ||
builder.Storage.TransactionResultErrorMessages = bstorage.NewTransactionResultErrorMessages(node.Metrics.Cache, node.DB, bstorage.DefaultCacheSize) | ||
builder.transactionResultErrorMessages = store.NewTransactionResultErrorMessages(node.Metrics.Cache, node.ProtocolDB, bstorage.DefaultCacheSize) | ||
} | ||
|
||
return nil | ||
|
@@ -2030,7 +2035,7 @@ func (builder *FlowAccessNodeBuilder) Build() (cmd.Node, error) { | |
Transactions: node.Storage.Transactions, | ||
ExecutionReceipts: node.Storage.Receipts, | ||
ExecutionResults: node.Storage.Results, | ||
TxResultErrorMessages: node.Storage.TransactionResultErrorMessages, | ||
TxResultErrorMessages: builder.transactionResultErrorMessages, | ||
ChainID: node.RootChainID, | ||
AccessMetrics: builder.AccessMetrics, | ||
ConnFactory: connFactory, | ||
|
@@ -2116,7 +2121,7 @@ func (builder *FlowAccessNodeBuilder) Build() (cmd.Node, error) { | |
builder.TxResultErrorMessagesCore = tx_error_messages.NewTxErrorMessagesCore( | ||
node.Logger, | ||
builder.nodeBackend, | ||
node.Storage.TransactionResultErrorMessages, | ||
builder.transactionResultErrorMessages, | ||
builder.ExecNodeIdentitiesProvider, | ||
) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,7 +91,7 @@ import ( | |
"github.com/onflow/flow-go/state/protocol/blocktimer" | ||
storageerr "github.com/onflow/flow-go/storage" | ||
storage "github.com/onflow/flow-go/storage/badger" | ||
"github.com/onflow/flow-go/storage/badger/procedure" | ||
"github.com/onflow/flow-go/storage/operation" | ||
"github.com/onflow/flow-go/storage/operation/pebbleimpl" | ||
storagepebble "github.com/onflow/flow-go/storage/pebble" | ||
"github.com/onflow/flow-go/storage/store" | ||
|
@@ -128,17 +128,22 @@ type ExecutionNode struct { | |
|
||
ingestionUnit *engine.Unit | ||
|
||
collector *metrics.ExecutionCollector | ||
executionState state.ExecutionState | ||
followerState protocol.FollowerState | ||
committee hotstuff.DynamicCommittee | ||
ledgerStorage *ledger.Ledger | ||
registerStore *storehouse.RegisterStore | ||
events *storage.Events | ||
serviceEvents *storage.ServiceEvents | ||
txResults *storage.TransactionResults | ||
results *storage.ExecutionResults | ||
myReceipts *storage.MyExecutionReceipts | ||
collector *metrics.ExecutionCollector | ||
executionState state.ExecutionState | ||
followerState protocol.FollowerState | ||
committee hotstuff.DynamicCommittee | ||
ledgerStorage *ledger.Ledger | ||
registerStore *storehouse.RegisterStore | ||
|
||
// storage | ||
events storageerr.Events | ||
serviceEvents storageerr.ServiceEvents | ||
txResults storageerr.TransactionResults | ||
results storageerr.ExecutionResults | ||
receipts storageerr.ExecutionReceipts | ||
myReceipts storageerr.MyExecutionReceipts | ||
commits storageerr.Commits | ||
|
||
providerEngine exeprovider.ProviderEngine | ||
checkerEng *checker.Engine | ||
syncCore *chainsync.Core | ||
|
@@ -202,7 +207,7 @@ func (builder *ExecutionNodeBuilder) LoadComponentsAndModules() { | |
Module("system specs", exeNode.LoadSystemSpecs). | ||
Module("execution metrics", exeNode.LoadExecutionMetrics). | ||
Module("sync core", exeNode.LoadSyncCore). | ||
Module("execution receipts storage", exeNode.LoadExecutionReceiptsStorage). | ||
Module("execution storage", exeNode.LoadExecutionStorage). | ||
Module("follower distributor", exeNode.LoadFollowerDistributor). | ||
Module("authorization checking function", exeNode.LoadAuthorizationCheckingFunction). | ||
Module("execution data datastore", exeNode.LoadExecutionDataDatastore). | ||
|
@@ -279,9 +284,9 @@ func (exeNode *ExecutionNode) LoadExecutionMetrics(node *NodeConfig) error { | |
// report the highest executed block height as soon as possible | ||
// this is guaranteed to exist because LoadBootstrapper has inserted | ||
// the root block as executed block | ||
var height uint64 | ||
var blockID flow.Identifier | ||
err := node.DB.View(procedure.GetLastExecutedBlock(&height, &blockID)) | ||
reader := node.ProtocolDB.Reader() | ||
err := operation.RetrieveExecutedBlock(reader, &blockID) | ||
if err != nil { | ||
// database has not been bootstrapped yet | ||
if errors.Is(err, storageerr.ErrNotFound) { | ||
|
@@ -290,7 +295,12 @@ func (exeNode *ExecutionNode) LoadExecutionMetrics(node *NodeConfig) error { | |
return fmt.Errorf("could not get highest executed block: %w", err) | ||
} | ||
|
||
exeNode.collector.ExecutionLastExecutedBlockHeight(height) | ||
executed, err := node.Storage.Headers.ByBlockID(blockID) | ||
if err != nil { | ||
return fmt.Errorf("could not get header by id: %v: %w", blockID, err) | ||
} | ||
|
||
exeNode.collector.ExecutionLastExecutedBlockHeight(executed.Height) | ||
return nil | ||
} | ||
|
||
|
@@ -300,11 +310,19 @@ func (exeNode *ExecutionNode) LoadSyncCore(node *NodeConfig) error { | |
return err | ||
} | ||
|
||
func (exeNode *ExecutionNode) LoadExecutionReceiptsStorage( | ||
func (exeNode *ExecutionNode) LoadExecutionStorage( | ||
node *NodeConfig, | ||
) error { | ||
exeNode.results = storage.NewExecutionResults(node.Metrics.Cache, node.DB) | ||
exeNode.myReceipts = storage.NewMyExecutionReceipts(node.Metrics.Cache, node.DB, node.Storage.Receipts.(*storage.ExecutionReceipts)) | ||
db := node.ProtocolDB | ||
exeNode.commits = store.NewCommits(node.Metrics.Cache, db) | ||
exeNode.results = store.NewExecutionResults(node.Metrics.Cache, db) | ||
exeNode.receipts = store.NewExecutionReceipts(node.Metrics.Cache, db, exeNode.results, storage.DefaultCacheSize) | ||
exeNode.myReceipts = store.NewMyExecutionReceipts(node.Metrics.Cache, db, exeNode.receipts) | ||
|
||
// Needed for gRPC server, make sure to assign to main scoped vars | ||
exeNode.events = store.NewEvents(node.Metrics.Cache, db) | ||
exeNode.serviceEvents = store.NewServiceEvents(node.Metrics.Cache, db) | ||
exeNode.txResults = store.NewTransactionResults(node.Metrics.Cache, db, exeNode.exeConf.transactionResultsCacheSize) | ||
return nil | ||
} | ||
|
||
|
@@ -438,7 +456,7 @@ func (exeNode *ExecutionNode) LoadGCPBlockDataUploader( | |
retryableUploader := uploader.NewBadgerRetryableUploaderWrapper( | ||
asyncUploader, | ||
node.Storage.Blocks, | ||
node.Storage.Commits, | ||
exeNode.commits, | ||
node.Storage.Collections, | ||
exeNode.events, | ||
exeNode.results, | ||
|
@@ -743,14 +761,18 @@ func (exeNode *ExecutionNode) LoadExecutionState( | |
chunkDataPacks := store.NewChunkDataPacks(node.Metrics.Cache, | ||
pebbleimpl.ToDB(chunkDataPackDB), node.Storage.Collections, exeNode.exeConf.chunkDataPackCacheSize) | ||
|
||
// Needed for gRPC server, make sure to assign to main scoped vars | ||
exeNode.events = storage.NewEvents(node.Metrics.Cache, node.DB) | ||
exeNode.serviceEvents = storage.NewServiceEvents(node.Metrics.Cache, node.DB) | ||
exeNode.txResults = storage.NewTransactionResults(node.Metrics.Cache, node.DB, exeNode.exeConf.transactionResultsCacheSize) | ||
getLatestFinalized := func() (uint64, error) { | ||
final, err := node.State.Final().Head() | ||
if err != nil { | ||
return 0, err | ||
} | ||
|
||
return final.Height, nil | ||
} | ||
|
||
exeNode.executionState = state.NewExecutionState( | ||
exeNode.ledgerStorage, | ||
node.Storage.Commits, | ||
exeNode.commits, | ||
node.Storage.Blocks, | ||
node.Storage.Headers, | ||
node.Storage.Collections, | ||
|
@@ -760,7 +782,8 @@ func (exeNode *ExecutionNode) LoadExecutionState( | |
exeNode.events, | ||
exeNode.serviceEvents, | ||
exeNode.txResults, | ||
node.DB, | ||
node.ProtocolDB, | ||
getLatestFinalized, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is for the execution state to implement getting highest finalized and executed block. |
||
node.Tracer, | ||
exeNode.registerStore, | ||
exeNode.exeConf.enableStorehouse, | ||
|
@@ -1316,7 +1339,7 @@ func (exeNode *ExecutionNode) LoadGrpcServer( | |
exeNode.events, | ||
exeNode.results, | ||
exeNode.txResults, | ||
node.Storage.Commits, | ||
exeNode.commits, | ||
exeNode.metricsProvider, | ||
node.RootChainID, | ||
signature.NewBlockSignerDecoder(exeNode.committee), | ||
|
@@ -1330,7 +1353,7 @@ func (exeNode *ExecutionNode) LoadBootstrapper(node *NodeConfig) error { | |
// check if the execution database already exists | ||
bootstrapper := bootstrap.NewBootstrapper(node.Logger) | ||
|
||
commit, bootstrapped, err := bootstrapper.IsBootstrapped(node.DB) | ||
commit, bootstrapped, err := bootstrapper.IsBootstrapped(node.ProtocolDB) | ||
if err != nil { | ||
return fmt.Errorf("could not query database to know whether database has been bootstrapped: %w", err) | ||
} | ||
|
@@ -1355,7 +1378,7 @@ func (exeNode *ExecutionNode) LoadBootstrapper(node *NodeConfig) error { | |
return fmt.Errorf("could not load bootstrap state from checkpoint file: %w", err) | ||
} | ||
|
||
err = bootstrapper.BootstrapExecutionDatabase(node.DB, node.RootSeal) | ||
err = bootstrapper.BootstrapExecutionDatabase(node.ProtocolDB, node.RootSeal) | ||
if err != nil { | ||
return fmt.Errorf("could not bootstrap execution database: %w", err) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Access node syncs events, transaction results from EN with indexer engine, I'm refactoring them altogether along with the execution node's saving results process.