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

For historical lookups, load block coordinates from older epochs, as well #4386

Merged
merged 11 commits into from
Aug 23, 2022

Conversation

andreibancioiu
Copy link
Collaborator

@andreibancioiu andreibancioiu commented Aug 21, 2022

Description of the reasoning behind the pull request (what feature was missing / how the problem was manifesting itself / what was the motive behind the refactoring)

Proposed Changes

  • For historical lookup, load block coordinates from older epochs, as well - rely on dblookupext, on storer.GetFromEpoch() etc.
  • Pass epoch (hint) to accountsRepository, then to accountsDBApiWithHistory.
  • Note that the epoch (hint) that reaches accountsDBApiWithHistory isn't used in this PR. A separate PR will make use of the epoch hint to appropriately recreate the trie (from older root hashes).

Testing procedure

  • Make sure to set NumEpochsToKeep = 10 (or so) and NumActivePersisters = 5 or 6 or 7 (or so).
  • Same as Implement queries for historical balances (state) #4371, but try to access older blocks. Though, key not found errors could (should) occur at this moment (depending on the queried epoch), since the accounts API cannot currently re-create a trie given an older rootHash (not found in the active persisters) - this will be fixed in a separate PR.

@andreibancioiu andreibancioiu self-assigned this Aug 21, 2022
@andreibancioiu andreibancioiu marked this pull request as ready for review August 21, 2022 20:21
@codecov-commenter
Copy link

Codecov Report

❗ No coverage uploaded for pull request base (historical-balances-08-12@32fb586). Click here to learn what that means.
The diff coverage is n/a.

@@                     Coverage Diff                      @@
##             historical-balances-08-12    #4386   +/-   ##
============================================================
  Coverage                             ?   73.79%           
============================================================
  Files                                ?      674           
  Lines                                ?    86853           
  Branches                             ?        0           
============================================================
  Hits                                 ?    64094           
  Misses                               ?    17965           
  Partials                             ?     4794           

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Contributor

@iulianpascalau iulianpascalau left a comment

Choose a reason for hiding this comment

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

Minor stuff. Will green after the target PR will get merged in the rc as to not double review this.

@@ -0,0 +1,3 @@
- Move the interface "HistoryRepository" where it's needed, not in the package where it's implemented
Copy link
Contributor

Choose a reason for hiding this comment

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

Mixed feelings about this todo file. Although will help us restructure the work I'm afraid it will be forgotten.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Right. Removed file, added EN-12965.

@@ -711,6 +712,24 @@ func GetSortedStorageUpdates(account *vmcommon.OutputAccount) []*vmcommon.Storag
return storageUpdates
}

func CreateHeader(shardId uint32, marshalizer marshal.Marshalizer, headerBuffer []byte) (data.HeaderHandler, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

missing comments here and on L723

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added.

return accountsAdapter.GetAccountWithBlockInfo(address, convertedOptions)
}

func (repository *accountsRepository) convertAccountQueryOptions(options api.AccountQueryOptions) (common.RootHashHolder, error) {
return holders.NewRootHashHolder(options.BlockRootHash), nil
func (repository *accountsRepository) convertAccountQueryOptions(options api.AccountQueryOptions) common.RootHashHolder {
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 for removing the error output parameter

func (repository *accountsRepository) convertAccountQueryOptions(options api.AccountQueryOptions) (common.RootHashHolder, error) {
return holders.NewRootHashHolder(options.BlockRootHash), nil
func (repository *accountsRepository) convertAccountQueryOptions(options api.AccountQueryOptions) common.RootHashHolder {
if options.HintEpoch.HasValue {
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of this if, you could have send the optionalUint32 parameter in the NewRootHashHolder constructor

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.

n.coreComponents.Uint64ByteSliceConverter(),
n.coreComponents.InternalMarshalizer(),
)
func (n *Node) getScheduledRootHash(epoch uint32, headerHash []byte) ([]byte, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

does this method is somehow the copy of the GetScheduledRootHashForHeader ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, but uses storer.GetFromEpoch() under the hood, instead of storer.Get(). Removed, refactored, added a new function: scheduledTxsExecution.GetScheduledRootHashForHeaderWithEpoch.

I didn't change the signature of the existing GetScheduledRootHashForHeader (only the private function it relies on) - is it all right?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, should be ok

@AdoAdoAdo AdoAdoAdo self-requested a review August 22, 2022 07:22
@@ -48,5 +53,14 @@ func TestExtractAccountQueryOptions(t *testing.T) {
options, err = extractAccountQueryOptions(testscommon.CreateGinContextWithRawQuery("onStartOfEpoch=7&blockRootHash=bbbb"))
require.ErrorContains(t, err, "onStartOfEpoch is not compatible")
require.Equal(t, api.AccountQueryOptions{}, options)

options, err = extractAccountQueryOptions(testscommon.CreateGinContextWithRawQuery("onFinalBlock=true&hintEpoch=7"))
require.ErrorContains(t, err, "hintEpoch is optional, but only compatible with blockRootHash")
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

}
}

// NewRootHashHolderWithEpoch creates a rootHashHolder
Copy link
Contributor

Choose a reason for hiding this comment

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

extend the comment by also setting the epoch of the rootHash

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed this constructor (per Iulian's comment).

@@ -711,6 +712,24 @@ func GetSortedStorageUpdates(account *vmcommon.OutputAccount) []*vmcommon.Storag
return storageUpdates
}

func CreateHeader(shardId uint32, marshalizer marshal.Marshalizer, headerBuffer []byte) (data.HeaderHandler, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe rename to UnmarshalHeader / UnmarshalMetaheader / UnmarshalShardHeader ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Create makes me think of a new header, created by constructor

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Right :) renamed.

iulianpascalau
iulianpascalau previously approved these changes Aug 22, 2022
@@ -590,13 +607,17 @@ func (ste *scheduledTxsExecution) getScheduledInfoForHeader(headerHash []byte) (
}
}()

marshalledSCRsSavedData, err := ste.storer.Get(headerHash)
if epoch.HasValue {
Copy link
Contributor

Choose a reason for hiding this comment

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

yup, this avoids the duplicated code 👍

@@ -54,10 +54,7 @@ func (repository *accountsRepository) GetAccountWithBlockInfo(address []byte, op
}

func (repository *accountsRepository) convertAccountQueryOptions(options api.AccountQueryOptions) common.RootHashHolder {
Copy link
Contributor

Choose a reason for hiding this comment

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

kind of useless function now

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed, inlined.

bogdan-rosianu
bogdan-rosianu previously approved these changes Aug 22, 2022
@@ -9,7 +9,7 @@ require (
github.com/ElrondNetwork/concurrent-map v0.1.3
github.com/ElrondNetwork/covalent-indexer-go v1.0.6
github.com/ElrondNetwork/elastic-indexer-go v1.2.38
github.com/ElrondNetwork/elrond-go-core v1.1.19-0.20220813193723-a7d8c4aeaa87
Copy link
Contributor

Choose a reason for hiding this comment

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

proper tag?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed, using v1.1.19.

)
}

func (n *Node) getBlockHeaderByHash(headerHash []byte) (data.HeaderHandler, error) {
epoch, err := n.getEpochByHash(headerHash)
Copy link
Contributor

Choose a reason for hiding this comment

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

can we add some support in case dblookup extensions is not enabled?
so we do not return error for example when we activate API calls on validators, and we query the recent (current epoch) block hashes.

With these changes, for validators the api will always return error (db lookup extension not activated) and previously it was not.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed to incorporate a fallback mechanism when dblookup extensions is not enabled (theoretically, wasn't a breaking change - the new query parameters have been recently added).

Base automatically changed from historical-balances-08-12 to rc/2022-july August 22, 2022 09:45
Copy link
Collaborator

@gabi-vuls gabi-vuls left a comment

Choose a reason for hiding this comment

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

System test passed.

@gabi-vuls gabi-vuls merged commit e15520a into rc/2022-july Aug 23, 2022
@gabi-vuls gabi-vuls deleted the historical-lookup-past-epochs branch August 23, 2022 08:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants