Repository navigation
RFC: one extension for algorithm selection and time-bounded work, or one per chain #251
Closed
cdonnachie
started this conversation in
General
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
I maintain Avian, a chain with two proof-of-work algorithms, X16RT and
MinotaurX, mined concurrently with independent per-algorithm difficulty. I have
a Template Provider and a Stratum v2 pool implemented, both working, and an
extension that makes them correct. Before I ask for an
extension_typeI wantto put the scoping question to this repository, because I think I framed it
badly the first time I asked and invited the obvious answer.
What the extension does
Two mechanisms, one message each plus replies. It changes no existing message
and adds no TLV fields.
Algorithm selection. A downstream role states which proof-of-work algorithm
a connection carries. Without it an upstream can only pin one algorithm per
listening port.
An upper bound on ntime. The specification defines
ntime_startas a lowerbound and says explicitly that it is not a consensus minimum. It defines no
maximum. X16RT derives its hash chain from
SHA256d(nTime & 0xffffff80), sothe function changes every 128 seconds, and a miner rolling
ntimeacross aboundary silently computes a different hash. Not a rejected share: a wrong
hash, submitted in good faith, indistinguishable from bad luck.
There is adjacent prior discussion in #187, on how far hardware rolls
ntimein practice and whether that stays within consensus limits. Bitcoin can treat
that as a question about limits it already has; a chain with an epoch-dependent
hash function needs the bound stated on the wire, because for it the limit is
not MAX_FUTURE_BLOCK_TIME but the next epoch boundary, which can be seconds
away.
Both failure modes are silent, which is why I would rather express them on the
wire than document them and hope.
The question I should have asked
I first called this a chain-specific extension. That undersells it and it is
also not true.
Time-bounded work applies to any proof of work whose function depends on a time
epoch. Algorithm selection applies to any chain mining several algorithms
concurrently with per-algorithm difficulty, which includes DigiByte, Myriad and
Verge. Each of those needs the same single thing from the wire: which algorithm
does this connection carry.
So the question is not whether Avian may have an id. It is whether this
repository wants one allocation covering that class, with the algorithm
identifier left for each chain to define, or whether it would rather each such
chain squat its own experimental id for identical semantics. The second outcome
is the collision a registry exists to prevent, and it is what happens by default
if nobody decides.
I have written it the first way.
pow_typeis aU8whose values are definedby the chain, not by this extension, so a multi-algorithm chain implements the
two messages and names its own algorithms. Avian's mapping is an example in the
document, not part of the format.
Two smaller things I would like an opinion on
It spans two protocols under one id. The three selection messages are
byte-identical on Template Distribution and on the Mining Protocol, because they
are connection-scoped and carry nothing protocol-specific. Only the time
constraints differ, since the two protocols name work differently: one keys on
template_id, the other onchannel_idandjob_id. A pool is a TemplateDistribution client facing the node and a Mining server facing workers, so under
two ids it would negotiate two extensions to obtain one capability. I think one
id is right but I would rather be told now than after an allocation.
version_rolling_maskis in the reply and is always zero. Avian keeps thealgorithm in
nVersionbits 16-23, which BIP320's mask fully contains, sorolling either trips a consensus check or silently moves the share to the other
algorithm and the wrong proof-of-work limit. The field is there so a later
version can open rolling without a format change, not because anything can turn
it on today.
The second extension, and why it is second
The implementation also has a message telling a client what became of a share
that was a block: whether the pool forwarded it, and whether the pool's node
adopted it. That is a real gap for a non-custodial pool, where consensus pays
the client directly for exactly those and
SubmitShares.Successsays only"accepted as a share".
It is not inside the extension above. It is a separate request,
0x0006,in the same pull request, and it may be rejected or redirected into core
without touching
0x0005.Keeping it separate is not tidiness, and the reason generalises past this
message. Extensions Negotiation agrees an
extension_typeand carries noper-extension version or supported-message list, so negotiating an extension
does not negotiate every message it will ever contain. This message started
life inside the larger extension, which clients were required to negotiate.
Clients built before it existed received it, treated it as a protocol
violation, closed the session, and went on hashing into a connection nobody was
serving.
An ignore-unknown-
msg_typerule fixes that going forward, and I think itbelongs somewhere in this specification. It does not fix software already
shipped, and it only ever licenses optional additions: a future message that
changed which work is valid could not be safely ignored, and since the
extension_typeis Stratum v2's only capability granularity, such a messageneeds its own allocation rather than another
msg_type. Worth knowing beforebundling anything.
One correction to the case I would have made for it a week ago, in case anyone
else has written the same thing down: a client can recognise a block
candidate by itself, because
SetNewPrevHashcarriesnbits. I had documentedthe opposite. The gap is what happens after it submits, not whether it knows
what it found.
Status
Implemented and running on both links, with the full wire format frozen and
written up. Currently on experimental
0x4001, which the specification saysmust not be present in production equipment, so an allocation is a mainnet
blocker for us rather than a preference.
I have opened a pull request against this repository with both definition
documents and their registry rows, since section 3.4.1 says allocation is
requested from this repository. The ids there are
0x0005and0x0006, takenas the next free pair after the open claims in #203 and #249, and I do not mind
what they end up being. Happy to take any of it apart there or here, whichever
suits.
All reactions