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

starts engine_preparePayload and engine_getPayload API call implementation #4371

Merged
merged 8 commits into from
Sep 17, 2021

Conversation

tbenr
Copy link
Contributor

@tbenr tbenr commented Sep 15, 2021

changelog:

  • introduces Duty preparation
  • uses Duty preparation in BlockProductionDuty to handle the call to the execution engine to prepare the block
  • starts extending other required classes to be able to call the new method
  • currently we are using slot as payloadId

introduces Duty preparation
uses Duty preparation in BlockProductionDuty to handle the call to the execution engine to prepare the block
starts extending other required classes to be able to call the new method
@tbenr tbenr changed the title starts the work for engine_preparePayload API call (#4346) implements engine API calls (#4346) Sep 15, 2021
public SafeFuture<Void> prepareDuty() {
executionPayloadRequestId =
UInt64.fromLongBits(SecureRandomProvider.publicSecureRandom().nextLong());
return validatorApiChannel.prepareExecutionPayload(slot, executionPayloadRequestId);
Copy link
Contributor

Choose a reason for hiding this comment

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

I would move this field initialization to the constructor and make it final
Does it make sense using random() for generating requestId here? Wouldn't a simple counter be enough?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the idea was to avoid any potential concurrency issues (can they happen here?) and generate different id in case of duty prepared twice (late consensus block arrival). In the latter I assumed we need to refresh the requestId (going to change it to payloadId as per latest HackMD update).

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, I follow the logic now... prepareDuty() is designed to be called more than once

Copy link
Contributor

Choose a reason for hiding this comment

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

I would suggest using AtomicInteger here even if it's a static field to generate rather than random. There's no reason we need to be using a secure random at this point.

I do wonder if we should be using the same requestId when we resend prepareDuty though - otherwise we're leaving the previous "prepare" call hanging and it will never be cancelled or followed by "get". Might be a question for the API spec as much as anything.

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 moved to AtomicLong and made executionPayloadId constant at every preparation

@tbenr tbenr changed the title implements engine API calls (#4346) starts engine_preparePayload API call implementation Sep 15, 2021
@Nashatyrev
Copy link
Contributor

Nashatyrev commented Sep 15, 2021

BTW, should the preparePayload be called on reorg?
Or just a new Duty recreated on reorg?

@tbenr
Copy link
Contributor Author

tbenr commented Sep 15, 2021

BTW, should the preparePayload be called on reorg?
Or just a new Duty recreated on reorg?

oh, I see onChainReorg event in DutyScheduler. But does it trigger an onAttestationCreationDue for the same slot in any case? Here I need @ajsutton :-)

@ajsutton
Copy link
Contributor

BTW, should the preparePayload be called on reorg?
Or just a new Duty recreated on reorg?

oh, I see onChainReorg event in DutyScheduler. But does it trigger an onAttestationCreationDue for the same slot in any case? Here I need @ajsutton :-)

It's not necessarily a chain reorg that triggers calling prepare again but any head update. The most common case will be that we're proposing at slot X and the block at X-1 is received late. That's a normal head update to fill the empty slot but it still changes the parent root of the block we'll create so need to send a new prepare call.

You should get another call to onAttestationCreationDue in that case - the duplicates are filtered by AbstractDutyScheduler.onProductionDue where it checks lastProductionSlot and we just don't want to do that same kind of check for preparations.

@tbenr tbenr changed the title starts engine_preparePayload API call implementation starts engine_preparePayload and engine_getPayload API call implementation Sep 16, 2021
@tbenr
Copy link
Contributor Author

tbenr commented Sep 16, 2021

@ajsutton a unit test is still failing i guess not related to current PR (GetPeersScoreTest)

btw I was trying to focus on preparePayload only but I ended up starting getPayload as well (they are quite related)

Copy link
Contributor

@Nashatyrev Nashatyrev left a comment

Choose a reason for hiding this comment

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

LGTM

@tbenr tbenr marked this pull request as ready for review September 17, 2021 12:26
@tbenr tbenr merged commit 57fe174 into Consensys:merge-interop Sep 17, 2021
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