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

state: Clean up state finalization #609

Merged
merged 1 commit into from
Apr 13, 2023
Merged

Conversation

rodiazet
Copy link
Collaborator

@rodiazet rodiazet commented Apr 4, 2023

  • Separate selfdestruct handling from empty account clearing.
  • Apply block reward to coinbase consistently.
  • Use it to properly clean state in t8n and state-test-runner.

@rodiazet rodiazet requested a review from chfast April 4, 2023 15:44
@codecov
Copy link

codecov bot commented Apr 4, 2023

Codecov Report

Merging #609 (9f5c406) into master (1fb6fa6) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #609   +/-   ##
=======================================
  Coverage   97.29%   97.29%           
=======================================
  Files          78       78           
  Lines        7640     7648    +8     
=======================================
+ Hits         7433     7441    +8     
  Misses        207      207           
Flag Coverage Δ
blockchaintests 65.16% <ø> (ø)
statetests 63.18% <100.00%> (+0.08%) ⬆️
unittests 94.84% <100.00%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
test/state/state.hpp 100.00% <ø> (ø)
test/state/state.cpp 97.65% <100.00%> (+0.11%) ⬆️
test/statetest/statetest_runner.cpp 100.00% <100.00%> (ø)
test/unittests/state_transition.cpp 100.00% <100.00%> (ø)

@@ -117,19 +117,22 @@ evmc_message build_message(const Transaction& tx, int64_t execution_gas_limit) n
}
} // namespace

void clear_empty_or_destructed_accounts(State& state, evmc_revision rev)
Copy link
Member

Choose a reason for hiding this comment

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

image

Maybe not very specific, but can we name it finalize()?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good idea :)

Copy link
Member

Choose a reason for hiding this comment

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

This YP part is actually wrong: ethereum/yellowpaper#885.

@rodiazet rodiazet force-pushed the coinbase-touching-cleanup branch 2 times, most recently from 346d056 to a0b39d8 Compare April 5, 2023 10:36
@rodiazet rodiazet requested a review from chfast April 5, 2023 10:37
test/state/state.cpp Outdated Show resolved Hide resolved
test/state/state.cpp Outdated Show resolved Hide resolved
@chfast chfast force-pushed the coinbase-touching-cleanup branch 2 times, most recently from 79f997b to 60e30e5 Compare April 13, 2023 15:56
@chfast chfast changed the title Coinbase touching cleanup state: Clean up state finalization Apr 13, 2023
- Separate selfdestruct handling from empty account clearing.
- Apply block reward to coinbase consistently.

Co-authored-by: Paweł Bylica <[email protected]>
@@ -28,6 +28,10 @@ void run_state_test(const StateTransitionTest& test, evmc::VM& vm)
validate_deployed_code(state, rev);

const auto res = state::transition(state, test.block, tx, rev, vm);

// Finalize block with reward 0.
Copy link
Member

Choose a reason for hiding this comment

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

In state tests it's not 0 on pre-merge revisions.

Copy link
Member

Choose a reason for hiding this comment

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

For state tests this is always 0. This effectively only touches/creates the coinbase account.

Copy link
Member

Choose a reason for hiding this comment

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

True, apparently it's non-zero only in blockchain tests.

Copy link
Member

Choose a reason for hiding this comment

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

FYI, this is configurable in t8n via --state.reward.

std::variant<TransactionReceipt, std::error_code> transition(
State& state, const BlockInfo& block, const Transaction& tx, evmc_revision rev, evmc::VM& vm)
{
auto& sender_acc = state.get(tx.sender);
const auto validation_result = validate_transaction(sender_acc, block, tx, rev);

if (holds_alternative<std::error_code>(validation_result))
{
// Pre EIP-158 coinbase has to be touched also for invalid tx.
Copy link
Member

Choose a reason for hiding this comment

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

Why is this not needed now?

Copy link
Member

Choose a reason for hiding this comment

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

This emulates applying block reward of 0. Previously, I wasn't exactly sure why this is needed. Now the block reward is "properly" applied in the end.

@chfast chfast merged commit 31fd534 into master Apr 13, 2023
@chfast chfast deleted the coinbase-touching-cleanup branch April 13, 2023 19:15
Copy link

@AungThuSoe24 AungThuSoe24 left a comment

Choose a reason for hiding this comment

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

Coinbase wallet

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.

5 participants