This repository has been archived by the owner on Nov 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 160
The "deepCopy" function from "StateObject" makes pointer copy instead of value copy #740
Labels
Comments
11 tasks
5 tasks
solution1
func (so *stateObject) deepCopy(db *CommitStateDB) *stateObject {
newAccount := ethermint.ProtoAccount().(*ethermint.EthAccount)
jsonAccount, err := so.account.MarshalJSON()
if err != nil {
panic(err)
}
err = newAccount.UnmarshalJSON(jsonAccount)
if err != nil {
panic(err)
}
newStateObj := newStateObject(db, newAccount)
newStateObj.code = so.code
newStateObj.dirtyStorage = so.dirtyStorage.Copy()
newStateObj.originStorage = so.originStorage.Copy()
newStateObj.suicided = so.suicided
newStateObj.dirtyCode = so.dirtyCode
newStateObj.deleted = so.deleted
return newStateObj
} solution2
func (so *stateObject) deepCopy(db *CommitStateDB) *stateObject {
pub := so.account.PubKey
if reflect.TypeOf(so.account.PubKey).Kind() == reflect.Ptr {
// Pointer:
pub = reflect.New(reflect.ValueOf(pub).Elem().Type()).Interface().(crypto.PubKey)
} else {
// Not pointer:
pub = reflect.New(reflect.TypeOf(pub)).Elem().Interface().(crypto.PubKey)
}
var newAccount types.EthAccount
newAccount.PubKey = pub
copy(newAccount.Address, so.account.Address)
copy(newAccount.CodeHash, so.account.CodeHash)
copy(newAccount.Coins, so.account.Coins)
newAccount.AccountNumber = so.account.AccountNumber
newAccount.Sequence = so.account.Sequence
newStateObj := newStateObject(db, newAccount)
newStateObj.code = so.code
newStateObj.dirtyStorage = so.dirtyStorage.Copy()
newStateObj.originStorage = so.originStorage.Copy()
newStateObj.suicided = so.suicided
newStateObj.dirtyCode = so.dirtyCode
newStateObj.deleted = so.deleted
return newStateObj
} |
This issue is stale because it has been open 45 days with no activity. Remove |
github-actions
bot
added
the
stale
stale PRs that will be closed if no further action occurs
label
Mar 23, 2021
araskachoi
removed
the
stale
stale PRs that will be closed if no further action occurs
label
Mar 29, 2021
This issue is stale because it has been open 45 days with no activity. Remove |
github-actions
bot
added
the
stale
stale PRs that will be closed if no further action occurs
label
Jun 6, 2021
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
risk
The text was updated successfully, but these errors were encountered: