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

upgrade Job Declaration and Mining Protocols #121

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

plebhash
Copy link
Contributor

@plebhash plebhash commented Jan 17, 2025

close #120

changes are divided by commits:

for easier review, I recommend this Markdown rendering on my fork

@plebhash plebhash force-pushed the upgrade-jdp branch 3 times, most recently from d7dbd0b to 22fb563 Compare January 17, 2025 23:22
@plebhash plebhash force-pushed the upgrade-jdp branch 6 times, most recently from c3baaca to 5583c11 Compare January 23, 2025 14:59
@plebhash plebhash changed the title [WIP] upgrade Job Declaration Protocol [WIP] upgrade Job Declaration and Mining Protocols Jan 23, 2025
@Sjors
Copy link
Contributor

Sjors commented Jan 24, 2025

I don't think it's wise to have two messages in the spec called SubmitSolution, defined in two different places and with different content. Imo they should either be unified and defined in one place, or one needs a new name.

06-Job-Declaration-Protocol.md Outdated Show resolved Hide resolved
06-Job-Declaration-Protocol.md Outdated Show resolved Hide resolved
06-Job-Declaration-Protocol.md Show resolved Hide resolved
06-Job-Declaration-Protocol.md Outdated Show resolved Hide resolved
06-Job-Declaration-Protocol.md Outdated Show resolved Hide resolved
@plebhash
Copy link
Contributor Author

I don't think it's wise to have two messages in the spec called SubmitSolution, defined in two different places and with different content. Imo they should either be unified and defined in one place, or one needs a new name.

I don't think it's possible to unify them, as one is meant for TP and the other for JDS (and each needs different parts of the solution)

I'm not opposed to renaming either one of them or both, but it would be good to get input from @Fi3 and @TheBlueMatt on this

@plebhash plebhash marked this pull request as ready for review January 24, 2025 13:57
@plebhash plebhash changed the title [WIP] upgrade Job Declaration and Mining Protocols upgrade Job Declaration and Mining Protocols Jan 24, 2025
05-Mining-Protocol.md Outdated Show resolved Hide resolved
@@ -470,8 +469,6 @@ The `mining_job_token` provides the information for the pool to authorize the cu
| coinbase_tx_outputs | B0_64K | Bitcoin transaction outputs to be included as the last outputs in the coinbase transaction |
| coinbase_tx_locktime | U32 | The locktime field in the coinbase transaction |
| merkle_path | SEQ0_255[U256] | Merkle path hashes ordered from deepest |
| extranonce_size | U16 | Size of extranonce in bytes that will be provided by the downstream node |
Copy link
Contributor

Choose a reason for hiding this comment

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

why you remove this? Is this ok with braiins as well @jakubtrnka?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

from discussions on Google Doc:

@TheBlueMatt said:

I do kinda wonder if we shouldn't drop all the extranonce size accounting (for custom work)... Like, the pool doesn't care what the extranonce size is, as long as its extranonce_prefix is honored. The extranonce prefix has a strict limit of 32 bytes, the server is expected to build the coinbase tx from the extranonce, the length is never given on the wire, why do we care here?

For extended channels, the extranonce length is included in coinbase_prefix, so the pool needs to know the extranonce length when it goes to send that. The same is not true anywhere in custom work. IMO the field should be dropped.

then @Fi3 said:

make totally sense, this is a very big change btw. I think that we should coordinate it at least with braiins if we decide to do it.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok just make sure that braiins is ok with this change

@@ -470,8 +469,6 @@ The `mining_job_token` provides the information for the pool to authorize the cu
| coinbase_tx_outputs | B0_64K | Bitcoin transaction outputs to be included as the last outputs in the coinbase transaction |
| coinbase_tx_locktime | U32 | The locktime field in the coinbase transaction |
| merkle_path | SEQ0_255[U256] | Merkle path hashes ordered from deepest |
| extranonce_size | U16 | Size of extranonce in bytes that will be provided by the downstream node |
| min_ntime | OPTION[u32] | TBD: Can custom job ever be future? |
Copy link
Contributor

Choose a reason for hiding this comment

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

why you remove this? Is this ok with braiins as well @jakubtrnka?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's duplicated... if you look above, you'll see that there's already a min_ntime field in SetCustomMiningJob

this field has data type OPTION[u32] and the description is TBD: Can custom job ever be future?

so the real purpose of this duplicate is not very clear... in case there's some meaningful motivation and we cannot remove it, we should at least clarify this motivation in the spec

@@ -75,45 +125,40 @@ Notably, if the pool intends to change the space it requires for coinbase transa
| request_id | U32 | Unique identifier for pairing the response |
| mining_job_token | B0_255 | Token that makes the client eligible for committing a mining job for approval/transaction declaration or for identifying custom mining job on mining connection. |
| coinbase_output_max_additional_size | U32 | The maximum additional serialized bytes which the pool will add in coinbase transaction outputs. See discussion in the Template Distribution Protocol's CoinbaseOutputDataSize message for more details. |
| async_mining_allowed | BOOL | If true, the mining_job_token can be used immediately on a mining connection in the SetCustomMiningJob message, even before DeclareMiningJob and DeclareMiningJob.Success messages have been sent and received. If false, Job Declarator MUST use this token for DeclareMiningJob only. <br>This MUST be true when SetupConnection.flags had REQUIRES_ASYNC_JOB_MINING set. |
Copy link
Contributor

