-
Notifications
You must be signed in to change notification settings - Fork 197
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
Conversation
…unit tests. Refactoring of "nodeBlocks.go".
Codecov Report
@@ 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. |
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.
Minor stuff. Will green after the target PR will get merged in the rc as to not double review this.
dblookupext/todo.txt
Outdated
@@ -0,0 +1,3 @@ | |||
- Move the interface "HistoryRepository" where it's needed, not in the package where it's implemented |
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.
Mixed feelings about this todo file. Although will help us restructure the work I'm afraid it will be forgotten.
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.
Right. Removed file, added EN-12965
.
process/common.go
Outdated
@@ -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) { |
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.
missing comments here and on L723
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.
Added.
state/accountsRepository.go
Outdated
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 { |
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.
👍 for removing the error output parameter
state/accountsRepository.go
Outdated
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 { |
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.
instead of this if, you could have send the optionalUint32 parameter in the NewRootHashHolder constructor
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.
Fixed.
node/nodeBlocks.go
Outdated
n.coreComponents.Uint64ByteSliceConverter(), | ||
n.coreComponents.InternalMarshalizer(), | ||
) | ||
func (n *Node) getScheduledRootHash(epoch uint32, headerHash []byte) ([]byte, 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.
does this method is somehow the copy of the GetScheduledRootHashForHeader ?
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.
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?
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.
yes, should be ok
@@ -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") |
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.
👍
common/holders/rootHashHolder.go
Outdated
} | ||
} | ||
|
||
// NewRootHashHolderWithEpoch creates a rootHashHolder |
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.
extend the comment by also setting the epoch of the rootHash
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.
Removed this constructor (per Iulian's comment).
process/common.go
Outdated
@@ -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) { |
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.
maybe rename to UnmarshalHeader
/ UnmarshalMetaheader
/ UnmarshalShardHeader
?
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.
Create
makes me think of a new header, created by constructor
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.
Right :) renamed.
@@ -590,13 +607,17 @@ func (ste *scheduledTxsExecution) getScheduledInfoForHeader(headerHash []byte) ( | |||
} | |||
}() | |||
|
|||
marshalledSCRsSavedData, err := ste.storer.Get(headerHash) | |||
if epoch.HasValue { |
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.
yup, this avoids the duplicated code 👍
state/accountsRepository.go
Outdated
@@ -54,10 +54,7 @@ func (repository *accountsRepository) GetAccountWithBlockInfo(address []byte, op | |||
} | |||
|
|||
func (repository *accountsRepository) convertAccountQueryOptions(options api.AccountQueryOptions) common.RootHashHolder { |
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.
kind of useless function now
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.
Removed, inlined.
@@ -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 |
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.
proper tag?
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.
Fixed, using v1.1.19
.
node/nodeBlocks.go
Outdated
) | ||
} | ||
|
||
func (n *Node) getBlockHeaderByHash(headerHash []byte) (data.HeaderHandler, error) { | ||
epoch, err := n.getEpochByHash(headerHash) |
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.
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.
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.
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).
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.
System test passed.
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
dblookupext
, onstorer.GetFromEpoch()
etc.accountsRepository
, then toaccountsDBApiWithHistory
.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
NumEpochsToKeep = 10
(or so) andNumActivePersisters = 5 or 6 or 7
(or so).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 olderrootHash
(not found in the active persisters) - this will be fixed in a separate PR.