Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,45 @@

## [Unreleased]

### Hosts: what a host changes to take the record of a conflict and the recheck of `conflicted` (for #47)

**A host changes nothing to keep today's machine, and one answer moves for every host.** (1) The latch is the default: `Params::new` sets `Params::recheck_conflicted` to `false`, and with it off a `conflicted` word stays `conflicted` under every chain event and recheck, as before; it leaves only by its own checked proof or a node's `rejected`. (2) For every host, in either mode: a proof offered as a competitor's whose txid is the tracked transaction's is refused, `Err(CheckError::TxidMismatch)` with `Reask::ProofFailed` and nothing else moved, where the latch wrote `conflicted` on the tracked transaction from its own proof. A competitor is another transaction; such bytes go to `Evidence::Proof`. (3) What a host must have checked before it feeds `Evidence::Competitor`: the hash of the competitor's bytes is the crate's check (the proof is built with `Proof::new` from those bytes); that those bytes spend an input of the tracked transaction stays the host's, which the crate cannot see. A competitor known only by someone's word is a hint or a node's verdict. (4) A host that turns the door on, `Params::new(..).with_recheck_conflicted(true)`, feeds its header feed's rows as it does today (`Tracker::on_chain`, or `Evidence::Chain` and `Evidence::Recheck` on one state); after a restore it feeds `Evidence::Recheck` to a `conflicted` word it wants read against today's headers (a restored record is not marked suspect); and on `Reask::CompetitorGone` it fetches the tracked transaction's proof and the named competitors' again. It turns the door on only when its own rules for a returned word are ready: a coin it released when the payment read `conflicted` is still released after the return unless the host locks it back. (5) `State`'s equality compares the record and the prior word; a match on `Reask` outside the crate already carries a wildcard arm (`#[non_exhaustive]`), and `Reask::LABELS` appends `competitor_gone`.

```rust
// The latch, today's machine: nothing to change.
let params = Params::new(3600, 1);
// The door, when the host's own rules lock back a returned payment's inputs.
let params = Params::new(3600, 1).with_recheck_conflicted(true);

// Before: a competitor's proof for the tracked txid wrote conflicted [txid].
// This line, for every host: refused; the proof door takes such a proof.
assert_eq!(
state.step(&params, &headers, Input::Evidence(Evidence::Competitor(own_proof))),
Err(CheckError::TxidMismatch)
);
```

### Added: the record of a conflict, the word it began from, and the door (for #47)

Mirrored from bsv-stack-lean's `lean/Tracker.lean` at `a7ef91de` (section "The recheck of `conflicted`"; `onCompetitor`, `onVerdict`, `keptRivals`, `keptPrior`, `verdictRivals`, `verdictPrior`, `leaveWord`, `recheckConflict`, `onChainConflict`, `rivalAtOrAbove`, `rivalCheckedAgainst`, `stepRecheck`, `conflictReask`).

