Skip to content

Conversation

@rodiazet
Copy link
Member

@rodiazet rodiazet commented Apr 11, 2023

  • Add support for withdrawals in t8n interface. It's required by execution-spec-tests
  • Tests

@rodiazet rodiazet requested a review from chfast April 11, 2023 13:02
test/t8n/t8n.cpp Outdated

// Apply withdrawals. Amount value is in gwei.
for (const auto& withdraw : block.withdrawals)
state.touch(withdraw.first).balance += withdraw.second * 1000000000;
Copy link
Member

Choose a reason for hiding this comment

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

Are withdrawals applies before block finalization? I.e. are touched accounts possibly 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.

Spec says that amount is non-zero. So I will not be removed on finalizing. Am I right? https://eips.ethereum.org/EIPS/eip-4895

@rodiazet rodiazet force-pushed the withdrawals-t8n branch 2 times, most recently from f942863 to 815339a Compare April 14, 2023 14:12
@codecov
Copy link

codecov bot commented Apr 14, 2023

Codecov Report

Merging #614 (f062020) into master (4211942) will increase coverage by 0.01%.
The diff coverage is 100.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #614      +/-   ##
==========================================
+ Coverage   97.29%   97.30%   +0.01%     
==========================================
  Files          78       79       +1     
  Lines        7648     7679      +31     
==========================================
+ Hits         7441     7472      +31     
  Misses        207      207              
Flag Coverage Δ
blockchaintests 65.16% <ø> (ø)
statetests 63.11% <53.84%> (-0.08%) ⬇️
unittests 94.86% <100.00%> (+0.02%) ⬆️

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

Impacted Files Coverage Δ
test/state/state.cpp 97.69% <100.00%> (+0.03%) ⬆️
test/state/state.hpp 100.00% <100.00%> (ø)
test/statetest/statetest_loader.cpp 89.69% <100.00%> (+0.31%) ⬆️
test/statetest/statetest_runner.cpp 100.00% <100.00%> (ø)
test/unittests/state_transition.cpp 100.00% <100.00%> (ø)
test/unittests/state_transition_block_test.cpp 100.00% <100.00%> (ø)
...est/unittests/statetest_loader_block_info_test.cpp 100.00% <100.00%> (ø)

[[nodiscard]] const auto& get_accounts() const noexcept { return m_accounts; }
};

using Withdrawals = std::vector<std::pair<address, uint64_t>>;
Copy link
Member

@axic axic Apr 14, 2023

Choose a reason for hiding this comment

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

Not necessary but perhaps a comment explaining what the value is and what range it has is useful (e.g. in gwei).

Copy link
Member Author

Choose a reason for hiding this comment

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

done

Copy link
Member

Choose a reason for hiding this comment

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

I think better will be to just define single using Withdrawal = std::pair<address, uint64_t>. But at this point a struct with named fields will do better.

[[nodiscard]] const auto& get_accounts() const noexcept { return m_accounts; }
};

using Withdrawals = std::vector<std::pair<address, uint64_t>>;
Copy link
Member

Choose a reason for hiding this comment

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

I think better will be to just define single using Withdrawal = std::pair<address, uint64_t>. But at this point a struct with named fields will do better.

@rodiazet rodiazet force-pushed the withdrawals-t8n branch 3 times, most recently from adf1def to 08cb281 Compare April 18, 2023 09:44

// Apply withdrawals. Amount value is in gwei.
for (const auto& withdraw : withdrawals)
state.touch(withdraw.first).balance += intx::uint256{withdraw.second} * 1000000000;
Copy link
Member

@axic axic Apr 20, 2023

Choose a reason for hiding this comment

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

Not sure if this is better but avoids counting zeroes:

Suggested change
state.touch(withdraw.first).balance += intx::uint256{withdraw.second} * 1000000000;
state.touch(withdraw.first).balance += intx::uint256{withdraw.second} * 1e9;

Not sure what is our preference in the codebase, @chfast.

Could also have constexpr helpers like from_gwei, which also removes the need for comments.

@rodiazet rodiazet force-pushed the withdrawals-t8n branch 2 times, most recently from ab1c40c to 02e6b21 Compare April 20, 2023 10:33
@axic axic force-pushed the withdrawals-t8n branch 8 times, most recently from 0fa05d0 to fe96d0e Compare April 20, 2023 11:50
EXPECT_EQ(bi.withdrawals[0].recipient, 0x0000000000000000000000000000000000000100_address);
EXPECT_EQ(bi.withdrawals[0].amount, 0x800000000);
EXPECT_EQ(bi.withdrawals[1].recipient, 0x0000000000000000000000000000000000000200_address);
EXPECT_EQ(bi.withdrawals[1].amount, 0xffffffffffffffff);
Copy link
Member

Choose a reason for hiding this comment

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

If we have the amount_wei helper, could also check for the output that here.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

}
};

using Withdrawals = std::vector<Withdrawal>;
Copy link
Member

Choose a reason for hiding this comment

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

This is not needed.

expect.post[create_address].code = bytes{0xFE};
}

TEST_F(state_transition, apply_withdrawal)
Copy link
Member

Choose a reason for hiding this comment

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

This should not be in "create" test suite. You need a new file, e.g. "block" or "env".

EXPECT_EQ(bi.number, 0);
EXPECT_EQ(bi.withdrawals.size(), 2);
EXPECT_EQ(bi.withdrawals[0].recipient, 0x0000000000000000000000000000000000000100_address);
EXPECT_EQ(bi.withdrawals[0].get_amount(), intx::uint256{0x800000000} * 1'000'000'000);
Copy link
Member

Choose a reason for hiding this comment

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

I think you should rather test .amount_in_gwei here.

Copy link
Member Author

@rodiazet rodiazet Apr 20, 2023

Choose a reason for hiding this comment

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

I wanted to test get_mount in one go too, but I can add additional check for gwei value only.

struct Withdrawal
{
address recipient;
/// The amount is denominated in gwei.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// The amount is denominated in gwei.
/// The amount is denominated in gwei.

or use ///<.

Copy link
Member

@chfast chfast left a comment

Choose a reason for hiding this comment

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

Please squash.

Copy link
Member

@axic axic left a comment

Choose a reason for hiding this comment

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

Looks good to me but please address @chfast's comments first.

Co-authored-by: Alex Beregszaszi <[email protected]>
@rodiazet rodiazet merged commit 62fb126 into master Apr 21, 2023
@rodiazet rodiazet deleted the withdrawals-t8n branch April 21, 2023 09:12
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.

4 participants