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

Export get diff accounts in block api #431

Merged
merged 2 commits into from
Oct 8, 2021

Conversation

keefel
Copy link
Contributor

@keefel keefel commented Sep 28, 2021

Description

Export GetDiffAccounts and GetDiffAccountsWithScope, GetDiffAccounts can get all diff accounts in a block, GetDiffAccountsWithScope can pass the interested accounts and return their diff value in a block.

Rationale

To get diff accounts in a block easily.

Example

Changes

Preflight checks

  • build passed (make build)
  • tests passed (make test)
  • manual transaction test passed

Already reviewed by

...

Related issues

... reference related issue #'s here ...

accounts = append(accounts, diffAccounts.Account)
}

if header.TxHash != types.EmptyRootHash && (accounts == nil || len(accounts) == 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

accounts == nil || len(accounts) ==0 ==> len(accounts)==0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

}

// GetDiffAccountsInBlock returns detailed changes of some interested accounts in a specific block number.
func (ec *Client) GetDiffAccountsInBlock(ctx context.Context, number *big.Int, accounts []common.Address) (*types.DiffAccountsInBlock, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

It is confusing between GetDiffAccounts and GetDiffAccountsInBlock.
I will suggest change GetDiffAccountsInBlock ==> GetDiffAccountsWithScope

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 idea, done

@@ -25,6 +25,8 @@ import (
"strings"
"time"

"github.com/ethereum/go-ethereum/consensus"
Copy link
Collaborator

Choose a reason for hiding this comment

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

format the import order

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

}

// GetDiffAccountsInBlock returns detailed changes of some interested accounts in a specific block number.
func (s *PublicBlockChainAPI) GetDiffAccountsInBlock(ctx context.Context, blockNr rpc.BlockNumber, accounts []common.Address) (*types.DiffAccountsInBlock, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

change the nameGetDiffAccountsInBlock

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done


if !skip {
// Compute account balance diff.
for _, account := range accounts {
Copy link
Collaborator

Choose a reason for hiding this comment

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

If the account balance diff is zero, please do not record it in the map.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Signed-off-by: Keefe-Liu <bianze.kernel@gmail.com>
@@ -25,6 +25,9 @@ import (
"testing"
"time"

"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/ethdb/memorydb"

Copy link
Contributor

Choose a reason for hiding this comment

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

fix imports

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

// Compute account balance diff.
for _, account := range accounts {
diffTx.Accounts[account] = new(big.Int).Sub(statedb.GetBalance(account), diffTx.Accounts[account])
if diffTx.Accounts[account].Cmp(big.NewInt(0)) == 0 {
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 if equal to 0, then not record?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sorry, I don't get your point, do you mean convert bigInt into int then compare with 0 directly?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry, just ignore.

Signed-off-by: Keefe-Liu <bianze.kernel@gmail.com>
@unclezoro unclezoro merged commit b2f1d25 into bnb-chain:develop Oct 8, 2021
This was referenced Oct 19, 2021
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