Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
16 changes: 10 additions & 6 deletions lib/features/mostro/transport.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,20 @@ enum Transport { giftWrap, nip44 }
/// degraded state so a misconfigured node is not silently mis-paired.
Transport resolveTransport(int? protocolVersion) {
switch (protocolVersion) {
case 2:
return Transport.nip44;
case 1:
case null:
// Legacy nodes only: the gift wrap transport is obsolete in the
// protocol and its code paths are scheduled for removal.
return Transport.giftWrap;
case 2:
case null:
// v2 is the live transport. Defaulting to it when the node info has
// not arrived yet avoids a useless kind-1059 REQ at every cold start
// followed by a CLOSE + re-REQ once protocol_version resolves.
return Transport.nip44;
Comment on lines +39 to +43

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve v1 sends until the node advertises its transport

When a user sends an order during cold start against a supported protocol_version=1 node, MostroService.publishOrder passes mostroInstance?.protocolVersion as null, so this branch now emits an unsupported kind-14 message that the v1 node ignores. The later instance listener only replaces the receive subscription; it cannot retry the lost outbound action. Limit the v2 default to the initial orders subscription optimization, or wait for transport discovery before selecting the outbound envelope.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 80dffa5 — but by waiting for transport discovery, not by preserving the v1 default on the send path.

The concern is real: an outbound envelope on the wrong transport is dropped by the node and nothing retries it. Keeping null → giftWrap for sends does not fix it though, it just moves the loss: on a v2 node (the mandatory case now) a cold-start send would go out as kind 1059 and be ignored exactly the same way. Either default is a guess, and one of the two nodes always loses.

So the send path no longer guesses. OpenOrdersRepository.awaitMostroInstance() returns the cached kind-38385 info event, or waits for it (bounded, 3s, well under the 10s orphan-session cleanup timer) and logs + falls back to the previous defaults on timeout. Applied at every wrapForTransport call site: MostroService.publishOrder, DisputeRepository, and the three restore requests. Same call also removes the PoW-0 guess those paths had, which had the same root cause.

The v2 default in resolveTransport stays as the last-resort fallback for the case where the info event genuinely never arrives.

Tests: test/data/repositories/open_orders_repository_await_instance_test.dart pins the three outcomes (cached, resolves on arrival, null on timeout). Full suite green (1196), flutter analyze clean.

default:
logger.w(
'Unsupported protocol_version $protocolVersion; '
'degrading to v1 gift wrap',
'Unknown protocol_version $protocolVersion; assuming v2 (NIP-44)',
);
return Transport.giftWrap;
return Transport.nip44;
}
}
12 changes: 7 additions & 5 deletions test/features/mostro/transport_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ void main() {
expect(resolveTransport(1), Transport.giftWrap);
});

test('null (tag absent / node info not yet fetched) → giftWrap', () {
expect(resolveTransport(null), Transport.giftWrap);
test('null (tag absent / node info not yet fetched) → nip44', () {
// Gift wrap is obsolete; defaulting to v2 avoids a useless kind-1059
// REQ + resubscribe at every cold start while the node info loads.
expect(resolveTransport(null), Transport.nip44);
});

test('unsupported version → degrades to giftWrap', () {
expect(resolveTransport(3), Transport.giftWrap);
expect(resolveTransport(0), Transport.giftWrap);
test('unknown versions assume the live transport (nip44)', () {
expect(resolveTransport(3), Transport.nip44);
expect(resolveTransport(0), Transport.nip44);
});
});
}
Loading