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

Add new JSON_RPC endpoints to get miner data by block number and block hash. #1538

Merged
merged 64 commits into from
Nov 6, 2020

Conversation

davemec
Copy link
Contributor

@davemec davemec commented Nov 5, 2020

PR description

Add new JSON_RPC endpoints to get miner data by block number and block hash.

Fixed Issue(s)

#1408

Changelog

David Mechler and others added 30 commits June 26, 2020 09:37
…d stack values

Signed-off-by: David Mechler <david.mechler@consensys.net>
Signed-off-by: David Mechler <david.mechler@consensys.net>
Signed-off-by: David Mechler <david.mechler@consensys.net>
…can occur

Signed-off-by: David Mechler <david.mechler@consensys.net>
…eation so that the hash can be managed.

Signed-off-by: David Mechler <david.mechler@consensys.net>
Signed-off-by: David Mechler <david.mechler@consensys.net>
Signed-off-by: David Mechler <david.mechler@consensys.net>
Signed-off-by: David Mechler <david.mechler@consensys.net>
Signed-off-by: David Mechler <david.mechler@consensys.net>
Signed-off-by: David Mechler <david.mechler@consensys.net>
Signed-off-by: David Mechler <david.mechler@consensys.net>
Signed-off-by: David Mechler <david.mechler@consensys.net>
Signed-off-by: David Mechler <david.mechler@consensys.net>
@davemec
Copy link
Contributor Author

davemec commented Nov 6, 2020

@richardpringle and @sammy1991106 please take a look at the changes and let me know if this is what you were expecting.

@davemec davemec requested a review from shemnon November 6, 2020 16:18
David Mechler added 2 commits November 6, 2020 12:15
Copy link
Contributor

@shemnon shemnon left a comment

Choose a reason for hiding this comment

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

  • safety bumpers around transaction receipt metadata reads
  • super class for the two RPC methods with a method that does all the math, taking a Block as an arg.

new BlockWithMetadata<>(
header, Collections.emptyList(), Collections.emptyList(), Difficulty.of(100L), 5);

Mockito.when(blockchainQueries.blockByNumber(Mockito.anyLong()))
Copy link
Contributor

Choose a reason for hiding this comment

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

Optional Style: Most of our mocking uses static import of .when() and (when not using the junit annotations) .mock(). Similarly for most of the Assertsions.* series to. This tends to make a more "readable" test at the expense of making it clear this is a Mockito method.

}

/*
Getting static block reward
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm surprised the google formatter didn't ask you to star indent this block.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment removed as this is no longer relevant.

pass in the block height (as a long) get the block reward (as wei)
each block spec has it. but it’s only meaningful w/in 6 blocks of the fork.

Didn’t happen at the two places we reduced block reward on mainnet. I say leave a comment but write no code.
Copy link
Contributor

Choose a reason for hiding this comment

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

Even though this is a slack quote it should be in a documentary tone. I'd also move it around 108-111 where the uncle reward calculation is calculated as it is a code relevant comment not a quasi-javadoc comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment removed as this is no longer relevant.

BlockWithMetadata<TransactionWithMetadata, Hash> block =
getBlockchainQueries().blockByNumber(blockNumber).orElse(null);

MinerDataResult minerDataResult = null;
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks duplicated from what is in EthGetMinerDataByBlockHash. This will burn us one day if we don't call a shared method. I'd recommend an AbstractMinerDataCall super class where this method is present and the two subclasses marshal the block by either hash or number.

If there are differences between the two then we need code comments pointing out the differences as the subtlety will be missed when we come back in the future,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added static method in EthGetMinerDataByBlockHash for both classes to call since EthGetMinerDataByBlockNumber has a parent.

if (withRevertReason && revertReason.isPresent()) {
out.writeBytes(revertReason.get());
if (withMetadata) {
out.writeBytes(revertReason.orElse(Bytes.EMPTY));
Copy link
Contributor

Choose a reason for hiding this comment

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

I had a comment written out about using out.writeNull if not present but when I looked at RLPOutput the impl is just to write empty bytes. Might be worth a comment pointing out that writing Bytes.EMPTY is the same as calling RLPOutput.writeNull

throw new RLPException("Unexpected value at end of TransactionReceipt");
}
revertReason = Optional.of(input.readBytes());
gasRemaining = input.readLong();
Copy link
Contributor

Choose a reason for hiding this comment

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

What about when we do a migration? What if we have an old DB with revert reason but not miner data and start extracting it? gasRemaining may not always be there.

I would wrap everything read after the metadataAllowed check in if (!input.isEndOfCurrentList()) { ... } individually as a safety measure. So two times in this case.

Copy link
Contributor Author

@davemec davemec Nov 6, 2020

Choose a reason for hiding this comment

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

Will wrap the gasRemaining read but the block starts with the check so the revertReason read is safe.

Signed-off-by: David Mechler <david.mechler@consensys.net>
David Mechler added 2 commits November 6, 2020 17:09
Signed-off-by: David Mechler <david.mechler@consensys.net>
Signed-off-by: David Mechler <david.mechler@consensys.net>
@davemec davemec merged commit 67191aa into hyperledger:master Nov 6, 2020
@sambacha
Copy link

sambacha commented Nov 7, 2020

Is there a new Postman def. for these included RPC calls?

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