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

add withKeys option on account #6123

Merged
merged 9 commits into from Apr 24, 2024
Merged

Conversation

raduchis
Copy link
Contributor

@raduchis raduchis commented Apr 19, 2024

Reasoning behind the pull request

  • do one single request on /address/:address?withKeys=true, so that also keys are returned together with the account information.

Proposed changes

  • add withKeys option

Testing procedure

  • #allIn

Pre-requisites

Based on the Contributing Guidelines the PR author and the reviewers must check the following requirements are met:

  • was the PR targeted to the correct branch?
  • if this is a larger feature that probably needs more than one PR, is there a feat branch created?
  • if this is a feat branch merging, do all satellite projects have a proper tag inside go.mod?


for _, address := range addresses {
accountResponse, blockInfoForAccount, err := nf.node.GetAccount(address, options)
accountResponse, blockInfoForAccount, err := nf.node.GetAccount(address, options, ctx)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we have an old issue here

seems that here we could return accounts with different block info, but in the end we reply with the latest block info, which might not be correct.

Could you request with the same roothash for all accounts?

Copy link
Contributor Author

@raduchis raduchis Apr 19, 2024

Choose a reason for hiding this comment

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

yes, changed the options so that all accounts are requested with the same roothash, from the first account

@@ -336,7 +339,10 @@ func (nf *nodeFacade) ComputeTransactionGasLimit(tx *transaction.Transaction) (*

// GetAccount returns a response containing information about the account correlated with provided address
func (nf *nodeFacade) GetAccount(address string, options apiData.AccountQueryOptions) (apiData.AccountResponse, apiData.BlockInfo, error) {
accountResponse, blockInfo, err := nf.node.GetAccount(address, options)
ctx, cancel := nf.getContextForApiTrieRangeOperations()
Copy link
Contributor

Choose a reason for hiding this comment

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

could we do the getContextForApiTrieRangeOperations only if withKeys option is set?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, changed it

Copy link
Contributor

Choose a reason for hiding this comment

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

Right.
Couldn't we just have a GetAccountWithKeys rather(if withKeys) so that we do not change the existing node and only use that if that bool flag is found?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good observation: refactored to have GetAccountWithKeys

@@ -321,7 +321,10 @@ func (nf *nodeFacade) GetLastPoolNonceForSender(sender string) (uint64, error) {

// GetTransactionsPoolNonceGapsForSender will return the nonce gaps from pool for sender, if exists, that is to be returned on API calls
func (nf *nodeFacade) GetTransactionsPoolNonceGapsForSender(sender string) (*common.TransactionsPoolNonceGapsForSenderApiResponse, error) {
accountResponse, _, err := nf.node.GetAccount(sender, apiData.AccountQueryOptions{})
ctx, cancel := nf.getContextForApiTrieRangeOperations()
Copy link
Contributor

Choose a reason for hiding this comment

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

I think here we can remove the getContextForApiTrieRangeOperations as this call does not support options.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

refactored to have a method GetAccountWithKeys

@@ -336,7 +339,10 @@ func (nf *nodeFacade) ComputeTransactionGasLimit(tx *transaction.Transaction) (*

// GetAccount returns a response containing information about the account correlated with provided address
func (nf *nodeFacade) GetAccount(address string, options apiData.AccountQueryOptions) (apiData.AccountResponse, apiData.BlockInfo, error) {
accountResponse, blockInfo, err := nf.node.GetAccount(address, options)
ctx, cancel := nf.getContextForApiTrieRangeOperations()
Copy link
Contributor

Choose a reason for hiding this comment

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

Right.
Couldn't we just have a GetAccountWithKeys rather(if withKeys) so that we do not change the existing node and only use that if that bool flag is found?

node/node.go Show resolved Hide resolved
node/node.go Outdated Show resolved Hide resolved
node.WithStateComponents(stateComponents),
)

recovAccnt, _, err := n.GetAccount(testscommon.TestAddressBob, api.AccountQueryOptions{WithKeys: false}, context.Background())
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make sens to test the Getters in parallel here on different go routines?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

do you mean to try to have multiple requests and check the result from different blocks?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, or from the same block, just making parallel requests.
If it doesn't make sense or it's already being tested somewhere else, we can skip it

facade/interface.go Outdated Show resolved Hide resolved
go.mod Show resolved Hide resolved
node/node.go Outdated Show resolved Hide resolved
node/node_test.go Outdated Show resolved Hide resolved
node/node_test.go Outdated Show resolved Hide resolved
node/node_test.go Outdated Show resolved Hide resolved
mariusmihaic
mariusmihaic previously approved these changes Apr 23, 2024
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.

Normal allin test: v1.6.15-dev-config-eb2e06c06d -> MX-15381-add-withKeys-on-a-74c90c5230

--- Specific errors ---

block hash does not match 1725
wrong nonce in block 679
miniblocks does not match 0
num miniblocks does not match 0
miniblock hash does not match 0
block bodies does not match 0
receipts hash missmatch 0

/------/

--- Statistics ---

Nr. of all ERRORS: 2
Nr. of all WARNS: 498
Nr. of new ERRORS: 1
Nr. of new WARNS: 5
Nr. of PANICS: 0

/------/

--- ERRORS ---

/------/

@miiu96 miiu96 merged commit 52a19be into rc/v1.7.0 Apr 24, 2024
8 checks passed
@miiu96 miiu96 deleted the MX-15381-add-withKeys-on-api-address branch April 24, 2024 12:57
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.

None yet

5 participants