-
Notifications
You must be signed in to change notification settings - Fork 324
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
account type with zero init nonce #3387
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3387 +/- ##
==========================================
+ Coverage 75.21% 75.41% +0.20%
==========================================
Files 244 244
Lines 22543 22675 +132
==========================================
+ Hits 16956 17101 +145
+ Misses 4664 4649 -15
- Partials 923 925 +2
Continue to review full report at Codecov.
|
146f7da
to
d63b9a1
Compare
api/coreservice.go
Outdated
accountMeta := &iotextypes.AccountMeta{ | ||
Address: addrStr, | ||
Balance: state.Balance.String(), | ||
Nonce: state.Nonce, | ||
PendingNonce: pendingNonce, | ||
Nonce: nonce, |
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.
why not use state.Nonce
as before? so line 260 to 263 is not necessary?
state/account.go
Outdated
// other actions' nonces start from 1 | ||
Nonce uint64 | ||
nonce uint64 |
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.
i think it's OK to leave it as it, or is there a particular reason to make nonce
unexported?
state/account.go
Outdated
switch st.Type { | ||
case 1: | ||
return st.nonce | ||
default: // 0 |
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
case 0:
return nonce + 1
default:
panic("unknown account type")
nonce++ | ||
nonce = state.PendingNonce() | ||
if !stateDB.usePendingNonce { | ||
nonce-- |
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.
is it possible a new account (type = 1) will go to here? then nonce would be 0-1
@@ -318,11 +342,14 @@ func (stateDB *StateDBAdapter) SetNonce(evmAddr common.Address, nonce uint64) { | |||
log.L().Debug("Called SetNonce.", | |||
zap.String("address", addr.String()), | |||
zap.Uint64("nonce", nonce)) | |||
s.Nonce = nonce | |||
if err := accountutil.StoreAccount(stateDB.sm, addr, s); err != nil { | |||
if err := accountutil.SetNonce(s, nonce); err != nil { |
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.
i don't recall, in the case stateDB.usePendingNonce == true
, why in GetNonce()
need to do nonce++
and in SetNonce()
do nonce--
to bring it back (line 340 above)
does this logic still hold for the new account (type = 1)?
6881b43
to
fb78e66
Compare
27fb160
to
1bc02b7
Compare
|
||
// create account | ||
require.NoError(createAccount(sm, addrv1.String(), big.NewInt(5))) | ||
s, err = accountutil.LoadAccount(sm, addrv1) | ||
require.NoError(err) | ||
require.Equal("5", s.Balance.String()) | ||
require.Equal(uint64(0x0), s.Nonce) |
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.
add test to create new type account, assert s.PendingNonce() == 0
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.
Are you sure to add unit test to this PR?
case state.ErrStateNotExist: | ||
return state.NewAccount(opts...) | ||
case nil: | ||
return account, nil |
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.
nit: move case nil:
to the first case, to be consistent with other places
action/protocol/account/util/util.go
Outdated
switch errors.Cause(err) { | ||
case nil: | ||
fallthrough | ||
case state.ErrStateNotExist: |
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.
nit: case nil, state.ErrStateNotExist
is more straightforward
func EmptyAccount() Account { | ||
return Account{ | ||
// NewAccount creates a new account with options | ||
func NewAccount(opts ...AccountCreationOption) (*Account, 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.
move to the head
if recipientAcct.IsContract() { | ||
// update sender Nonce | ||
accountutil.SetNonce(tsf, sender) | ||
if fixNonce || tsf.Nonce() != 0 { |
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.
SetPendingNonce
can be moved out of if condition?
} | ||
|
||
// SetPendingNonce sets the pending nonce | ||
func (st *Account) SetPendingNonce(nonce uint64) 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.
IMO, we should keep using SetNonce(nonce)
, this way SetPendingNonce(nonce+1)
feels more confusing
for _, addr := range stateDB.cachedContractAddrs() { | ||
c := stateDB.cachedContract[addr] | ||
if stateDB.disableSortCachedContracts { | ||
for _, c := range stateDB.cachedContract { |
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.
IMO it's not necessary to flip the flag? it increases the risk of making accidental error, and make it hard to review
if we really want to do it, better do it in a separate PR, since this is not related to zero-nonce
@@ -26,7 +26,7 @@ | |||
"rawGasLimit": 1000000, | |||
"rawGasPrice": "0", | |||
"rawAccessList": [{ | |||
"address": "06abb2ca03834bd4f62c610ca7627e3dd12d9a97", | |||
"address": "675f1057F81e9e768e33faddbd5609C09F4c0a5C", |
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.
why would the address change?
accountMeta := &iotextypes.AccountMeta{ | ||
Address: addrStr, | ||
Balance: state.Balance.String(), | ||
Nonce: state.Nonce, |
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 safety better do this in another PR as TODO mentioned, my worry is that this might breaking the API behavior, some user may be using meta.Nonce
from returned value and this will break their code?
return st.nonce | ||
default: // 0 | ||
return st.nonce + 1 | ||
} |
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.
same as in SetNonce
:
case 0:
return st.nonce + 1
default:
return ErrUnknownAccountType
* upstream/master: (24 commits) account type with zero init nonce (iotexproject#3387) [api] Separate Server and Server Handler (iotexproject#3485) [ioctl] Build hdwallet derive command line into new ioctl (iotexproject#3418) [ioctl] Build hdwallet create command line into new ioctl (iotexproject#3470) [makefile] add go mod tidy (iotexproject#3471) [api] update chain metrics (iotexproject#3484) remove config.EVMNetworkID() (iotexproject#3460) [filedao] remove checkMasterChainDBFile() (iotexproject#3463) [api] add crashlog (iotexproject#3456) [api] Move generateBlockMeta to grpcserver.go (iotexproject#3303) [ioctl] Build action hash command line into new ioctl (iotexproject#3425) [ioctl] Build hdwallet export command line into new ioctl (iotexproject#3423) [ioctl] Refactor nodereward command in new ioctl (iotexproject#3416) [ioctl] Cleanup TestNewNodeDelegateCmd (iotexproject#3421) [blockchain] Remove BoltDBDaoOption (iotexproject#3465) remove InMemDaoOption (iotexproject#3464) [action] add evm london test (iotexproject#3402) [ioctl] create main for ioctl/newcmd (iotexproject#3296) [ioctl] Build block bucket command line into new ioctl (iotexproject#3386) [ioctl] Build hdwallet import command line into new ioctl (iotexproject#3419) ...
Description
Close other PRs per reviewers' request.
In this PR:
Fixes # (issue)
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
Test Configuration:
Checklist: