Support withdrawals in t8n#614
Conversation
|
|
||
| // Apply withdrawals. Amount value is in gwei. | ||
| for (const auto& withdraw : block.withdrawals) | ||
| state.touch(withdraw.first).balance += withdraw.second * 1000000000; |
There was a problem hiding this comment.
Are withdrawals applies before block finalization? I.e. are touched accounts possibly removed?
There was a problem hiding this comment.
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
f942863 to
815339a
Compare
Codecov Report
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
Flags with carried forward coverage won't be shown. Click here to find out more.
|
| [[nodiscard]] const auto& get_accounts() const noexcept { return m_accounts; } | ||
| }; | ||
|
|
||
| using Withdrawals = std::vector<std::pair<address, uint64_t>>; |
There was a problem hiding this comment.
Not necessary but perhaps a comment explaining what the value is and what range it has is useful (e.g. in gwei).
There was a problem hiding this comment.
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>>; |
There was a problem hiding this comment.
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.
adf1def to
08cb281
Compare
|
|
||
| // Apply withdrawals. Amount value is in gwei. | ||
| for (const auto& withdraw : withdrawals) | ||
| state.touch(withdraw.first).balance += intx::uint256{withdraw.second} * 1000000000; |
There was a problem hiding this comment.
Not sure if this is better but avoids counting zeroes:
| 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.
ab1c40c to
02e6b21
Compare
0fa05d0 to
fe96d0e
Compare
| 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); |
There was a problem hiding this comment.
If we have the amount_wei helper, could also check for the output that here.
b6435c7 to
849d4f6
Compare
| } | ||
| }; | ||
|
|
||
| using Withdrawals = std::vector<Withdrawal>; |
| expect.post[create_address].code = bytes{0xFE}; | ||
| } | ||
|
|
||
| TEST_F(state_transition, apply_withdrawal) |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
I think you should rather test .amount_in_gwei here.
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
| /// The amount is denominated in gwei. | |
| /// The amount is denominated in gwei. |
or use ///<.
849d4f6 to
0150610
Compare
Co-authored-by: Alex Beregszaszi <[email protected]>
0150610 to
f062020
Compare
Co-authored-by: Alex Beregszaszi <[email protected]>
execution-spec-tests