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

[evm] remove corresponding logs when tx is reverted #3014

Merged
merged 3 commits into from
Jan 26, 2022

Conversation

dustinxie
Copy link
Member

No description provided.

@dustinxie dustinxie requested a review from a team as a code owner January 21, 2022 03:38
@codecov
Copy link

codecov bot commented Jan 21, 2022

Codecov Report

Merging #3014 (6de075d) into master (97d0259) will increase coverage by 0.11%.
The diff coverage is 87.50%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3014      +/-   ##
==========================================
+ Coverage   64.96%   65.07%   +0.11%     
==========================================
  Files         191      191              
  Lines       20603    20628      +25     
==========================================
+ Hits        13384    13424      +40     
+ Misses       5528     5511      -17     
- Partials     1691     1693       +2     
Impacted Files Coverage Δ
action/protocol/context.go 37.81% <0.00%> (-0.33%) ⬇️
action/protocol/execution/evm/evm.go 45.89% <0.00%> (-0.29%) ⬇️
action/protocol/execution/evm/evmstatedbadapter.go 59.81% <100.00%> (+4.74%) ⬆️
db/trie/mptrie/extensionnode.go 71.65% <0.00%> (+1.57%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 97d0259...6de075d. Read the comment docs.

require.Equal(test.logAddr, stateDB.logs[test.logSize-1].Address)
} else {
require.Equal(6, len(stateDB.logs))
require.Equal("io1x3cv7c4w922k6wx5s8p6d8sjrcqlcfrxhkn5xe", stateDB.logs[5].Address)
Copy link
Member Author

Choose a reason for hiding this comment

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

if revertLog is not enabled, the number of logs stays at 6

@@ -892,10 +919,16 @@ func (stateDB *StateDBAdapter) clear() {
stateDB.suicideSnapshot = nil
stateDB.preimages = nil
stateDB.preimageSnapshot = nil
stateDB.logsSnapshot = nil
Copy link
Member

Choose a reason for hiding this comment

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

Once the memory is unreachable, it will be freed.
No need to set it to nil

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, reason for this:

  1. this is for code clarity (clearly tells reader the variable is not needed anymore), follow the existing code
  2. in a sense help the runtime/GC to know immediately this memory is no longer needed and can be GC'ed, similar to 90badd6#diff-aa7bcf8c732d6ec1b1b2d3a3324071563c4c913f007f3298bf8f7e1f7c78aaa5R49

Copy link
Member

Choose a reason for hiding this comment

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

Unlike C++, Go is automatic memory management. The GC won't invoked immediately when the reference is removed.

Copy link
Member Author

Choose a reason for hiding this comment

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

right ... again the reasons explained above

// restore logs
if stateDB.revertLog {
stateDB.logs = stateDB.logs[:stateDB.logsSnapshot[snapshot]]
delete(stateDB.logsSnapshot, snapshot)
Copy link
Member

Choose a reason for hiding this comment

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

why do we need map here? Is the distribution of sn sparse?
I think slice is enough

Copy link
Member Author

Choose a reason for hiding this comment

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

updated in 3rd commit

receipt.AddLogs(stateDB.Logs()...).AddTransactionLogs(depositLog, burnLog)
if receipt.Status == uint64(iotextypes.ReceiptStatus_Success) ||
featureCtx.AddOutOfGasToTransactionLog && receipt.Status == uint64(iotextypes.ReceiptStatus_ErrCodeStoreOutOfGas) {
receipt.AddTransactionLogs(stateDB.TransactionLogs()...)
}
stateDB.clear()
Copy link
Collaborator

Choose a reason for hiding this comment

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

The position change of this line may be a hard fork.

Copy link
Member Author

@dustinxie dustinxie Jan 24, 2022

Choose a reason for hiding this comment

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

from my understanding it's not a hard-fork, clear() does not clear Logs and TransactionLogs, which are used in line 246~249, now moving clear() to after line 249 and as a result, these 2 can be cleared as well

it is not a necessary change, just to make clear() a little better, that's why I put it in a 2nd commit. I am fine we don't check this in. Let me know your thoughts

Copy link
Collaborator

Choose a reason for hiding this comment

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

then, it should be fine.

receipt.AddLogs(stateDB.Logs()...).AddTransactionLogs(depositLog, burnLog)
if receipt.Status == uint64(iotextypes.ReceiptStatus_Success) ||
featureCtx.AddOutOfGasToTransactionLog && receipt.Status == uint64(iotextypes.ReceiptStatus_ErrCodeStoreOutOfGas) {
receipt.AddTransactionLogs(stateDB.TransactionLogs()...)
}
stateDB.clear()
Copy link
Collaborator

Choose a reason for hiding this comment

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

then, it should be fine.

@@ -62,11 +62,13 @@ type (
suicideSnapshot map[int]deleteAccount // snapshots of suicide accounts
preimages preimageMap
preimageSnapshot map[int]preimageMap
logsSnapshot []int // logs is an array, save len(logs) at time of snapshot suffices
Copy link
Collaborator

Choose a reason for hiding this comment

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

shall we revert transaction logs as well? if so, it is better to have it fixed in this PR as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

right, good catch

@CoderZhi CoderZhi merged commit 0206622 into iotexproject:master Jan 26, 2022
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