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

Change native execution value to Gwei Uint64 #12291

Merged
merged 15 commits into from
Apr 22, 2023

Conversation

terencechain
Copy link
Member

@terencechain terencechain commented Apr 16, 2023

Following up #12290, Default execution value type to uin64. Consensus layer uses gwei as the primitive type so it's better to have that as the native first class citizen rather than using big.Int

@terencechain terencechain self-assigned this Apr 16, 2023
@terencechain terencechain requested a review from a team as a code owner April 16, 2023 23:59
Comment on lines 164 to 167
v := big.NewInt(0).SetBytes(bytesutil.ReverseByteOrder(b.p.Value))
gweiPerEth := big.NewInt(int64(params.BeaconConfig().GweiPerEth))
v.Div(v, gweiPerEth)
return blocks.WrappedExecutionPayloadHeaderCapella(b.p.Header, v.Uint64())
Copy link
Member Author

Choose a reason for hiding this comment

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

Thinking this may be better to be its own helper

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah I feel like we should have helper of the form
func (z *Int) ToGwei() uint64

@terencechain terencechain added the Blocked Blocked by research or external factors label Apr 17, 2023
@terencechain terencechain removed the Blocked Blocked by research or external factors label Apr 18, 2023
@terencechain terencechain added the Ready For Review A pull request ready for code review label Apr 19, 2023
@@ -160,8 +161,10 @@ func WrappedBuilderBidCapella(p *ethpb.BuilderBidCapella) (Bid, error) {
// Header returns the execution data interface.
func (b builderBidCapella) Header() (interfaces.ExecutionData, error) {
// We have to convert big endian to little endian because the value is coming from the execution layer.
v := bytesutil.ReverseByteOrder(b.p.Value)
return blocks.WrappedExecutionPayloadHeaderCapella(b.p.Header, big.NewInt(0).SetBytes(v))
v := big.NewInt(0).SetBytes(bytesutil.ReverseByteOrder(b.p.Value))
Copy link
Contributor

Choose a reason for hiding this comment

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

Should protect for p == nil here.

Comment on lines 164 to 167
v := big.NewInt(0).SetBytes(bytesutil.ReverseByteOrder(b.p.Value))
gweiPerEth := big.NewInt(int64(params.BeaconConfig().GweiPerEth))
v.Div(v, gweiPerEth)
return blocks.WrappedExecutionPayloadHeaderCapella(b.p.Header, v.Uint64())
Copy link
Contributor

Choose a reason for hiding this comment

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

yeah I feel like we should have helper of the form
func (z *Int) ToGwei() uint64

@@ -258,10 +258,9 @@ func TestClient_HTTP(t *testing.T) {
require.DeepEqual(t, want.ExecutionPayload.PrevRandao.Bytes(), pb.PrevRandao)
require.DeepEqual(t, want.ExecutionPayload.ParentHash.Bytes(), pb.ParentHash)

v, err := resp.Value()
v, err := resp.ValueInGwei()
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel it's fine to keep this one as Value() all values in the CL are Gwei after this change

Copy link
Member Author

Choose a reason for hiding this comment

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

resp is already interface.ExecutionData. Do you want me to have both Value and ValueInGwei getters for ExecutionData?

vs := &Server{
ExecutionEngineCaller: &powtesting.EngineClient{PayloadIDBytes: id, ExecutionPayloadCapella: &v1.ExecutionPayloadCapella{BlockNumber: 1, Withdrawals: withdrawals}, BlockValue: big.NewInt(18395081606530051)},
ExecutionEngineCaller: &powtesting.EngineClient{PayloadIDBytes: id, ExecutionPayloadCapella: &v1.ExecutionPayloadCapella{BlockNumber: 1, Withdrawals: withdrawals}, BlockValue: v.Uint64()},
Copy link
Contributor

Choose a reason for hiding this comment

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

Simply but the Gwei value for the test and avoid the big Int arithmetics here.

@@ -331,7 +333,7 @@ func TestNoWeiOverflow(t *testing.T) {

blk, err := blocks.NewSignedBeaconBlock(util.NewBeaconBlockCapella())
require.NoError(t, err)
vs.ExecutionEngineCaller = &powtesting.EngineClient{PayloadIDBytes: id, ExecutionPayloadCapella: &v1.ExecutionPayloadCapella{BlockNumber: 3, Withdrawals: withdrawals}, BlockValue: big.NewInt(162927606e9)} // 0.16 ETH
vs.ExecutionEngineCaller = &powtesting.EngineClient{PayloadIDBytes: id, ExecutionPayloadCapella: &v1.ExecutionPayloadCapella{BlockNumber: 3, Withdrawals: withdrawals}, BlockValue: 162927606} // 0.16 ETH
Copy link
Contributor

Choose a reason for hiding this comment

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

In fact probably this test can be completely removed as there's no overflow to test anymore.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll just remove the test

@@ -323,7 +322,7 @@ func createWrappedPayloadHeaderCapella(t testing.TB) interfaces.ExecutionData {
BlockHash: make([]byte, fieldparams.RootLength),
TransactionsRoot: make([]byte, fieldparams.RootLength),
WithdrawalsRoot: make([]byte, fieldparams.RootLength),
}, big.NewInt(11))
}, 11)
Copy link
Contributor

Choose a reason for hiding this comment

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

This number is not used right? cause I don't see it tested anywhere, and if it was 11 Wei before, it should be 0 Gwei now I guess

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point. Changed it to 0s

@prylabs-bulldozer prylabs-bulldozer bot merged commit 08d6ecc into develop Apr 22, 2023
@delete-merged-branch delete-merged-branch bot deleted the default-value-uint64 branch April 22, 2023 00:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ready For Review A pull request ready for code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants