-
Notifications
You must be signed in to change notification settings - Fork 293
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
Support withdrawals in t8n #614
Conversation
test/t8n/t8n.cpp
Outdated
@@ -160,6 +160,10 @@ int main(int argc, const char* argv[]) | |||
if (block_reward.has_value()) | |||
state.touch(block.coinbase).balance += *block_reward; | |||
|
|||
// 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.
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?
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.
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.
|
test/state/state.hpp
Outdated
@@ -66,6 +66,8 @@ class State | |||
[[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.
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).
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.
done
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 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.
test/state/state.hpp
Outdated
@@ -66,6 +66,8 @@ class State | |||
[[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.
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.
adf1def
to
08cb281
Compare
test/state/state.cpp
Outdated
|
||
// 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.
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:
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.
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.
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.
done
b6435c7
to
849d4f6
Compare
test/state/state.hpp
Outdated
} | ||
}; | ||
|
||
using Withdrawals = std::vector<Withdrawal>; |
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.
This is not needed.
@@ -32,3 +32,11 @@ TEST_F(state_transition, create_tx) | |||
|
|||
expect.post[create_address].code = bytes{0xFE}; | |||
} | |||
|
|||
TEST_F(state_transition, apply_withdrawal) |
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.
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.
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.
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 wanted to test get_mount
in one go too, but I can add additional check for gwei value only.
test/state/state.hpp
Outdated
struct Withdrawal | ||
{ | ||
address recipient; | ||
/// The amount is denominated in gwei. |
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 amount is denominated in gwei. | |
/// The amount is denominated in gwei. |
or use ///<
.
849d4f6
to
0150610
Compare
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.
Please squash.
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.
Looks good to me but please address @chfast's comments first.
Co-authored-by: Alex Beregszaszi <alex@rtfs.hu>
0150610
to
f062020
Compare
execution-spec-tests