Choose a reason for hiding this comment

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

how the upstream communicate if the token is for coinbase-only mode or for full-template mode?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

by simply allowing the connection to be established or not

when JDC sends SetupConnection, the DECLARE_TX_DATA bit flag is used to signal that it consents to revealing the txs... then it's up to JDS to decide whether this is ok or not

so we have 4 possible scenarios:

JDS allows Coinbase-only mode JDS does NOT allow Coinbase-only mode
JDC sets DECLARE_TX_DATA SetupConnection.Success SetupConnection.Success
JDC does NOT set DECLARE_TX_DATA SetupConnection.Success SetupConnection.Error (unsupported-feature-flags)

do you feel this still leaves room for unspecified scenarios?

Copy link
Contributor Author

@plebhash plebhash Jan 28, 2025

Choose a reason for hiding this comment

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

I guess this is heavily based on the assumption that JDS will operate EITHER under Coinbase-only OR Full-Template, but not BOTH at the same time.

If we want to allow for JDS to operate under both at the same time, then I see how DECLARE_TX_DATA is not sufficient, as JDC wouldn't know under which mode the token is supposed to be used.

So I guess the question is: does this scenario make sense? Can JDS ever allow for both Coinbase-only and Full-Template at the same time? TBH it doesn't really make much sense in my head, but maybe I have some blindspot.

| tx_short_hash_nonce | U64 | A unique nonce used to ensure tx_short_hash collisions are uncorrelated across the network |
| tx_short_hash_list | SEQ0_64K[SHORT_TX_ID] | Sequence of SHORT_TX_IDs. Inputs to the SipHash functions are transaction hashes from the mempool. Secret keys k0, k1 are derived from the first two little-endian 64-bit integers from the SHA256(tx_short_hash_nonce), respectively (see bip-0152 for more information). Upstream node checks the list against its mempool. Does not include the coinbase transaction (as there is no corresponding full data for it yet). |
| tx_hash_list_hash | U256 | SHA256 hash of the list of full txids, concatenated in the same sequence as they are declared in the_short_hash_list |
| prev_hash | U256 | Chain tip that the template is based on. JDS SHOULD accept templates based on different tips, as long as they are on the best block height. JDS MUST reject templates based on old tips. |
Copy link
Contributor

Choose a reason for hiding this comment

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

can we make this field optional?

Copy link
Contributor Author

@plebhash plebhash Jan 28, 2025

Choose a reason for hiding this comment

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

what would be the rationale?

I assume you want to give room for a scenario where JDS is allowed to ignore prev_hash on DeclareMiningJob, which leaves us with the following possibilities:

JDS cares about prev_hash JDS does NOT care about prev_hash
DeclareMiningJob sets prev_hash JDS verifies prev_hash JDS ignores prev_hash

or maybe DeclareMiningJob.Error to discourage unnecessary bandwidth consumption
DeclareMiningJob does NOT set prev_hash DeclareMiningJob.Error (invalid-job-param-value-prev-hash) -

is that correct?

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 not sure how it will work. Let's say that the pool reject the work cause it is in a old tip. Isn't it the same that just rejecting the work? When a client get a share rejection and the share is good it wait a little bit and if it do not see a new prev hash it just change pool. I don't understand what this field add (in that scenario). I agree that it could be useful in particular cases; for example when we are in a fork, so the pool know which phash need to use to verify shares. But for the 99.9% of the time I don't see how this can be useful. Also note that we should support the case where JDS and pool do not communicate.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The prev_hash here is needed just to let the JDS check that the declared job is built on a valid tip (and not on an old one).

06-Job-Declaration-Protocol.md Outdated Show resolved Hide resolved
as agreed between @GitGab19, @TheBlueMatt, @Fi3 and @plebhash, we are
dropping the "async" terminology in preference of coinbase vs template
"modes".

async terminology was causing confusion and leading to conflicting interpretation of the specs.

now, coinbase vs template modes make it explicitly clear how each side (JDC vs JDS) handles job declaration, especially with regards to:
- knowledge about the txdata contained in the template
- ability to propagate a valid block

the original semantics of async is now expressed with the notion of "optimistic mining"
allows JDS to reject work on old tips, or with potential double spends
the version field was rolled during mining, and therefore has to be informed to JDS when the solution is being submitted.

apparently it was removed by mistake on commit ce1edfb
@Fi3
Copy link
Contributor

Fi3 commented Jan 28, 2025

I don't think it's wise to have two messages in the spec called SubmitSolution, defined in two different places and with different content. Imo they should either be unified and defined in one place, or one needs a new name.

make sense

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.

Spec Changes for Job Declaration + Mining Protocols
4 participants