mirror of
https://github.com/status-im/status-go.git
synced 2025-01-22 04:31:30 +00:00
[#4605] Skip nonce check when possible during tx detection
This commit is contained in:
parent
9050ed7aaf
commit
647c3b0fd8
@ -6,6 +6,8 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"golang.org/x/exp/slices"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
@ -148,36 +150,56 @@ func (c *findNewBlocksCommand) Run(parent context.Context) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
accounts := []common.Address{}
|
accountsToCheck := []common.Address{}
|
||||||
|
// accounts which might have outgoing transfers initiated outside
|
||||||
|
// the application, e.g. watch only or restored from mnemonic phrase
|
||||||
|
accountsWithOutsideTransfers := []common.Address{}
|
||||||
|
|
||||||
for _, account := range c.accounts {
|
for _, account := range c.accounts {
|
||||||
if mnemonicWasNotShown {
|
|
||||||
acc, err := c.accountsDB.GetAccountByAddress(nodetypes.Address(account))
|
acc, err := c.accountsDB.GetAccountByAddress(nodetypes.Address(account))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.error = err
|
c.error = err
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if mnemonicWasNotShown {
|
||||||
if acc.AddressWasNotShown {
|
if acc.AddressWasNotShown {
|
||||||
log.Info("skip findNewBlocksCommand, mnemonic has not been shown and the address has not been shared yet", "address", account)
|
log.Info("skip findNewBlocksCommand, mnemonic has not been shown and the address has not been shared yet", "address", account)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
accounts = append(accounts, account)
|
if !mnemonicWasNotShown || acc.Type != accounts.AccountTypeGenerated {
|
||||||
|
accountsWithOutsideTransfers = append(accountsWithOutsideTransfers, account)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(accounts) == 0 {
|
accountsToCheck = append(accountsToCheck, account)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(accountsToCheck) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
headNum, accountsWithDetectedChanges, err := c.detectTransfers(parent, accounts)
|
headNum, accountsWithDetectedChanges, err := c.detectTransfers(parent, accountsToCheck)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("findNewBlocksCommand error on transfer detection", "error", err, "chain", c.chainClient.NetworkID())
|
log.Error("findNewBlocksCommand error on transfer detection", "error", err, "chain", c.chainClient.NetworkID())
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(accountsWithDetectedChanges) != 0 || c.iteration%nonceCheckIntervalIterations == 0 {
|
if len(accountsWithDetectedChanges) != 0 {
|
||||||
c.findAndSaveEthBlocks(parent, c.fromBlockNumber, headNum, accounts)
|
c.findAndSaveEthBlocks(parent, c.fromBlockNumber, headNum, accountsToCheck)
|
||||||
|
} else if c.iteration%nonceCheckIntervalIterations == 0 && len(accountsWithOutsideTransfers) > 0 {
|
||||||
|
c.findAndSaveEthBlocks(parent, c.fromBlockNumber, headNum, accountsWithOutsideTransfers)
|
||||||
|
for _, account := range accountsToCheck {
|
||||||
|
if slices.Contains(accountsWithOutsideTransfers, account) {
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
err := c.markEthBlockRangeChecked(account, &BlockRange{nil, c.fromBlockNumber, headNum})
|
||||||
|
if err != nil {
|
||||||
|
c.error = err
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if len(accountsWithDetectedChanges) != 0 || c.iteration%logsCheckIntervalIterations == 0 {
|
if len(accountsWithDetectedChanges) != 0 || c.iteration%logsCheckIntervalIterations == 0 {
|
||||||
c.findAndSaveTokenBlocks(parent, c.fromBlockNumber, headNum)
|
c.findAndSaveTokenBlocks(parent, c.fromBlockNumber, headNum)
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,7 @@ import (
|
|||||||
"github.com/status-im/status-go/t/utils"
|
"github.com/status-im/status-go/t/utils"
|
||||||
|
|
||||||
"github.com/status-im/status-go/multiaccounts/accounts"
|
"github.com/status-im/status-go/multiaccounts/accounts"
|
||||||
|
multicommon "github.com/status-im/status-go/multiaccounts/common"
|
||||||
"github.com/status-im/status-go/params"
|
"github.com/status-im/status-go/params"
|
||||||
statusRpc "github.com/status-im/status-go/rpc"
|
statusRpc "github.com/status-im/status-go/rpc"
|
||||||
"github.com/status-im/status-go/rpc/network"
|
"github.com/status-im/status-go/rpc/network"
|
||||||
@ -1368,6 +1369,18 @@ func TestFetchNewBlocksCommand(t *testing.T) {
|
|||||||
accDB, err := accounts.NewDB(appdb)
|
accDB, err := accounts.NewDB(appdb)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
for _, address := range []*common.Address{&address1, &address2} {
|
||||||
|
acc := &accounts.Account{
|
||||||
|
Address: ethtypes.BytesToAddress(address.Bytes()),
|
||||||
|
Type: accounts.AccountTypeWatch,
|
||||||
|
Name: address.String(),
|
||||||
|
ColorID: multicommon.CustomizationColorPrimary,
|
||||||
|
Emoji: "emoji",
|
||||||
|
}
|
||||||
|
err = accDB.SaveOrUpdateAccounts([]*accounts.Account{acc}, false)
|
||||||
|
require.NoError(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
tc := &TestClient{
|
tc := &TestClient{
|
||||||
t: t,
|
t: t,
|
||||||
balances: map[common.Address][][]int{},
|
balances: map[common.Address][][]int{},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user