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

GetBodiesByRangeV1 implementation #4939

Merged
merged 5 commits into from
Dec 15, 2022
Merged

Conversation

deffrian
Copy link
Contributor

@deffrian deffrian commented Nov 27, 2022

Fixes | Closes | Resolves #

Changes:

Types of changes

What types of changes does your code introduce?
Put an x in the boxes that apply

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Other (please describe):

Testing

Have been tested manually with sepolia node.
Hive tests:
rpc
rpc-compat
engine

Requires testing

  • Yes
  • No

In case you checked yes, did you write tests??

  • Yes
  • No

@deffrian deffrian changed the title Feature/get bodies by range GetBodiesByRangeV1 implementation Nov 27, 2022
@deffrian deffrian marked this pull request as ready for review December 4, 2022 12:20
@flcl42 flcl42 self-requested a review December 6, 2022 07:39
{
List<ExecutionPayloadBodyV1Result> payloadBodies = new(blockHashes.Length);
List<ExecutionPayloadBodyV1Result?> payloadBodies = new(blockHashes.Length);
Copy link
Member

Choose a reason for hiding this comment

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

use Array here not list, can avoid later ToArray call.

ErrorCodes.LimitExceeded);
}

List<ExecutionPayloadBodyV1Result?> payloadBodies = new((int)count);
Copy link
Member

Choose a reason for hiding this comment

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

Just use Array

Comment on lines +36 to +41
var payloadBodies = new ExecutionPayloadBodyV1Result?[count];
for (int i = 0; i < count; i++)
{
Block? block = _blockTree.FindBlock(start + i);
payloadBodies[i] = block is not null ? new ExecutionPayloadBodyV1Result(block.Transactions) : null;
}
Copy link
Member

Choose a reason for hiding this comment

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

Question - maybe even better would be to change result from array to IEnumerable<> and go with yield return? Would avoid even more allocations.

Comment on lines +28 to +36
var payloadBodies = new ExecutionPayloadBodyV1Result?[blockHashes.Length];
for (int i = 0; i < blockHashes.Length; ++i)
{
Block? block = _blockTree.FindBlock(hash);
if (block is not null)
{
payloadBodies.Add(new ExecutionPayloadBodyV1Result(block.Transactions));
}
Block? block = _blockTree.FindBlock(blockHashes[i]);

payloadBodies[i] = block is not null ? new ExecutionPayloadBodyV1Result(block.Transactions) : null;
}

return Task.FromResult(ResultWrapper<ExecutionPayloadBodyV1Result[]>.Success(payloadBodies.ToArray()));
return Task.FromResult(ResultWrapper<ExecutionPayloadBodyV1Result?[]>.Success(payloadBodies));
Copy link
Member

Choose a reason for hiding this comment

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

Question - maybe even better would be to change result from array to IEnumerable<> and go with yield return? Would avoid even more allocations.

Copy link
Member

Choose a reason for hiding this comment

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

Would play less nicely with Exception though, as this would be evaluated during serialization.

Copy link
Member

Choose a reason for hiding this comment

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

One other idea to explore. With this branch: feature/json_dispose_result , we could use ArrayPoolList here. Just need to also dispose it if exception is thrown.

@MarekM25 MarekM25 merged commit ea34f6f into master Dec 15, 2022
@MarekM25 MarekM25 deleted the feature/get_bodies_by_range branch December 15, 2022 09:30
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