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 requests to use flat encoding #7771

Merged
merged 38 commits into from
Oct 24, 2024
Merged

Conversation

jframe
Copy link
Contributor

@jframe jframe commented Oct 15, 2024

PR description

Update generalised request encoding for changes introduced in devnet4

EIP-7251: change request to flat encoding ethereum/EIPs#8857
EIP-6110: change request to flat encoding ethereum/EIPs#8856
EIP-7002: change request to flat encoding ethereum/EIPs#8855
EIP-7685: change requests hash to flat hash ethereum/EIPs#8854
EIP-7685: group requests into request-data ethereum/EIPs#8924
Make execution requests a sidecar, take 2 ethereum/execution-apis#591

Fixed Issue(s)

#7744

Thanks for sending a pull request! Have you done the following?

  • Checked out our contribution guidelines?
  • Considered documentation and added the doc-change-required label to this PR if updates are required.
  • Considered the changelog and included an update if required.
  • For database changes (e.g. KeyValueSegmentIdentifier) considered compatibility and performed forwards and backwards compatibility tests

Locally, you can run these tests to catch failures early:

  • unit tests: ./gradlew build
  • acceptance tests: ./gradlew acceptanceTest
  • integration tests: ./gradlew integrationTest
  • reference tests: ./gradlew ethereum:referenceTests:referenceTests

@Gabriel-Trintinalia
Copy link
Contributor

I would love to have Request renamed to ExecutionRequest everywhere but can be done later

Signed-off-by: Jason Frame <[email protected]>
Signed-off-by: Jason Frame <[email protected]>
@jframe jframe marked this pull request as ready for review October 23, 2024 04:20
/**
* Hash of empty requests or "0x6036c41849da9c076ed79654d434017387a88fb833c2856b32e18218b3341c5f"
*/
public static final Hash EMPTY_REQUESTS_HASH =
Copy link
Contributor

@Gabriel-Trintinalia Gabriel-Trintinalia Oct 24, 2024

Choose a reason for hiding this comment

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

Assuming this will change for devnet5?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep this will change for devnet5. Will create another PR for that change though

Comment on lines 55 to 58
if (!allRequestTypesAreContained(maybeRequests.get())) {
LOG.warn("Requests must contain all request types");
return false;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this work if we add a new request type for an futere fork?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No it won't work as the list of request types will be different for each fork. This will also need to change for upcoming execution request changes, as there could be empty requests.

Maybe we don't even need this check? Think only the first two validations are actually necessary

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed this size check since we won't be able do this soon with the upcoming changes anyway

Comment on lines 44 to 47
if (requests == null) {
requests = new ArrayList<>();
}
requests.add(r);
Copy link
Contributor

Choose a reason for hiding this comment

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

With this change, the only way to return Optional.Empty is a processor coordinator with no processors. We can throw an exception in the builder if trying to build with empty processors and simplify this method to return List

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nice suggestion. I've done that and also simplified the process method to use a stream because doesn't need to consider nulls now

@siladu
Copy link
Contributor

siladu commented Oct 24, 2024

@jframe fyi, I am in the middle of reviewing

@siladu
Copy link
Contributor

siladu commented Oct 24, 2024

I would love to have Request renamed to ExecutionRequest everywhere but can be done later

Maybe even EngineExecutionRequest to further refine the scope?

ExecutionRequest still pretty generic, unless understood within the context of the Engine API.

If we need to cross a boundary from engine API to core domain, then does something like SystemCallRequest make sense?

@Gabriel-Trintinalia
Copy link
Contributor

I would love to have Request renamed to ExecutionRequest everywhere but can be done later

Maybe even EngineExecutionRequest to further refine the scope?

ExecutionRequest still pretty generic, unless understood within the context of the Engine API.

If we need to cross a boundary from engine API to core domain, then does something like SystemCallRequest make sense?

We have the deposit request that is not a a system call

@siladu
Copy link
Contributor

siladu commented Oct 24, 2024

We have the deposit request that is not a a system call

ContractRequest?? 😅

@Gabriel-Trintinalia
Copy link
Contributor

We have the deposit request that is not a a system call

ContractRequest?? 😅

CLRequest? ConsensusRequest? EngineRequest?

@jframe
Copy link
Contributor Author

jframe commented Oct 24, 2024

My preference is for ExecutionRequest and it also matches with what it's called in the engine API spec. In EIP 7685 it's just called Requests but easy enough to know it means ExecutionRequests.

Also rather do that change in a separate PR once we agree on a name.

Copy link
Contributor

@siladu siladu left a comment

Choose a reason for hiding this comment

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

Sooo much deleted code, love it! +1,099 −5,067 Kudos to the spec authors too🏅

A few nits and questions - happy to approve if you think there's nothing further to change based on my comments.

@@ -106,6 +106,7 @@ public JsonRpcResponse process(
case INVALID_PROPOSAL_PARAMS:
case INVALID_REMOTE_CAPABILITIES_PARAMS:
case INVALID_REWARD_PERCENTILES_PARAMS:
case INVALID_REQUESTS_PARAMS:
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: a little close to INVALID_REQUEST, maybe we could namespace with something, e.g. INVALID_EXECUTION_REQUESTS_PARAMS or
INVALID_ENGINE_NEW_PAYLOAD_REQUESTS_PARAMS (others already use this prefix)

General point: "requests" is a very overloaded name
Saw Gabriel mentioned changing to executionRequests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good idea, changed it to INVALID_EXECUTION_REQUESTS_PARAMS

Comment on lines 58 to 59
return IntStream.range(0, requests.size() - 1)
.allMatch(i -> requests.get(i).getType().compareTo(requests.get(i + 1).getType()) <= 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: guava has quite a neat way of doing this

Suggested change
return IntStream.range(0, requests.size() - 1)
.allMatch(i -> requests.get(i).getType().compareTo(requests.get(i + 1).getType()) <= 0);
return Ordering.natural().onResultOf(Request::getType).isOrdered(requests);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nice! much less code

Copy link
Contributor

Choose a reason for hiding this comment

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

Enjoying the removal of lots of code, esp in this class :)

Comment on lines 145 to 149
if (yield.isEmpty()) {
return Optional.empty();
} else {
return yield.get().getRequests();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (yield.isEmpty()) {
return Optional.empty();
} else {
return yield.get().getRequests();
}
return yield.flatMap(BlockProcessingOutputs::getRequests);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

.flatMap(receipt -> receipt.getLogsList().stream())
.filter(log -> address.equals(log.getLogger()))
.map(DepositLogDecoder::decodeFromLog)
.reduce(Bytes::concatenate));
Copy link
Contributor

Choose a reason for hiding this comment

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

a nice fix for java stream junkies here ;)

Copy link
Contributor

@siladu siladu left a comment

Choose a reason for hiding this comment

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

My remaining unresolved comments are only nits, nice to haves or namings

@jframe jframe enabled auto-merge (squash) October 24, 2024 08:27
@jframe jframe merged commit f16d352 into hyperledger:main Oct 24, 2024
43 checks passed
@jframe jframe deleted the 7685_flat_encoding branch October 24, 2024 09:06
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.

4 participants