-
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?
Conversation
f793dcf
to
51b6fa0
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #6906 +/- ##
==========================================
+ Coverage 41.14% 41.24% +0.10%
==========================================
Files 2133 2141 +8
Lines 187011 188713 +1702
==========================================
+ Hits 76946 77838 +892
- Misses 103622 104363 +741
- Partials 6443 6512 +69
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
7aaf9ae
to
868a31e
Compare
2a5846c
to
e9fe482
Compare
events storage.Events | ||
lightTransactionResults storage.LightTransactionResults | ||
transactionResultErrorMessages storage.TransactionResultErrorMessages |
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.
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
ProtocolDB
is a storage abstraction, so that we can change in a single place to decide using badger or pebble.
@@ -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 comment
The 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.
@@ -179,15 +180,20 @@ func findLastExecutedAndSealedHeight(state protocol.State, db *badger.DB) (uint6 | |||
} | |||
|
|||
var blockID flow.Identifier | |||
var lastExecuted uint64 | |||
err = db.View(procedure.GetLastExecutedBlock(&lastExecuted, &blockID)) |
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.
The GetLastExecutedBlock
procedure is replaced by RetrieveExecutedBlock
which returns only the block ID, and getting the block with protocol State.
} | ||
|
||
// RemoveStateCommitment removes the state commitment by block ID | ||
func RemoveStateCommitment(w storage.Writer, blockID flow.Identifier) error { |
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.
This file is mostly identical with storage/badger/operation/commits.go
, except BatchRemoveStateCommitment
and BatchIndexStateCommitment
are removed, since RemoveStateCommitment
is always a batch updates.
@@ -0,0 +1,31 @@ | |||
package operation_test |
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.
this file is identical to the same file in storage/badger/operation/
@@ -0,0 +1,166 @@ | |||
package operation |
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.
this file is identical to the same file in storage/badger/operation/
Except the following functions are removed:
- BatchInsertTransactionResult
- BatchIndexTransactionResult
@@ -0,0 +1,82 @@ | |||
package store |
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.
this file is identical to the same file in storage/badger/operation/
storage/store/my_receipts.go
Outdated
blockID := receipt.ExecutionResult.BlockID | ||
receiptID := receipt.ID() | ||
var myOwnReceiptExecutedBefore flow.Identifier | ||
err := operation.LookupOwnExecutionReceipt(rw.GlobalReader(), blockID, &myOwnReceiptExecutedBefore) |
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.
This is where we need to pay attention to, the original implementation can check if an own receipt already exist during insert.
if errors.Is(err, storage.ErrAlreadyExists) {
var savedReceiptID flow.Identifier
err := operation.LookupOwnExecutionReceipt(blockID, &savedReceiptID)(tx)
if err != nil {
return err
}
The original implementation can do so because it's using badger transaction. However, the new storage abstraction uses badger updates, so we have to check it ourselves.
The new way it works is to acquire the indexingOwnReceipts
and ensure no other process is storing own receipts, so that the check for if any own receipts for this block won't be stale.
storage/store/my_receipts_test.go
Outdated
}) | ||
}) | ||
|
||
t.Run("store1 different receipt concurrent for same block should fail", func(t *testing.T) { |
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.
This file is the same as the original, except this added concurrent tests.
block := unittest.BlockFixture() | ||
receipt1 := unittest.ReceiptForBlockFixture(&block) | ||
|
||
err := db.WithReaderBatchWriter(func(rw storage.ReaderBatchWriter) error { |
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.
This file is the same as the deleted storage/badger/my_receipts_test.go, except the StoreMyReceipt call is replaced with BatchStoreMyReceipt, since we never call StoreMyReceipt alone.
This PR updates the execution node and access node’s saving result process to use the new storage abstraction.
The following database modules are refactored into new storage abstraction: