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

Mempool optimization: on transaction addition, call "GetTransferredValue" and retain its value #6641

Merged
merged 3 commits into from
Nov 29, 2024

Conversation

andreibancioiu
Copy link
Collaborator

@andreibancioiu andreibancioiu commented Nov 29, 2024

Reasoning behind the pull request

Proposed changes

Testing procedure

  • Standard testing

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?

@andreibancioiu andreibancioiu marked this pull request as ready for review November 29, 2024 09:54
Comment on lines +29 to +34
if check.IfNil(args.txGasHandler) {
return nil, dataRetriever.ErrNilTxGasHandler
}
if check.IfNil(args.marshalizer) {
return nil, dataRetriever.ErrNilMarshalizer
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Somehow superfluous checks (dependencies are verified one layer above, as well), should I remove them?

}

// GetTransferredValue returns the value transferred by a transaction.
func (host *mempoolHost) GetTransferredValue(tx data.TransactionHandler) *big.Int {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Function moved from SelectionSession, no other change.

require.NotNil(t, host)
}

func TestMempoolHost_GetTransferredValue(t *testing.T) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Tests simply moved from selectionSession_test.go.

AdoAdoAdo
AdoAdoAdo previously approved these changes Nov 29, 2024
Comment on lines +36 to +38
argsParser := parsers.NewCallArgsParser()

esdtTransferParser, err := parsers.NewESDTTransferParser(args.marshalizer)
Copy link
Collaborator

Choose a reason for hiding this comment

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

why not get these two as arguments as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We instantiate them within mempoolHost, so that shardedTxPool doesn't have knowledge on the components from VM common parsers - somehow, a bit of information hiding (even though both mempoolHost and shardedTxPool live in the same package).

maybeMultiTransfer := bytes.HasPrefix(data, []byte(core.BuiltInFunctionMultiESDTNFTTransfer))
if !maybeMultiTransfer {
// Early exit (optimization).
return nil
Copy link
Collaborator

Choose a reason for hiding this comment

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

wouldn't it be easier/safer to return big.NewInt(0) here? (and L79, L84, L88)

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.

@andreibancioiu andreibancioiu merged commit d556eb8 into feat/mempool Nov 29, 2024
5 checks passed
@andreibancioiu andreibancioiu deleted the MX-16211-optimize-get-value branch November 29, 2024 14:01
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.

3 participants