[Mining] Build empty block on when chainTip changes. #7104

pull pstratem wants to merge 3 commits into bitcoin:master from pstratem:2015-11-26-gbt-latency changing 3 files +123 −116
  1. pstratem commented at 2:42 PM on November 26, 2015: contributor

    Reduce latency of switching to new block.

    Edit: I'm not really sure this is a good idea.

  2. petertodd commented at 10:24 PM on November 26, 2015: contributor

    We're still building on a fully validated chainTip right?

    Personally I'd even go as far as saying we should explicitly support SPV mining, so this is definitely a Concept ACK for me.

  3. pstratem commented at 10:40 PM on November 26, 2015: contributor

    @petertodd That's correct.

  4. jameshilliard commented at 6:30 AM on November 27, 2015: contributor

    @pstratem This should probably be a configurable option. I'm also not entirely sure how this would affect block notifys, maybe one way to handle this would be to have two notify triggers, one for when the empty template is ready and one when the full is so that the stratum server can push out full templates as soon as they are ready. @petertodd I'm not sure how one could properly implement SPV mining, even if you implement a timeout you can't easily roll back stratum templates to the previous block in most(maybe all) the deployed cgminer versions.

  5. pstratem commented at 6:51 AM on November 27, 2015: contributor

    @jameshilliard I don't see the point of it being a configurable option.

    Using blocknotify only is dangerous, you can and will miss notifications. Because of this the only wy to get a truly low latency pool is to run multiple bitcoind nodes and merge the result of getblocktemplate at the pool level.

  6. jameshilliard commented at 7:01 AM on November 27, 2015: contributor

    @pstratem The point for having it configurable would be in cases where this makes a minimal difference in GBT times while at the same having higher costs for sending stratum updates(I could potentially see this as an issue for some pools with very large amounts of connections).

    The current behavior with ckpool for is that a notify immediately triggers a GBT call and template update in addition to the normal 30 second GBT polls. How would using only blocknotify's miss notifications, is it not reliable in core? I haven't noticed any reliability issues with blocknotify(from my benchmarking the 3 public ckpool based pools are generally some of the fastest pools to send out updates aside from f2pool and btcchina, which SPV mine of course).

  7. dcousens commented at 7:09 AM on November 27, 2015: contributor

    Using blocknotify only is dangerous, you can and will miss notifications.

    That sounds like the bigger problem here?

  8. pstratem commented at 7:11 AM on November 27, 2015: contributor

    @dcousens There isn't a reasonable way to ensure that the notifications are delivered and correctly processed.

    It's a byzantine consensus problem all by itself.

  9. pstratem commented at 7:13 AM on November 27, 2015: contributor

    @jameshilliard And what happens when the notify triggers during the middle of a getblocktemplate scheduled poll? It stalls for the full interval of a getblocktemplate call.

    That's the last piece of optimization advice I'm ever giving to anybody concerning ckpool.

  10. dcousens commented at 7:24 AM on November 27, 2015: contributor

    It's a byzantine consensus problem all by itself.

    That should only be the case in terms of the network consistently receiving the same notifications, not whether our software processes notifications or not. If a block notification happens [locally], it should be processed deterministically?

  11. jameshilliard commented at 7:30 AM on November 27, 2015: contributor

    @pstratem what's the best way to handle this situation? If the getblocktemplate call from the scheduled poll returns an updated template it will get pushed out to miners anyways(shouldn't bitcoind be interrupting CNB and rerunning it if a new block comes in?), I thought CNB is single threaded and that doing simultaneous getblocktemplate calls would not make the second return any faster.

  12. pstratem commented at 7:33 AM on November 27, 2015: contributor

    @dcousens blocknotify can fail in a bunch of ways that getblocktemplate calls cannot.

    Relying on it for low latency operation is a Bad Idea (tm).

  13. jonasschnelli added the label Mining on Nov 27, 2015
  14. gmaxwell commented at 7:36 PM on November 27, 2015: contributor

    @jameshilliard In any case, in the example that you gave you'll pick up the new work at the 30 second poll; which isn't so unreasonable (it's a 5% capacity loss); especially compared to avoiding parties mining without validation which radically undermines the security assumptions of lite wallets.

    A simple heuristic would be to decrease the poll interval to 2 seconds when the current template is under a threshold size... but I expect people don't actually want to issue reissue work that fast in any case.

    Alternatively, one can immediately poll GBT again after getting the empty result; and hold off on notifying miners until it results, but use the empty template for any work requests that come in while waiting. @pstratem One thing you could do instead is have a fast argument to GBT that only returns cached or empty templates. (IMO fast should be the default: to do otherwise is to just set a trap for users, but I don't think it's worth arguing with anyone.)

  15. jameshilliard commented at 10:32 PM on November 27, 2015: contributor

    @gmaxwell Current behavior is to queue the notify and issue another GBT request right after the scheduled one finishes, this usually results in two quick stratum updates one right after the other. I think it would be ideal if core would make sure the first one always return updated work that way updates can be pushed out faster since you wouldn't have to wait for the second to return.

    but I expect people don't actually want to issue reissue work that fast in any case.

    This isn't really an issue for most smaller pools AFAIK.

  16. pstratem commented at 10:21 AM on November 29, 2015: contributor

    @gmaxwell it cant be based on a parameter since you dont know whether you want a fast call until you've already made the call

  17. pstratem commented at 10:41 AM on December 1, 2015: contributor

    Modified to interact with the long polling code.

    Now we will return an empty block only to longpoll callers.

    This has the advantage of supporting multiple callers that want an empty template.

  18. Build empty block on when chainTip changes.
    Reduce latency of switching to new block.
    2ff742fd78
  19. Place all of the transaction selection logic in conditional gated by fBuildEmptyBlock 16ca72bd68
  20. Move nMedianTimePast into select transactions block. b3c5a91332
  21. pstratem closed this on Dec 13, 2015

  22. DrahtBot locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-19 00:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me