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

Unwrap payload bid #14035

Merged
merged 16 commits into from
May 22, 2024
Merged

Unwrap payload bid #14035

merged 16 commits into from
May 22, 2024

Conversation

kasey
Copy link
Contributor

@kasey kasey commented May 22, 2024

What type of PR is this?

Other

What does this PR do? Why is it needed?

This PR removes the need for types that satisfy ExecutionData to internally carry bid values in wei/gwei. The payload bid is a separate piece of data from the payload and coupling them together creates complexity outside of the small proposal code path where it applies.

Which issues(s) does this PR fix?

This PR is setting the stage for further simplification of the consesus-types package. By bringing ExecutionData closer to the spec types, we can begin to reduce the number of different representations for the type.

This is a big set of changes but I built it up in layers, so if you look at the individual commits that should make the review more managable. Feedback to break this up to a smaller commit is welcome - I can strip off the newest commits that remove helper methods from consensus-types without breaking the earlier changes in proposal or engine code.

Comment on lines 293 to 295
//d := time.Now().Add(defaultEngineTimeout)
//ctx, cancel := context.WithDeadline(ctx, d)
//defer cancel()
Copy link
Member

Choose a reason for hiding this comment

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

What should we do about these commented code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

✂️

@@ -154,7 +155,7 @@ func TestConstructGenericBeaconBlock(t *testing.T) {
t.Run("phase0 block", func(t *testing.T) {
b, err := blocks.NewSignedBeaconBlock(util.NewBeaconBlock())
require.NoError(t, err)
result, err := vs.constructGenericBeaconBlock(b, nil)
result, err := vs.constructGenericBeaconBlock(b, nil, primitives.ZeroWei)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

note to self: primitives.ZeroWei should be a func that returns a new value each call. Returning a pointer type risks some code mutating it accidentally.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm going to fix this in a follow-up PR.

log.WithError(err).Error("Could not get builder payload")
} else if builderBid == nil {
builderGetPayloadMissCount.Inc()
log.WithError(err).Error("Could not get builder payload")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is wonky, I actually don't think we need to do anything if err == nil && builderBid == nil - this means getBuilderPayloadAndBlobs decided we didn't need to call the builder, because it's disabled or pre-bellatrix.

res, err := vs.ExecutionEngineCaller.GetPayload(ctx, pid, slot)
if err == nil {
//payload, bundle, overrideBuilder := res.ExecutionData, res.BlobsBundle, res.OverrideBuilder
//bundleCache.add(slot, bundle)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

✂️

return payload, overrideBuilder, nil

// TODO: remove bundleCache code
//bundleCache.add(slot, res.BlobsBundle)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

✂️

terencechain
terencechain previously approved these changes May 22, 2024
}
winningBid := primitives.ZeroWei
var bundle *enginev1.BlobsBundle
if slots.ToEpoch(sBlk.Block().Slot()) >= params.BeaconConfig().BellatrixForkEpoch {
Copy link
Contributor

Choose a reason for hiding this comment

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

dumb question maybe, do we have to check in this way to account for forks? instead of checking the block/state version?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As to why I did it this way, I think I was copying existing code in setExecutionData (which this method calls). I don't mind changing it though.

if err != nil {
return nil, nil, errors.Wrap(err, "could not wrap capella payload")
}
return w, nil, s.ErrSubmitBlindedBlock
case version.Deneb:
w, err := blocks.WrappedExecutionPayloadDeneb(s.PayloadDeneb, big.NewInt(0))
w, err := blocks.WrappedExecutionPayloadDeneb(s.PayloadDeneb)
Copy link
Contributor

Choose a reason for hiding this comment

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

should we add electra stuff in this PR? ( I saw some electra stuff but also a lot of other places not accounted for)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd rather not, I'm only touching electra stuff that needs to be changed in reaction to removing bids from the payload interface.

}

// Compare payload values between local and builder. Default to the local value if it is higher.
localValueGwei := primitives.WeiToGwei(local.Bid)
builderValueGwei := primitives.WeiToGwei(bid.WeiValue())
Copy link
Contributor

Choose a reason for hiding this comment

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

should we add a function on bid to return GweiValue instead? not sure which is more readable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I only added the WeiValue method because it encapsulates the tricky reversing logic for accessing a value that is directly stored by the type. IMO the gwei conversion is pretty trivial and doesn't warrant another method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also thinking about modifying the Value method to just be the WeiValue method since I don't think we want to expose the little endian version, but I'll need to double check usage.

}
return setExecution(blk, execution, false, kzgCommitments)
// TODO: plumb blobs bundle through here.
Copy link
Contributor

Choose a reason for hiding this comment

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

is this still a TODO?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nope, will delete

}

// warnIfFeeRecipientDiffers logs a warning if the fee recipient in the included payload does not
// match the requested one.
func warnIfFeeRecipientDiffers(payload interfaces.ExecutionData, feeRecipient primitives.ExecutionAddress) {
func warnIfFeeRecipientDiffers(payload, val []byte) {
Copy link
Contributor

Choose a reason for hiding this comment

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

these parameters feel harder to read, is there a better name for this? ( not a big deal , just a comment)

Copy link
Contributor Author

@kasey kasey May 22, 2024

Choose a reason for hiding this comment

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

I thought this was more clear since both parameters are fee recipients and now have the same type (previously one was called feeRecipient, which is also in the fuction name, and yeah they're both fee recipients). The function name tells you that you are comparing fee recipients, I figured it would be clear that one is the fee recipient from the payload, and the other is the one from the validator registration. Maybe the val name is too ambiguous and something like this would be more clear?
func warnIfFeeRecipientDiffers(payload, registration []byte) {

Copy link
Contributor

@james-prysm james-prysm May 22, 2024

Choose a reason for hiding this comment

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

func warnIfFeeRecipientDiffers(payload, registration []byte) {

yeah i think that may be better 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Even more simple: func warnIfFeeRecipientDiffers(want, got []byte) {

@kasey kasey enabled auto-merge May 22, 2024 21:58
@kasey kasey added this pull request to the merge queue May 22, 2024
Merged via the queue into develop with commit 2265af5 May 22, 2024
17 checks passed
@kasey kasey deleted the unwrap-payload-bid branch May 22, 2024 22:23
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.

3 participants