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 support for mining ommers, up to 8 blocks behind the head job #2576

Merged
merged 3 commits into from
Jul 27, 2021

Conversation

atoulme
Copy link
Contributor

@atoulme atoulme commented Jul 25, 2021

Signed-off-by: Antoine Toulme antoine@lunar-ocean.com

PR description

This allows miners to send solutions for blocks up to 8 blocks behind head, to be included as ommers.

Fixed Issue(s)

Fixes #2572

Changelog

Signed-off-by: Antoine Toulme <antoine@lunar-ocean.com>
import org.apache.tuweni.units.bigints.UInt256;

public class PoWSolver {

private static final long POW_JOB_TTL = 1000 * 60 * 5; // 5 minutes
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 value related to something ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not really. 13s per block on average, so 13 times 8 is 108s, times 2 makes 3 minutes and a half, and buffered to 5 minutes to ensure we catch stragglers. We can use a different approach. I have another ticket to add meters to count accepted solutions vs rejected solutions.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok it was to make sure I didn't miss anything. did you had the opportunity to test it ? I can test it on ropsten if you want

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 did not. I kinda wanted folks to review as well. I added some unit tests to make sure it made sense.

Copy link
Contributor

Choose a reason for hiding this comment

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

My instinct says this should be configurable. Probably via an --X flag.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is 5 minutes an ok default?

Copy link
Contributor

Choose a reason for hiding this comment

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

maybe 2x high? But since we are just keeping block headers (right?) from 5 min ago unless things get very hairy I don't see it causing resource problems. If we were keeping TXes it could be problematic.

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, only block headers. It should be fine.

final Optional<PoWSolution> calculatedSolution = testNonce(inputs, solution.getNonce());

if (calculatedSolution.isPresent()) {
LOG.debug("Accepting a solution from a miner");
currentJob.get().solvedWith(calculatedSolution.get());
currentJobs.remove(solution.getPowHash());
Copy link
Contributor

Choose a reason for hiding this comment

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

Does the miner want multiple ommers minable? Removing on the first solution precludes that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right now, we only accept one solution per block (the solveFor method blocks until the future completes). This repeats the same mechanism but with ommer blocks. We could potentially choose to allow more than one solution per block, turn those into ommers and replace the proposed block with the block with the best nonce. That's why I wanted a review, I'm just not sure how far to push this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To be clear, that'd be best addressed as a separate PR, because changing solveFor feels like a change worth doing on its own, whether we accept mining ommers or not.

@shemnon
Copy link
Contributor

shemnon commented Jul 26, 2021

Plumb the --X flag through to configure retention and I'll approve it unless someone from ConsenSys objects.

@atoulme atoulme force-pushed the add_ommer_mining_support branch from 814feaf to ad44007 Compare July 27, 2021 04:37
Signed-off-by: Antoine Toulme <antoine@lunar-ocean.com>
@atoulme atoulme force-pushed the add_ommer_mining_support branch from ad44007 to fa02aa0 Compare July 27, 2021 04:48
import org.apache.tuweni.units.bigints.UInt256;

public class PoWSolver {

private static final int MAX_OMMER_DEPTH = 8;
Copy link
Contributor

Choose a reason for hiding this comment

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

For another PR, another --X candidate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#2584 is open

@atoulme atoulme merged commit ea623a3 into hyperledger:master Jul 27, 2021
@atoulme atoulme deleted the add_ommer_mining_support branch July 27, 2021 16:38
eum602 pushed a commit to lacchain/besu that referenced this pull request Nov 3, 2023
…perledger#2576)

* Add support for mining ommers, up to 8 blocks behind the head job

Signed-off-by: Antoine Toulme <antoine@lunar-ocean.com>

* Add a CLI option to set PoW jobs TTL

Signed-off-by: Antoine Toulme <antoine@lunar-ocean.com>
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.

block creator: allow submitting 8-block deep uncle solutions
3 participants