- `Competitor`, re-exported at the crate root (`Tracker.Competitor`): a competitor on the record, with private fields and the readers `txid()`, `tx_len()`, `checked()`, `gone()` and `standing()`. `tx_len()` is the competitor's own measured length, `Some` for a competitor entered by a proof (never 64) and `None` for one a node's verdict named; it is never the tracked transaction's measure (ahead of the Lean, whose `Competitor` has no length yet). No public constructor and no serde form: a checked proof has neither.
- `State::rivals() -> &[Competitor]` (`State.rivals`), the newest at the front, and `State::prior() -> Option<&Word>` (`State.prior`), the word held when the conflict began. A checked competitor's proof puts the competitor on the record with its proof and length; a node's `conflicted` verdict puts its competitors on it with neither, so no root rechecks them; a conflict that begins starts its own record and keeps the word of its moment as the prior word; a later competitor joins it. A `rejected` verdict and a `mined` word's re-ask leave both. The record is kept, with its marks, after the word leaves `conflicted`.
- `Params::recheck_conflicted: bool`, `false` in `Params::new`, and `Params::with_recheck_conflicted` (`Params` is `#[non_exhaustive]`: no host breaks). `State::step` reads it: off, the latch (`Tracker.step`); on, the machine with the door (`Tracker.stepRecheck`), where a `conflicted` word meeting a chain event or an executed recheck goes through the recheck of the conflict and every other input is the latch's step.
- The recheck reads the host's header at each standing competitor's height that carries a proof, one read each. A header with another root marks the competitor gone; no header, or a headers fault, is not gone. Every competitor gone: the word returns to `leave_word(prior)` (`seen` returns as `announced`; `mined`, `conflicted` or none would read `unknown`; every other word as it was, `handed` with its instances), with `Reask::CompetitorGone { competitors }` naming the word's competitors, the record kept and marked, the suspect mark cleared. A standing competitor unanswered: `conflicted` on the standing competitors, `Reask::Recheck`, the mark as it was, and `Err(CheckError::Unavailable(h))` or `Err(CheckError::Headers(e))` for the unanswered competitor nearest the front. Else `conflicted` on the standing ones, the marks cleared. An empty record and a competitor a node named never leave this way. A restored version 1 `conflicted` row's competitors stand on the record as named ones once a competitor or a verdict joins the word (each id of the word's list with no entry on the record goes on it as named, ahead of `onCompetitor` and `onVerdict` in bsv-stack-lean's `lean/Tracker.lean` at `9a727a64`), so under the door such a row never leaves by a chain event or a recheck.
- The feed under the door, as for `mined`: a reorg at or below a standing competitor's height marks the word and rechecks; an invalidation of a standing competitor's checked header marks and rechecks; a fork at or below one marks it with `Reask::Fork`; a tip rechecks a marked word and reads nothing for an unmarked one. The crate's split meets a `conflicted` word as a fork, and its resolved split as the tip of a marked word at or below a standing competitor, as both meet a `mined` word (the stack's `ChainEvent` has no split).
- `Tracker` keeps two indexes for `conflicted` words: the heights of their standing checked competitors and the headers those were checked against. Under the flag alone, `Tracker::on_chain` adds the words they select to a reorg's, a fork's, a split's and an invalidation's targets, after the `mined` words and with no txid twice. With the flag off the selection and every output are the latch's.
- `Reask::CompetitorGone { competitors: Vec<TxId> }`, label `competitor_gone`, compact re-ask tag `8`.
- `Evidence::Competitor`'s doc says what the host must have shown: the hash of the competitor's bytes is the crate's check, and the spend of our input stays the host's.

### Changed: a competitor's proof for the tracked txid is refused, and the compact form carries the record (for #47)

- `State::step` on `Evidence::Competitor`, in order: a proof whose txid is the tracked one is refused (`CheckError::TxidMismatch`, `Reask::ProofFailed`, the word and the record untouched; `Tracker.competitor_is_another`); then the competitor's own length (a proof not built from its bytes is `CheckError::Unmeasured`); then the header check.
- The compact form fills the two fields version 2 already carries, with no new version: no published release reads version 2. The record: a varint count, then each competitor's txid (an id), its length (`0`, or `1` and a varint), its checked proof (`0`, or `1` and the record as the evidence field writes it, read back as a record and never checked against headers) and its mark. The prior word: `0`, or `1` and a word as the word field writes it. Re-ask tag `8`, competitor gone, and its ids. A record restores exactly, its competitors not marked suspect; a version 1 row restores with an empty record and no prior word.
- Refused, through the variants `CompactError` has: re-ask tag `8` under version 1 (`Malformed("re-ask tag")`); a prior word `mined` or `conflicted` (`Malformed("prior word")`); a competitor's checked proof with no length (`Malformed("competitor's proof with no length")`); a length beside a competitor with no proof (`Malformed("named competitor with a length")`); a competitor with no proof marked gone (`Malformed("named competitor marked gone")`); a competitor that is the tracked transaction, or whose proof is another transaction's (`Evidence(CheckError::TxidMismatch)`); a competitor's length of 64 (`Evidence(CheckError::AmbiguousLength)`); a competitor's record that does not hold together (`Evidence(_)`). Instances now stand only beside `handed` and beside `conflicted` whose prior word is `handed` (`Malformed("instances beside a word that holds none")`).
- `tests/compact_golden.rs`: every golden string is byte-identical but `conflicted_by_ids_and_text`'s tail, where the node's verdict now writes its two competitors on the record and the prior word `unknown`; its old ending is quoted in its doc. `version_1_bytes_still_restore` and `version_2_is_version_1_with_four_empty_fields` read that one state's record apart; `handed_refusals` and `tests/compact.rs`'s `version_2_refusals` lose the refusals of a record "held empty in this release"; `an_instance_beside_each_word_of_record` reads the list kept beside `conflicted` only when its prior word is `handed`.
- Tests: `tests/transitions.rs` (the latch over a `conflicted` word under every chain event and a recheck; a competitor's proof for the tracked txid, refused in both modes, the latch's old answer quoted; the record and the prior word; a competitor's length and the tracked transaction's measure kept apart, the K4 scope of the crate's issue 57; the door's rows over one state), `tests/reorg_by_root.rs` (the latch's outputs over a registry with `conflicted` words, unchanged with the flag named off; the selection under the door; one header read per standing competitor with a proof), `tests/compact.rs` (a state with a record round-trips; the record's refusals; the round trip's generator feeds the door), `tests/labels.rs` (`competitor_gone`), a unit test of `leave_word`. `tests/handed_properties.rs`'s `handed_to_only_beside_handed` is tightened to `conflicted` whose prior word is `handed`, both ways.

### Hosts: what a host of 0.9.0-beta.11 changes to take the tenth word (for #56)

**A host of 0.9.0-beta.11 changes each exhaustive match on `Word`, and may start feeding three acts.** (1) `Word` has a tenth word, `Word::Handed`, and is still not `#[non_exhaustive]`, on purpose: every exhaustive match on `Word` outside the crate stops compiling (E0004) until it names the word, because each place that names words must decide what `handed` means for it. (2) A host that feeds no `HostAction::HandOver` never sees `Word::Handed`, and every word it sees is the word it saw at 0.9.0-beta.11: no other act, hint or evidence writes it (the Lean's `handedNamed_run` and the arms of `step` in `lean/Tracker.lean` at bsv-stack-lean `08ce467d`). Once a host feeds the act, a rule that reads a word by its text or through a wildcard arm reads `handed` as whatever that arm says, in silence; name each before feeding the act. (3) A re-ask of the new kind `Reask::Reannounce` asks the host to post the bytes again to each instance of `State::handed_to()`; it is never a proof request, so a host that fetches a proof for every due re-ask whatever its kind fetches the wrong thing for it. `Reask::LABELS` gains `"reannounce"` at its end. (4) `State::to_compact` writes version 2 of the compact form. Version 1 bytes a host stored still restore, as the same state with no instance; an older crate refuses version 2 bytes with `CompactError::UnknownVersion(2)` and restores nothing.
Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ so the host tells it the length, and these are the host's duties:
unmeasured, and a host that holds its bytes hands them to `State::measure`
before it serves the inclusion.
- Build a competitor's proof from the competitor's own bytes; any other is
refused (`CheckError::Unmeasured`).
refused (`CheckError::Unmeasured`). The hash of those bytes is the crate's
check; that they spend an input of the tracked transaction stays the
host's to have shown. A proof for the tracked transaction itself is no
competitor's and is refused (`CheckError::TxidMismatch`).
- Read every `Result` of a measure or a restore. `State::measure`,
`Tracker::track_bytes` and `Tracker::restore` answer
`CheckError::AmbiguousLength` when a measure of 64 bytes meets a proof the
Expand Down Expand Up @@ -101,8 +104,9 @@ An unavailable header or failed check keeps the word and schedules a re-ask.
Broadcaster rejection and
mempool conflict do not by themselves write `Rejected` or `Conflicted`.
`NodeVerdict` is a separate host-supplied authority boundary; a host must not
relabel a broadcaster's refusal as a local node verdict. The host also supplies
the fact that a proved competitor spends one of the tracked inputs.
relabel a broadcaster's refusal as a local node verdict. The crate checks that
a competitor's proof was built from bytes that hash to its txid; the host
supplies the fact that those bytes spend one of the tracked inputs.

The host supplies `Headers`, `ProofFetcher`, `HintSource` and `Clock`, executes
scheduled re-asks and reports decoding and check errors. After a chain event a
Expand Down
2 changes: 1 addition & 1 deletion docs/SPEC.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ A transaction of exactly 64 bytes is never taken as proven by a merkle path (BRC

No proof built from 64 bytes or on a stated 64 reaches the door: neither constructor yields one. A proof the door takes is kept in the record with no length: the state's measure, beside it, is the length. A row "built from bytes at another length" is reachable only by two byte strings of one hash; the unit test in `src/state.rs` reaches it.

The competitor door takes a proof built from the competitor's own bytes and refuses any other, `Err(Unmeasured)` with the word kept and `Reask::ProofFailed`. The competitor is judged by its own length, never by the tracked transaction's measure: a state measured at 64 still takes a competitor's proof. That the competitor spends an input of the tracked transaction stays the host's to have shown.
The competitor door takes a proof built from the competitor's own bytes and refuses any other, `Err(Unmeasured)` with the word kept and `Reask::ProofFailed`. The competitor is judged by its own length, never by the tracked transaction's measure: a state measured at 64 still takes a competitor's proof. The hash of the competitor's bytes is the crate's check; that the competitor spends an input of the tracked transaction stays the host's to have shown. A proof offered as a competitor's for the tracked txid itself is refused, `Err(TxidMismatch)` with the word and the record kept and `Reask::ProofFailed` (for #47): the proof door is the one that takes it. A competitor's length is kept on the record of the conflict beside its proof (`Competitor::tx_len`) and never unsays the tracked transaction's word.

### The fault roads

Expand Down
13 changes: 13 additions & 0 deletions docs/VERIFICATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -1694,3 +1694,16 @@ The four properties of `tests/properties.rs` keep their names and statements ove
At the opening run the seventh fault was caught by the earlier change's example alone: the trace reached a pending `reannounce` beside another word than `handed` in no case. The draw now ticks at the due time five codes in thirty, and `handOver_clears_reannounce` checks that premise is met; it fails on that fault.

Not mirrored here, each a host's: the wallet's statements over the word (`lean/Wallet/Handed.lean`, `TakenOnlyHanded`), the merge rank of `handed`, the held answer `heldAnswer .handed`, the refusal of the end of a hold for an action of the host's own (the crate cannot see an origin), and the gate vectors' rows that name `handed`. The rows and the statements of the recheck of `conflicted` (`stepRecheck`, `handed_written_cases`, `returnHanded`) are not in this section.

## A restored version 1 `conflicted` row under the door (for #47, 2026-11-28)

[SRC] bsv-stack-lean `lean/Tracker.lean` at `9a727a64` (`9a727a64653b602377b6c3acad543e6997544bfb`): a `State` stored before the record existed reads with `rivals := []` and `prior := none`, and `recheckConflict` leaves a `conflicted` word with no record as it is. `onCompetitor` and `onVerdict` join such a word with `keptRivals`, which keeps the record as it was: the word then lists the stored competitors and the record holds the joined one alone, so the stored ones do not stand once the joined one's root is gone. The crate names them instead, and builds ahead of the Lean there.

[X] `cargo test --locked`, each answer at the pull request's base before the cure and after it:

| test | what is checked | before | after |
|---|---|---|---|
| `a_version_1_conflicted_row_keeps_its_competitors_under_the_door` `[AHEAD OF THE LEAN]` | the published `conflicted` row of record (`tests/compact_golden.rs`'s `VERSION_1`), the door on, a checked competitor Z joins, a reorg removes Z's root: the word stays `conflicted` on the row's two competitors, Z marked gone on the record, no `Reask::CompetitorGone`; a later reorg, a recheck and a tip leave it | red: the word read `unknown` with `CompetitorGone` | green |
| `a_version_1_conflicted_row_is_latched_with_the_door_off` | the same row and join with the door off: the reorg leaves the state whole | green | green |
| `a_version_1_conflicted_row_nothing_joins_never_leaves_and_writes_back_whole` | the row restored and never joined, the door on, two reorgs, a recheck and a tip: the state as restored, its record empty, and its bytes the version 1 row with the opening byte `02` and four empty fields, spelled as a literal | green | green |
| `a_conflicted_word_and_its_record_name_the_same_competitors` (`tests/compact.rs`) `[AHEAD OF THE LEAN]` | over the round trip's generator (256 cases), every other case born a restored version 1 row on `hash(9)`, each step under the door or the latch: after every step a `conflicted` word's ids and its record's standing ids are one set unless the record is empty, an empty record stands beside the row's own word alone, and a restored row returns only from a later conflict begun after the subject's own proof ended the row's | red | green: 129 restored rows, 46 joins on a restored row, 1 return of a later conflict |
Loading
Loading