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 161
Use value copy instead of pointer copy in stateObject.deepCopy #741
Closed
Closed
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
673e690
Use value copy instead of pointer copy in stateObject.deepCopy
summerpro 7050668
add change log
summerpro 3d6a5d9
Merge branch 'development' into ray/deepCopy
fedekunze 880ad13
Merge branch 'development' into ray/deepCopy
summerpro 9069c70
Merge branch 'development' into ray/deepCopy
summerpro 0f2804f
Merge branch 'development' into ray/deepCopy
summerpro 9347eec
panic when MarshalJSON failed
summerpro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -400,7 +400,16 @@ func (so *stateObject) GetCommittedState(_ ethstate.Database, key ethcmn.Hash) e | |
func (so *stateObject) ReturnGas(gas *big.Int) {} | ||
|
||
func (so *stateObject) deepCopy(db *CommitStateDB) *stateObject { | ||
newStateObj := newStateObject(db, so.account) | ||
newAccount := ethermint.ProtoAccount().(*ethermint.EthAccount) | ||
jsonAccount, err := so.account.MarshalJSON() | ||
if err != nil { | ||
return nil | ||
} | ||
err = newAccount.UnmarshalJSON(jsonAccount) | ||
if err != nil { | ||
return nil | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is this for? why don't you copy the existing fields to a new There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The member variable PubKey of ETHAccount is of interface type, do you have a better suggestion for deep copy of interface type? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @fedekunze Hi, what do you think of this solution? Can it be passed? Are there any possible problems with this solution? |
||
newStateObj := newStateObject(db, newAccount) | ||
|
||
newStateObj.code = so.code | ||
newStateObj.dirtyStorage = so.dirtyStorage.Copy() | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
seems that using value copy is ok here but when error happens during
marshal
orunmarshal
, error will be suppressed and nil will be returned, in this case, any one who invokeddeepCopy
may encounternil pointer dereference
and there is no way to prevent it.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.
The error returned in marshal is usually due to an operating system error. In this case, panic may be more appropriate.
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 wrote another solution, you can take a look(link), but I am not familiar with the usage of reflect, and I am worried that there will be any problems.
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.
@freddyli7 Looking forward to your reply