Skip to content

Conversation

Sjors
Copy link
Owner

@Sjors Sjors commented Jul 22, 2024

This adds waitFeesChanged() to the Mining interface.

The Stratum v2 protocol allows pushing out templates as fees in the mempool increase. This interface lets us know when it's time to do so.

Without Cluster Mempool however the implementation is "fake", instead returning every time a transaction is added to the mempool. So for now I'm keeping this draft. It's here to provide a complete and stable Mining interface for bitcoin#30437 to build on.

Unlike the entire Mining interface so far, this is not a refactor. It adds new functionality.

The current implementation is very similiar to how longpolling in getblocktemplate works, which checks getTransactionsUpdated every 10 seconds.

However once Cluster Mempool is added it will be cheap enough to frequently generate a block template, check if the fees have gone up enough and then return. That would cause a behaviour change if getblocktemplate were to use waitFeesChanged(), which is why this PR does not touch the longpolling code.

TODO:

  • try with (draft) cluster mempool branch

@Sjors
Copy link
Owner Author

Sjors commented Jul 22, 2024

@sdaftuar @sipa repeating my comment from bitcoin#30443 (with updated code).

I made a branch sv2-cluster that combines bitcoin#28676 with bitcoin#29432:

The main commit is bitcoin@625e444. The waitFeesChanged() interface implementation now frequently creates a new template.

The Template Provider then uses that to see if sending a new NewTemplate message is justified.

It still takes 20-30ms on mainnet to create a template, without or the cluster mempool changes. I guess BlockAssembler::CreateNewBlock doesn't actually take advance of it? How would I go about getting the total fees for the first block?

You can see it in action using src/bitcoind -sv2 -debug=sv2 -loglevel=sv2:trace

Once the node is at the tip you'll see frequent [sv2:trace] Assemble template: ...ms messages. (this even works without a connected SRI client, which is a convenient bug)

It doesn't have to be very precise. The user can configure -sv2delta as a threshold for when to send out new templates, but we can be off by a bit. The actual block is constructed later.

@Sjors Sjors force-pushed the 2024/07/mining-fees-changed branch from c0408d6 to 9a723c7 Compare September 30, 2024 18:15
@Sjors
Copy link
Owner Author

Sjors commented Sep 30, 2024

Reopening this on the main repo at bitcoin#31003

@Sjors Sjors closed this Sep 30, 2024
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.

1 participant