PoolMatcher registers players by (tokenId, atomTier) and opens a
round at minPlayers. OneShotRound collects contributions, shuffles token
outputs, and calls assembleAlpSend for an unsigned fused tx. OneShotClient
is the in-process join/contribute helper. No network, signing, broadcast,
or Tor yet.
Details
- Reviewers
Fabien - Group Reviewers
Restricted Project - Commits
- rABCdf27e1fd3145: [alp-fusion] Add in-process pool match and one-shot round driver
- cd apps/alp-fusion && pnpm test
- Confirm pool readiness, two-player assemble → EMPP SEND, and atom-burn failure path
Diff Detail
- Repository
- rABC Bitcoin ABC
- Lint
Lint Not Applicable - Unit
Tests Not Applicable
Event Timeline
Build Bitcoin ABC Diffs / Diff Testing (ai-review) passed.
CodeRabbit Review
Diff : committed changes only
Compare : HEAD → master
Directory : work
────────────────────────────────────────
(\(\
(• .•) Keep your friends close, but your code reviewers closer.
────────────────────────────────────────────────────────────────────────
major [Functional Correctness]
→ ]8;;vscode://file//work/apps/alp-fusion/src/coordinator/pool.ts:40apps/alp-fusion/src/coordinator/pool.ts:40-44]8;;
Require an integer player threshold.
NaN and fractional values pass this check. For example, `new
PoolMatcher(2.5) becomes ready with three registrations, but splice(0,
2.5)` takes only two players. Reject non-integer values before storing
minPlayers.
Proposed fix
constructor(minPlayers = DEFAULT_MIN_PLAYERS) {
- if (minPlayers < 2) {
- throw new Error('minPlayers must be >= 2');
+ if (!Number.isSafeInteger(minPlayers) || minPlayers < 2) {
+ throw new Error('minPlayers must be an integer >= 2');
}
this.minPlayers = minPlayers;
}────────────────────────────────────────────────────────────────────────
minor [Functional Correctness]
→ ]8;;vscode://file//work/apps/alp-fusion/test/coordinator/pool.test.ts:41apps/alp-fusion/test/coordinator/pool.test.ts:41-53]8;;
Test isolation by atomTier.
This test changes tokenId but does not use a second tier for the same
token. Add registrations with one tokenId and different atomTier
values. The test must fail if keyFor() stops including atomTier.
Proposed test addition
it('isolates pools by tokenId and atomTier', () => {
const m = new PoolMatcher(2);
m.register({ playerId: 'a', tokenId: TOKEN_ID, atomTier: 1n });
+ m.register({ playerId: 'tier-2', tokenId: TOKEN_ID, atomTier: 2n });
m.register({
playerId: 'b',
tokenId: 'ff'.repeat(32),
atomTier: 1n,
});
expect(m.isReady(TOKEN_ID, 1n)).to.equal(false);
m.register({ playerId: 'c', tokenId: TOKEN_ID, atomTier: 1n });
expect(m.isReady(TOKEN_ID, 1n)).to.equal(true);
+ expect(m.isReady(TOKEN_ID, 2n)).to.equal(false);
expect(m.isReady('ff'.repeat(32), 1n)).to.equal(false);
});────────────────────────────────────────────────────────────────────────
minor [Maintainability & Code Quality] → ]8;;vscode://file//work/apps/alp-fusion/README.md:50apps/alp-fusion/README.md:50]8;; Update the project status. The coordinator and one-shot client are implemented in this change. The phrase “coordinator next” is now incorrect and conflicts with roadmap item 4.
────────────────────────────────────────────────────────────────────────
minor [Functional Correctness] → ]8;;vscode://file//work/apps/alp-fusion/src/client/oneshot.ts:69apps/alp-fusion/src/client/oneshot.ts:69-74]8;; Reject duplicate and unexpected contributions. Line 69 overwrites an earlier contribution when two records have the same playerId. Lines 70-74 also accept records for players outside ready.playerIds and then ignore them. Validate that contributions has exactly one record for each ready player before constructing OneShotRound.
────────────────────────────────────────
Review complete
4 findings ✔
Major 1
Minor 3
8 files reviewed:
- apps/alp-fusion/README.md
- apps/alp-fusion/src/client/oneshot.ts
- apps/alp-fusion/src/coordinator/pool.ts
- apps/alp-fusion/src/coordinator/round.ts
- apps/alp-fusion/src/coordinator/types.ts
- apps/alp-fusion/src/protocol/constants.ts
- apps/alp-fusion/test/coordinator/pool.test.ts
- apps/alp-fusion/test/coordinator/round.test.ts
────────────────────────────────────────
Print all AI prompts: coderabbit review --show-prompts
Build Bitcoin ABC Diffs / Diff Testing (ai-review) passed.
CodeRabbit Review
Diff : committed changes only
Compare : HEAD → master
Directory : work
────────────────────────────────────────
(\(\
(• .•) Trained in all forms of code review, from the ancient art of waterfall to the modern ways of agile.
────────────────────────────────────────────────────────────────────────
minor [Maintainability & Code Quality]
→ ]8;;vscode://file//work/apps/alp-fusion/src/client/oneshot.ts:27apps/alp-fusion/src/client/oneshot.ts:27-35]8;;
Fix the unresolved API reference.
{@link openRoundIfReady} is not defined or imported in oneshot.ts. The
exported orchestration helper is runOneShotRound. Replace the link or
add the documented API.────────────────────────────────────────────────────────────────────────
minor [Data Integrity & Integration]
→ ]8;;vscode://file//work/apps/alp-fusion/src/client/oneshot.ts:68apps/alp-fusion/src/client/oneshot.ts:68-77]8;;
Reject duplicate and unknown contributions.
new Map(contributions.map(...)) silently overwrites duplicate playerId
entries. The round never receives the duplicate, so round-level validation
cannot detect it. The loop also ignores contributions for players outside
ready.playerIds.
Validate that the input contains exactly one contribution for every ready
player.
Proposed validation
- const byId = new Map(contributions.map(c => [c.playerId, c]));
+ const byId = new Map<PlayerId, PlayerContribution>();
+ for (const contribution of contributions) {
+ if (byId.has(contribution.playerId)) {
+ throw new Error(
+ `duplicate contribution for player ${contribution.playerId}`,
+ );
+ }
+ byId.set(contribution.playerId, contribution);
+ }
for (const id of ready.playerIds) {
- if (!byId.has(id)) {
+ const contribution = byId.get(id);
+ if (contribution === undefined) {
throw new Error(`missing contribution for player ${id}`);
}
}────────────────────────────────────────────────────────────────────────
major [Data Integrity & Integration]
→ ]8;;vscode://file//work/apps/alp-fusion/src/coordinator/round.ts:100apps/alp-fusion/src/coordinator/round.ts:100-126]8;;
Add validation against overlapping/duplicate UTXOs across contributions.
submitContribution checks tokenId, phase, non-empty inputs/outputs, and
duplicate playerId submissions. It does not check whether the same
prevOut (txid + outIdx) appears in more than one contribution's
tokenInputs or fuelInputs, or is repeated within one contribution.
Since multiple untrusted players submit inputs independently, a buggy or
malicious client can reference a UTXO already claimed by another player.
Nothing in this file catches that before assemble() builds the combined
input list. Validate uniqueness of every prevOut across all collected
contributions, either in submitContribution or at the start of
assemble(), and reject the round with a clear error before calling
assembleAlpSend.
🛡️ Proposed fix for duplicate-input detection in assemble()
try {
const tokenInputs = [];
const fuelInputs: FusionFuelInput[] = [];
const tokenOutputs: FusionTokenOutput[] = [];
+ const seenOutpoints = new Set<string>();
for (const id of this.playerIds) {
const c = this.contributions.get(id)!;
+ for (const inp of [...c.tokenInputs, ...(c.fuelInputs ?? [])]) {
+ const key = `${inp.prevOut.txid}:${inp.prevOut.outIdx}`;
+ if (seenOutpoints.has(key)) {
+ throw new Error(`duplicate input ${key} across contributions`);
+ }
+ seenOutpoints.add(key);
+ }
tokenInputs.push(...c.tokenInputs);
tokenOutputs.push(...c.tokenOutputs);
if (c.fuelInputs) {
fuelInputs.push(...c.fuelInputs);
}
}────────────────────────────────────────
Review complete
3 findings ✔
Major 1
Minor 2
8 files reviewed:
- apps/alp-fusion/README.md
- apps/alp-fusion/src/client/oneshot.ts
- apps/alp-fusion/src/coordinator/pool.ts
- apps/alp-fusion/src/coordinator/round.ts
- apps/alp-fusion/src/coordinator/types.ts
- apps/alp-fusion/src/protocol/constants.ts
- apps/alp-fusion/test/coordinator/pool.test.ts
- apps/alp-fusion/test/coordinator/round.test.ts
────────────────────────────────────────
Print all AI prompts: coderabbit review --show-prompts
Address CodeRabbit feedback on D20430:
- Fix broken JSDoc {@link} in oneshot client
- runOneShotRound: reject duplicate/unexpected playerIds; require one contrib per ready player
- OneShotRound.assemble: reject duplicate/overlapping prevOut across contributions
- PoolMatcher: require minPlayers to be a safe integer >= 2
- Tests: atomTier pool isolation + new rejection paths
Build Bitcoin ABC Diffs / Diff Testing (ai-review) passed.
CodeRabbit Review
Diff : committed changes only
Compare : HEAD → master
Directory : work
────────────────────────────────────────
(\(\
(• .•) Tree-sitter is my GPS.
────────────────────────────────────────────────────────────────────────
major [Security & Privacy] → ]8;;vscode://file//work/apps/alp-fusion/src/protocol/constants.ts:63apps/alp-fusion/src/protocol/constants.ts:63-67]8;; Do not use two players as the default fusion privacy threshold. PoolMatcher uses this value when callers omit minPlayers. In a two-player round, either participant can identify its own inputs and outputs, then attribute the remaining participant-owned inputs and token outputs to the single counterparty. Set a privacy-preserving production default, such as 8. Keep 2 only as an explicit test configuration. Proposed fix -export const DEFAULT_MIN_PLAYERS = 2; +export const DEFAULT_MIN_PLAYERS = 8;
────────────────────────────────────────────────────────────────────────
critical [Functional Correctness] → ]8;;vscode://file//work/apps/alp-fusion/src/coordinator/round.ts:14apps/alp-fusion/src/coordinator/round.ts:14-15]8;; Add the FusionTokenInput annotation. In this external module, strict mode infers const tokenInputs = [] as never[], so .push(...c.tokenInputs) fails. Import FusionTokenInput and declare const tokenInputs: FusionTokenInput[] = [].
────────────────────────────────────────
Review complete
2 findings ✔
Critical 1
Major 1
8 files reviewed:
- apps/alp-fusion/README.md
- apps/alp-fusion/src/client/oneshot.ts
- apps/alp-fusion/src/coordinator/pool.ts
- apps/alp-fusion/src/coordinator/round.ts
- apps/alp-fusion/src/coordinator/types.ts
- apps/alp-fusion/src/protocol/constants.ts
- apps/alp-fusion/test/coordinator/pool.test.ts
- apps/alp-fusion/test/coordinator/round.test.ts
────────────────────────────────────────
Print all AI prompts: coderabbit review --show-prompts
Address CodeRabbit: DEFAULT_MIN_PLAYERS=8 (CashFusion privacy floor; tests keep explicit 2) and type tokenInputs as FusionTokenInput[] to avoid never[] under strict inference.
Build Bitcoin ABC Diffs / Diff Testing (ai-review) passed.
CodeRabbit Review
Diff : committed changes only
Compare : HEAD → master
Directory : work
────────────────────────────────────────
(\(\
(• .•) Test your estimates. Mathematical analysis of algorithms doesn't tell you everything. Try timing your code in its target environment.
────────────────────────────────────────────────────────────────────────
minor [Functional Correctness]
→ ]8;;vscode://file//work/apps/alp-fusion/src/coordinator/pool.ts:47apps/alp-fusion/src/coordinator/pool.ts:47-60]8;;
Store a registration snapshot.
Line 59 retains the caller-owned reg object. A caller can change
reg.playerId after registration. The duplicate check can then accept the
original playerId again, and takeReady can return an unregistered
replacement ID.
Store a copy before adding it to the pool. Add a regression test that
mutates the original registration after register.
Proposed fix
- list.push(reg);
+ list.push({ ...reg });────────────────────────────────────────────────────────────────────────
minor [Maintainability & Code Quality] → ]8;;vscode://file//work/apps/alp-fusion/src/client/oneshot.ts:5apps/alp-fusion/src/client/oneshot.ts:5-10]8;; Correct the OneShotClient contract documentation. OneShotClient only registers and submits a contribution. It does not wait for a ReadyPool or return an AssembledAlpSend. runOneShotRound performs those operations.
────────────────────────────────────────
Review complete
2 findings ✔
Minor 2
9 files reviewed:
- apps/alp-fusion/README.md
- apps/alp-fusion/SPEC.md
- apps/alp-fusion/src/client/oneshot.ts
- apps/alp-fusion/src/coordinator/pool.ts
- apps/alp-fusion/src/coordinator/round.ts
- apps/alp-fusion/src/coordinator/types.ts
- apps/alp-fusion/src/protocol/constants.ts
- apps/alp-fusion/test/coordinator/pool.test.ts
- apps/alp-fusion/test/coordinator/round.test.ts
────────────────────────────────────────
Print all AI prompts: coderabbit review --show-prompts
Address CodeRabbit: snapshot PoolRegistration on register (block post-register mutation) and correct OneShotClient docs (register/contribute only; runOneShotRound assembles).
Tail of the build log:
/work /work/abc-ci-builds/ai-review Connecting to CodeRabbit... 0s elapsed Preparing review... 1s elapsed ✗ Review limit reached Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. You're only billed for reviews past your plan's rate limits ($0.25/file). You can wait 16 minutes for the limit to reset. https://app.coderabbit.ai/settings/billing?tab=usage&orgId=79839cd4-7849-4bd5-8d6d-5ecaf453356e Build ai-review failed with exit code 1
| apps/alp-fusion/src/coordinator/pool.ts | ||
|---|---|---|
| 56 ↗ | (On Diff #60746) | not sure this is worth throwing, you could just return the existing entry here |
| 86 ↗ | (On Diff #60746) | shouldn't you shuffle the players first ? |
| apps/alp-fusion/src/coordinator/round.ts | ||
| 33 ↗ | (On Diff #60746) | TIL |
| 54 ↗ | (On Diff #60746) | Any reason for not going after all the 53 bits of entropy ? |
| 56 ↗ | (On Diff #60746) | beware this can return NaN in theory. Maybe it's better to handle the undefined case and throw. |
| 190 ↗ | (On Diff #60746) | It's critical this is never used in prod, make super sure it can't be set outside of tests |
Address Fabien review: idempotent pool register; shuffle waiters on takeReady; shared 53-bit cryptoUnitInterval with empty-buffer guard; shuffleSeed gated to NODE_ENV=test.
Build Bitcoin ABC Diffs / Diff Testing (ai-review) passed.
CodeRabbit Review
Diff : committed changes only
Compare : HEAD → master
Directory : work
────────────────────────────────────────
(\(\
(• .•) Preventing Skynet from becoming self-aware.
────────────────────────────────────────────────────────────────────────
major [Functional Correctness] → ]8;;vscode://file//work/apps/alp-fusion/src/client/oneshot.ts:66apps/alp-fusion/src/client/oneshot.ts:66-86]8;; Expose ReadyPool before accepting exact contributions. If a pool has more than minPlayers registrations, takeReady selects a random subset. The caller cannot know that subset before this function returns. If the caller supplies contributions for all waiting players, Lines 70-73 reject the unselected players. If the caller supplies only minPlayers contributions, Lines 82-85 can reject the call when the shuffled subset contains a different player. Split pool selection from contribution collection. For example, expose an operation that returns ReadyPool and OneShotRound first, then accept contributions for ready.playerIds.
────────────────────────────────────────
Review complete
1 finding ✔
Major 1
11 files reviewed:
- apps/alp-fusion/README.md
- apps/alp-fusion/SPEC.md
- apps/alp-fusion/package.json
- apps/alp-fusion/src/client/oneshot.ts
- apps/alp-fusion/src/coordinator/pool.ts
- apps/alp-fusion/src/coordinator/random.ts
- apps/alp-fusion/src/coordinator/round.ts
- apps/alp-fusion/src/coordinator/types.ts
- apps/alp-fusion/src/protocol/constants.ts
- apps/alp-fusion/test/coordinator/pool.test.ts
... and 1 more file
────────────────────────────────────────
Print all AI prompts: coderabbit review --show-prompts
Address Fabien: move mulberry32/shuffleInPlace into random.ts (dedupe UINT32_RANGE); flatten shuffleSeed NODE_ENV gate.
Tail of the build log:
/work /work/abc-ci-builds/ai-review Connecting to CodeRabbit... 0s elapsed Preparing review... 1s elapsed ✗ Review limit reached Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. You're only billed for reviews past your plan's rate limits ($0.25/file). You can wait 14 minutes for the limit to reset. https://app.coderabbit.ai/settings/billing?tab=usage&orgId=79839cd4-7849-4bd5-8d6d-5ecaf453356e Build ai-review failed with exit code 1