Skip to content
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

[Storehouse] Add CreateStorageSnapshot to Execution state #5031

Merged
merged 12 commits into from
Nov 22, 2023

Conversation

zhangchiqing
Copy link
Member

@zhangchiqing zhangchiqing commented Nov 17, 2023

Working towards #4998

This PR:

  • Update NewStorageSnapshot to take blockID and height it's compatible with storehouse.
  • Add CreateStorageSnapshot to ScriptExecutionState in order to handle looking up state commitment by block id, and then lookup ledger storage by state commitment. The CreateStorageSnapshot could allow us to have different implementation with storehouse storage.

@zhangchiqing zhangchiqing changed the base branch from master to leo/storehouse-committer November 17, 2023 06:17
@@ -545,7 +545,7 @@ func (h *handler) GetAccountAtBlockID(

value, err := h.engine.GetAccount(ctx, flowAddress, blockFlowID)
if err != nil {
if errors.Is(err, scripts.ErrStateCommitmentPruned) {
if errors.Is(err, state.ErrStateCommitmentPruned) {
return nil, status.Errorf(codes.OutOfRange, "state for block ID %s not available", blockFlowID)
}
if errors.Is(err, storage.ErrNotFound) {
Copy link
Member Author

Choose a reason for hiding this comment

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

I think this is the case that block is not found, rather than account not found, might need to update error message

@@ -545,7 +545,7 @@ func (h *handler) GetAccountAtBlockID(

value, err := h.engine.GetAccount(ctx, flowAddress, blockFlowID)
if err != nil {
if errors.Is(err, scripts.ErrStateCommitmentPruned) {
if errors.Is(err, state.ErrStateCommitmentPruned) {
Copy link
Member Author

Choose a reason for hiding this comment

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

I wonder if we should distinguish between block not executed error, so that we can remove L539, since GetAccount is already checking that.

@codecov-commenter
Copy link

codecov-commenter commented Nov 17, 2023

Codecov Report

Attention: 7 lines in your changes are missing coverage. Please review.

Comparison is base (0ba81ff) 56.24% compared to head (a5d8fcc) 56.23%.

Files Patch % Lines
engine/execution/rpc/engine.go 20.00% 4 Missing ⚠️
cmd/execution_builder.go 0.00% 2 Missing ⚠️
engine/execution/state/state.go 93.75% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5031      +/-   ##
==========================================
- Coverage   56.24%   56.23%   -0.01%     
==========================================
  Files         975      974       -1     
  Lines       90864    90802      -62     
==========================================
- Hits        51110    51067      -43     
+ Misses      35944    35925      -19     
  Partials     3810     3810              
Flag Coverage Δ
unittests 56.23% <74.07%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@zhangchiqing zhangchiqing force-pushed the leo/storehouse-committer branch 2 times, most recently from d94c72e to 6e9e5df Compare November 18, 2023 02:30
@zhangchiqing zhangchiqing marked this pull request as ready for review November 21, 2023 01:44
@zhangchiqing zhangchiqing changed the title [Storehouse] Execution state [Storehouse] Add CreateStorageSnapshot to Execution state Nov 21, 2023
Comment on lines +43 to +50
NewStorageSnapshot(commit flow.StateCommitment, blockID flow.Identifier, height uint64) snapshot.StorageSnapshot

// CreateStorageSnapshot creates a new ready-only view at the given block.
// It returns:
// - (nil, nil, storage.ErrNotFound) if block is unknown
// - (nil, nil, state.ErrNotExecuted) if block is not executed
// - (nil, nil, state.ErrExecutionStatePruned) if the execution state has been pruned
CreateStorageSnapshot(blockID flow.Identifier) (snapshot.StorageSnapshot, *flow.Header, error)
Copy link
Member

Choose a reason for hiding this comment

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

Do we still need the first method?
I wonder (not sure the impact of the change on the current usage of the method) if we could have one method that you could call with options, something like:

CreateStorageSnapshot(WithBlockID(id)) 
CreateStorageSnapshot(WithCommitment(commitment), WithBlockID(id), WithHeight(height)) 

You could then internally decide how to handle that. I don't have much context on the usage tho, so feel free to disregard

Copy link
Member Author

Choose a reason for hiding this comment

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

There are a few different scenarios that still need the NewStorageSnapshot function. Let me explain why we need these two methods:

  1. There are two storage engines, ledger-based storage (current) and storehouse-based storage (upgrading to). Ledger-based storage takes commitment to find register, whereas storehouse takes BlockID and Height. We would like to use a flag to control which storage engine to use in the execution state, and we don't want the caller to know this implementation detail. That's why we pass all three data to the NewStorageSnapshot method, so that the execution state can decide internally which data to use. If we make them as options like what you suggested with WithCommitment/WithBlockID, then it means the caller still has to know the implementation detail to decide which option to use.

  2. Usually, we will lookup block first before querying the register, that's why I made this function CreateStorageSnapshot that takes a blockID, and lookup the commitment or block height and then create the storage snapshot.

  3. But then, why do we still need the NewStorageSnapshot, if we always need lookup commitment or block height ? Because there are one scenario where we don't need to lookup commitment or block height. That's when we are executing a block, the commitment and the block height is already available, see this change in ingestion engine. Using CreateStorageSnap there would make a unnecessary call.

Base automatically changed from leo/storehouse-committer to master November 22, 2023 17:09
@zhangchiqing zhangchiqing added this pull request to the merge queue Nov 22, 2023
Merged via the queue into master with commit 357a0c9 Nov 22, 2023
54 checks passed
@zhangchiqing zhangchiqing deleted the leo/storehouse-execution-state branch November 22, 2023 18:15
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants