agent-comms 9.0.15 → 9.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +2 -0
- package/dist/core/bridge-mesh.d.ts.map +1 -1
- package/dist/core/bridge-mesh.js +1 -0
- package/dist/core/bridge-mesh.js.map +1 -1
- package/dist/core/coordinator-role.d.ts +15 -2
- package/dist/core/coordinator-role.d.ts.map +1 -1
- package/dist/core/coordinator-role.js +109 -11
- package/dist/core/coordinator-role.js.map +1 -1
- package/dist/core/data-frame-routing.d.ts +18 -2
- package/dist/core/data-frame-routing.d.ts.map +1 -1
- package/dist/core/data-frame-routing.js +93 -26
- package/dist/core/data-frame-routing.js.map +1 -1
- package/dist/core/ledger-gaps.d.ts +68 -0
- package/dist/core/ledger-gaps.d.ts.map +1 -0
- package/dist/core/ledger-gaps.js +170 -0
- package/dist/core/ledger-gaps.js.map +1 -0
- package/dist/core/tool.d.ts +6 -0
- package/dist/core/tool.d.ts.map +1 -1
- package/dist/core/tool.js +18 -1
- package/dist/core/tool.js.map +1 -1
- package/dist/core/wire-mesh-transport.d.ts +3 -2
- package/dist/core/wire-mesh-transport.d.ts.map +1 -1
- package/dist/core/wire-mesh-transport.js +1 -1
- package/dist/core/wire-mesh-transport.js.map +1 -1
- package/package.json +2 -2
- package/src/core/bridge-mesh.ts +1 -0
- package/src/core/coordinator-role.ts +126 -7
- package/src/core/data-frame-routing.ts +113 -26
- package/src/core/ledger-gaps.ts +234 -0
- package/src/core/tool.ts +30 -0
- package/src/core/wire-mesh-transport.ts +2 -2
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
* WireMeshTransport's own core/data frame dispatch (data-have, data-request, data-entries), split out under the repo's max-lines cap the same way gossip-directory.ts and hub-forwarding.ts were each split from the same owning file.
|
|
3
3
|
*/
|
|
4
4
|
import { handleDataEntries, handleDataHave, handleDataRequest, } from "wire-mesh-core/domain/data-sync";
|
|
5
|
-
import { deviceIdToHex } from "wire-mesh-core/domain/device-id";
|
|
5
|
+
import { bytesToHex, deviceIdToHex } from "wire-mesh-core/domain/device-id";
|
|
6
6
|
import { isDataFrame } from "wire-mesh-core/domain/hub-mailbox";
|
|
7
7
|
import { readMembershipProof } from "./gossip-directory.js";
|
|
8
|
+
import { LedgerGapTracker } from "./ledger-gaps.js";
|
|
8
9
|
/** The most entries one data-entries reply carries, for every log this side answers for, the account ledger's included: a longer log catches up over several rounds, so the bound only caps one frame's size. */
|
|
9
10
|
export const DATA_ENTRIES_RESPONSE_LIMIT = 100;
|
|
10
11
|
/** The hub data channel over whatever hub session `hub()` currently returns, read on each call because the router is built before the hub it talks through. */
|
|
@@ -48,6 +49,9 @@ export async function routeDataFrame(deps, connection, frame) {
|
|
|
48
49
|
ledger.ownsLog(frame.peer)) {
|
|
49
50
|
if (!(await deps.account.isAccountPeer(deviceIdHex)))
|
|
50
51
|
return;
|
|
52
|
+
if (frame.type === "data-have") {
|
|
53
|
+
deps.gaps?.noteHave(deviceIdHex, frame.peer, frame["head-seq"]);
|
|
54
|
+
}
|
|
51
55
|
const reply = await ledger.handleDataFrame(frame);
|
|
52
56
|
if (reply !== null)
|
|
53
57
|
await connection.send(reply);
|
|
@@ -84,6 +88,9 @@ export async function routeRelayedDataFrame(deps, fromDeviceHex, frame) {
|
|
|
84
88
|
return;
|
|
85
89
|
if (!(await account.isAccountPeer(fromDeviceHex)))
|
|
86
90
|
return;
|
|
91
|
+
if (frame.type === "data-have") {
|
|
92
|
+
deps.gaps?.noteHave(fromDeviceHex, frame.peer, frame["head-seq"]);
|
|
93
|
+
}
|
|
87
94
|
const reply = await ledger.handleDataFrame(frame);
|
|
88
95
|
if (reply !== null)
|
|
89
96
|
await hub.send(fromDeviceHex, reply);
|
|
@@ -92,28 +99,44 @@ export async function routeRelayedDataFrame(deps, fromDeviceHex, frame) {
|
|
|
92
99
|
deps.onError?.(error instanceof Error ? error : new Error(String(error)));
|
|
93
100
|
}
|
|
94
101
|
}
|
|
95
|
-
/** Offers every account writer log this machine holds to every device that holds the same account and that this side can reach (agent-comms#344): over a live, trusted data connection, or, for a device it meets only through the relay hub, over a relay pairing. Such a device that is behind asks for what it is missing, which is the data-domain fan-out that carries each machine's grants and revocations to every other. A device reachable both ways is offered the logs once, directly. Called on the gossip cadence, so a machine that was away when an entry was written still catches up the next time it is reachable. A send that fails is reported and the rest carry on; the next round retries it. */
|
|
102
|
+
/** Offers every account writer log this machine holds to every device that holds the same account and that this side can reach (agent-comms#344): over a live, trusted data connection, or, for a device it meets only through the relay hub, over a relay pairing. Such a device that is behind asks for what it is missing, which is the data-domain fan-out that carries each machine's grants and revocations to every other. A device reachable both ways is offered the logs once, directly. Called on the gossip cadence, so a machine that was away when an entry was written still catches up the next time it is reachable. A send that fails is reported through onError and the rest carry on; the next round retries it. Resolves with whether any device was reached and with this side's heads, read once. */
|
|
96
103
|
export async function announceAccountLedger(deps) {
|
|
97
104
|
const ledger = deps.account.ledger();
|
|
98
105
|
if (ledger === undefined)
|
|
99
|
-
return;
|
|
106
|
+
return { reached: false, localHeads: new Map() };
|
|
100
107
|
const frames = await ledger.announcements();
|
|
101
|
-
|
|
102
|
-
|
|
108
|
+
const localHeads = new Map();
|
|
109
|
+
for (const frame of frames) {
|
|
110
|
+
localHeads.set(bytesToHex(frame.peer), frame["head-seq"]);
|
|
111
|
+
}
|
|
112
|
+
let devices = 0;
|
|
113
|
+
let sent = 0;
|
|
103
114
|
const reportError = (error) => {
|
|
104
115
|
deps.onError?.(error instanceof Error ? error : new Error(String(error)));
|
|
105
116
|
};
|
|
117
|
+
// A device whose membership cannot be read is reported and skipped: one device that makes this throw must not stop the round from being counted.
|
|
118
|
+
const isAccountPeer = async (deviceHex) => {
|
|
119
|
+
try {
|
|
120
|
+
return await deps.account.isAccountPeer(deviceHex);
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
reportError(error);
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
};
|
|
106
127
|
const direct = new Set();
|
|
107
128
|
const offers = [];
|
|
108
129
|
for (const [deviceHex, connection] of deps.connectionsByPeer) {
|
|
109
130
|
if (!deps.peerSessions.has(deviceHex))
|
|
110
131
|
continue;
|
|
111
|
-
if (!(await
|
|
132
|
+
if (!(await isAccountPeer(deviceHex)))
|
|
112
133
|
continue;
|
|
113
134
|
direct.add(deviceHex);
|
|
135
|
+
devices += 1;
|
|
114
136
|
for (const frame of frames) {
|
|
115
137
|
try {
|
|
116
138
|
await connection.send(frame);
|
|
139
|
+
sent += 1;
|
|
117
140
|
}
|
|
118
141
|
catch (error) {
|
|
119
142
|
reportError(error);
|
|
@@ -121,26 +144,39 @@ export async function announceAccountLedger(deps) {
|
|
|
121
144
|
}
|
|
122
145
|
}
|
|
123
146
|
const { hub } = deps;
|
|
124
|
-
if (hub
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
147
|
+
if (hub !== undefined) {
|
|
148
|
+
let hubPeers = [];
|
|
149
|
+
try {
|
|
150
|
+
hubPeers = hub.peers();
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
reportError(error);
|
|
154
|
+
}
|
|
155
|
+
for (const deviceHex of hubPeers) {
|
|
156
|
+
if (direct.has(deviceHex))
|
|
157
|
+
continue;
|
|
158
|
+
if (!(await isAccountPeer(deviceHex)))
|
|
159
|
+
continue;
|
|
160
|
+
devices += 1;
|
|
161
|
+
// Each device is offered concurrently: a pairing to a device that is not there waits out its own handshake, which must not hold up the others.
|
|
162
|
+
offers.push((async () => {
|
|
163
|
+
for (const frame of frames) {
|
|
164
|
+
try {
|
|
165
|
+
await hub.send(deviceHex, frame);
|
|
166
|
+
sent += 1;
|
|
167
|
+
}
|
|
168
|
+
catch (error) {
|
|
169
|
+
reportError(error);
|
|
170
|
+
}
|
|
139
171
|
}
|
|
140
|
-
}
|
|
141
|
-
}
|
|
172
|
+
})());
|
|
173
|
+
}
|
|
142
174
|
}
|
|
143
175
|
await Promise.all(offers);
|
|
176
|
+
return {
|
|
177
|
+
reached: sent > 0 || (frames.length === 0 && devices > 0),
|
|
178
|
+
localHeads,
|
|
179
|
+
};
|
|
144
180
|
}
|
|
145
181
|
/** WireMeshTransport's core/data state and dispatch, split out under the repo's max-lines cap: the connection each peer's frames arrive on, routing of every data frame received, the mechanical send primitive, and the periodic offer of the account ledger's writer logs, and the same exchange with a device met only through the relay hub. */
|
|
146
182
|
export class DataFrameRouter {
|
|
@@ -150,6 +186,8 @@ export class DataFrameRouter {
|
|
|
150
186
|
/** Every peer this side has ever received a frame from, keyed by device-id hex, tracking the raw wire-mesh-core Connection each frame arrived on: what sendDataFrame needs, since neither AcceptedMeshSession nor MeshSession exposes a generic "send an arbitrary frame" method the way the raw Connection itself does. Registered eagerly on the very first frame from a connection (including one still in quarantine, e.g. before connect_request approval) so a later sendDataFrame call can reach it; routeDataFrame's own trust gate (peerSessions.has) is what actually decides whether to act on anything received this way, not this map. */
|
|
151
187
|
connectionsByPeer = new Map();
|
|
152
188
|
announceInterval;
|
|
189
|
+
/** What each peer says the account's writer logs reach, and the rounds this side has stayed behind it. Undefined for a transport with no account ledger. */
|
|
190
|
+
gaps;
|
|
153
191
|
/** Whether an announcement round is still running, so a round slowed by an unreachable hub peer is not stacked on by the next tick. */
|
|
154
192
|
announcing = false;
|
|
155
193
|
constructor(deps) {
|
|
@@ -158,10 +196,22 @@ export class DataFrameRouter {
|
|
|
158
196
|
const { account } = deps;
|
|
159
197
|
if (account === undefined)
|
|
160
198
|
return;
|
|
199
|
+
const gaps = new LedgerGapTracker({
|
|
200
|
+
request: async (source, frame) => this.requestFrom(source, frame),
|
|
201
|
+
isLive: (source) => deps.peerSessions.has(source) ||
|
|
202
|
+
(deps.hub?.peers().includes(source) ?? false),
|
|
203
|
+
onError: (error) => {
|
|
204
|
+
deps.onError?.(error);
|
|
205
|
+
},
|
|
206
|
+
});
|
|
207
|
+
this.gaps = gaps;
|
|
161
208
|
this.announceInterval = setInterval(() => {
|
|
162
209
|
if (this.announcing)
|
|
163
210
|
return;
|
|
164
211
|
this.announcing = true;
|
|
212
|
+
const report = (error) => {
|
|
213
|
+
deps.onError?.(error instanceof Error ? error : new Error(String(error)));
|
|
214
|
+
};
|
|
165
215
|
announceAccountLedger({
|
|
166
216
|
connectionsByPeer: this.connectionsByPeer,
|
|
167
217
|
account,
|
|
@@ -169,15 +219,30 @@ export class DataFrameRouter {
|
|
|
169
219
|
peerSessions: deps.peerSessions,
|
|
170
220
|
onError: deps.onError,
|
|
171
221
|
})
|
|
172
|
-
.
|
|
173
|
-
|
|
174
|
-
})
|
|
222
|
+
.then(async (offered) => gaps.round(offered.localHeads, { offline: !offered.reached }))
|
|
223
|
+
.catch(report)
|
|
175
224
|
.finally(() => {
|
|
176
225
|
this.announcing = false;
|
|
177
226
|
});
|
|
178
227
|
}, deps.announceIntervalMs);
|
|
179
228
|
this.announceInterval.unref();
|
|
180
229
|
}
|
|
230
|
+
/** Sends a data-request to one source, over its direct session when it has one and through the relay hub otherwise. */
|
|
231
|
+
async requestFrom(source, frame) {
|
|
232
|
+
const connection = this.connectionsByPeer.get(source);
|
|
233
|
+
if (connection !== undefined && this.deps.peerSessions.has(source)) {
|
|
234
|
+
await connection.send(frame);
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
if (this.deps.hub === undefined) {
|
|
238
|
+
throw new Error(`no route to ${source} to ask it for ledger entries`);
|
|
239
|
+
}
|
|
240
|
+
await this.deps.hub.send(source, frame);
|
|
241
|
+
}
|
|
242
|
+
/** The account ledger's logs this side has stayed behind for several rounds, for whoami. Empty when there is no account ledger. */
|
|
243
|
+
stalledLogs() {
|
|
244
|
+
return this.gaps?.stalled() ?? [];
|
|
245
|
+
}
|
|
181
246
|
/** See routeDataFrame. */
|
|
182
247
|
async route(connection, frame) {
|
|
183
248
|
await routeDataFrame({
|
|
@@ -185,6 +250,7 @@ export class DataFrameRouter {
|
|
|
185
250
|
dataStorage: this.dataStorage,
|
|
186
251
|
account: this.deps.account,
|
|
187
252
|
peerSessions: this.deps.peerSessions,
|
|
253
|
+
gaps: this.gaps,
|
|
188
254
|
onError: this.deps.onError,
|
|
189
255
|
}, connection, frame);
|
|
190
256
|
}
|
|
@@ -193,6 +259,7 @@ export class DataFrameRouter {
|
|
|
193
259
|
await routeRelayedDataFrame({
|
|
194
260
|
account: this.deps.account,
|
|
195
261
|
hub: this.deps.hub,
|
|
262
|
+
gaps: this.gaps,
|
|
196
263
|
onError: this.deps.onError,
|
|
197
264
|
}, fromDeviceHex, frame);
|
|
198
265
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-frame-routing.js","sourceRoot":"","sources":["../../src/core/data-frame-routing.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,iBAAiB,GAClB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;
|
|
1
|
+
{"version":3,"file":"data-frame-routing.js","sourceRoot":"","sources":["../../src/core/data-frame-routing.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,iBAAiB,GAClB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAC5E,OAAO,EAAE,WAAW,EAAE,MAAM,mCAAmC,CAAC;AAUhE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAyB,MAAM,kBAAkB,CAAC;AAG3E,iNAAiN;AACjN,MAAM,CAAC,MAAM,2BAA2B,GAAG,GAAG,CAAC;AAkB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,EAAE;QACjB,MAAM,qBAAqB,CACzB;YACE,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,OAAO;YAC1B,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG;YAClB,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,OAAO;SAC3B,EACD,aAAa,EACb,KAAK,CACN,CAAC;IACJ,CAAC,CAAC;IAEF,wHAAwH;IACxH,KAAK,CAAC,IAAI,CACR,aAAqB,EACrB,KAA2D;QAE3D,MAAM,UAAU,GAAG,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;QAC7D,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;YAC7B,MAAM,IAAI,KAAK,CACb,kDAAkD,aAAa,EAAE,CAClE,CAAC;QACJ,CAAC;QACD,MAAM,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC;IAED,wGAAwG;IACxG,IAAI;QACF,IAAI,IAAI,CAAC,gBAAgB,KAAK,SAAS;YAAE,OAAO;QAChD,aAAa,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;QACrC,IAAI,CAAC,gBAAgB,GAAG,SAAS,CAAC;IACpC,CAAC;CACF"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gap detection for the account ledger's replicated writer logs (agent-comms#344), with no wire change. A `data-have` frame already carries the head sequence of the log it names, so each machine can see how far every peer says a log goes. A machine that stays behind that head for several rounds in a row, while the entries it asks for do not arrive, has a log something is withholding or dropping: a revocation could be in the missing part.
|
|
3
|
+
*
|
|
4
|
+
* What is kept: for each log, each live source's own announced head. A source is a peer this side reached over a direct session or over the relay hub. Each replication round compares those heads with this side's own and counts the rounds a log has stayed behind without advancing. At LEDGER_STALL_ROUNDS the log is reported as stalled, and again only if the gap grew and LEDGER_REPORT_REPEAT_ROUNDS rounds have passed, and the entries are asked of every source that announced a higher head, not only the one that answered first. A log that catches up, or whose announcing sources have gone, is forgotten.
|
|
5
|
+
*
|
|
6
|
+
* What is bounded: the logs tracked (MAX_TRACKED_LEDGER_LOGS, preferring logs this side already holds), how far ahead of this side's head an announced head may be (MAX_ANNOUNCED_HEAD_DISTANCE), how many reports of an ignored announcement are remembered, and how often a repeated report is made. Reports of ignored announcements are remembered apart from the logs, so forgetting a log never makes a report repeat.
|
|
7
|
+
*
|
|
8
|
+
* What it cannot see: a single path that withholds everything, including the higher head, since the head is learned from the same frames; a log beyond the tracked limit that this side does not hold; a head more than MAX_ANNOUNCED_HEAD_DISTANCE ahead, which is ignored; a log that is slow but still advancing, which is never behind for LEDGER_STALL_ROUNDS rounds without moving; and a machine that reaches no peer of the account at all, whose rounds are not counted.
|
|
9
|
+
*/
|
|
10
|
+
import type { DataRequestFrame } from "wire-mesh-core/generated/protocol";
|
|
11
|
+
/** How many consecutive replication rounds a log may stay behind an announced head, without a new entry arriving, before it is reported as stalled. */
|
|
12
|
+
export declare const LEDGER_STALL_ROUNDS = 3;
|
|
13
|
+
/** How many rounds pass before a gap that has grown since it was last reported is reported again, so a peer that raises its head every round gets one report per interval and not one per round. */
|
|
14
|
+
export declare const LEDGER_REPORT_REPEAT_ROUNDS = 10;
|
|
15
|
+
/** The most writer logs tracked at once. The account's logs are one per machine that ever wrote, so this is far above any real account. At the limit a log this side holds takes the place of one it does not, and any other log announced is not tracked, which is reported at most once per LEDGER_REPORT_REPEAT_ROUNDS rounds. */
|
|
16
|
+
export declare const MAX_TRACKED_LEDGER_LOGS = 256;
|
|
17
|
+
/** The furthest an announced head may be ahead of this side's own and still be believed. Heads count ledger entries, which are grants and revocations, and a reply carries a bounded batch, so a head further ahead than this is not an honest gap: it is not recorded, and is reported once. */
|
|
18
|
+
export declare const MAX_ANNOUNCED_HEAD_DISTANCE = 1000000;
|
|
19
|
+
/** A log this side is behind, reported once it has stayed so for LEDGER_STALL_ROUNDS rounds. */
|
|
20
|
+
export interface StalledLedgerLog {
|
|
21
|
+
/** The writer log's id, hex. */
|
|
22
|
+
log: string;
|
|
23
|
+
/** This side's head sequence for it. */
|
|
24
|
+
localHead: number;
|
|
25
|
+
/** The highest head any live source announced. */
|
|
26
|
+
announcedHead: number;
|
|
27
|
+
/** The rounds it has stayed behind. */
|
|
28
|
+
rounds: number;
|
|
29
|
+
}
|
|
30
|
+
/** What the tracker needs from its owner. */
|
|
31
|
+
export interface LedgerGapDeps {
|
|
32
|
+
/** Sends a request for the entries after `frame["from-seq"]` of a log to one source, directly or through the hub. A rejection is reported and does not stop the others. */
|
|
33
|
+
request: (source: string, frame: Readonly<DataRequestFrame>) => Promise<void>;
|
|
34
|
+
/** Whether a source is still reachable: its announced heads are forgotten when it is not. */
|
|
35
|
+
isLive: (source: string) => boolean;
|
|
36
|
+
/** Where a stall is reported, and a failed request. */
|
|
37
|
+
onError: (error: Error) => void;
|
|
38
|
+
}
|
|
39
|
+
/** What a round is told about how it went. */
|
|
40
|
+
export interface LedgerRoundOptions {
|
|
41
|
+
/** True when this machine reached no peer of the account this round: no offer went out, so nothing was asked of anyone. The round still notices a log that has caught up, but it is not counted as a round the log stayed behind. */
|
|
42
|
+
offline?: boolean;
|
|
43
|
+
}
|
|
44
|
+
export declare class LedgerGapTracker {
|
|
45
|
+
private readonly deps;
|
|
46
|
+
private readonly logs;
|
|
47
|
+
private roundNumber;
|
|
48
|
+
private overLimitReportedAtRound;
|
|
49
|
+
/** The logs this side held at the last round, which a log announced at the tracking limit is preferred for. */
|
|
50
|
+
private held;
|
|
51
|
+
/** The `log:source` of every out-of-range announcement reported, oldest first, kept apart from the logs so that a log forgotten and announced again is not reported again. */
|
|
52
|
+
private readonly reportedOutOfRange;
|
|
53
|
+
constructor(deps: Readonly<LedgerGapDeps>);
|
|
54
|
+
/** Records the head `source` announced for a log. Called for every `data-have` an account peer sends for one of the account's logs. */
|
|
55
|
+
noteHave(source: string, log: Uint8Array, head: number): void;
|
|
56
|
+
/** Makes room for a log at the tracking limit by dropping a tracked log this side holds nothing of, and only when this side holds the new one. */
|
|
57
|
+
private makeRoomFor;
|
|
58
|
+
private reportOverLimit;
|
|
59
|
+
/** Remembers that an out-of-range announcement was reported, and whether it had been before. */
|
|
60
|
+
private firstReportOfOutOfRange;
|
|
61
|
+
/**
|
|
62
|
+
* One replication round: compares every announced head with this side's (`localHeads`, by log id hex, absent for a log this side holds nothing of), counts the rounds each log stays behind without advancing, and on reaching LEDGER_STALL_ROUNDS reports it and asks every source that announced a higher head for the entries. Resolves once the requests have been sent.
|
|
63
|
+
*/
|
|
64
|
+
round(localHeads: ReadonlyMap<string, number>, options?: Readonly<LedgerRoundOptions>): Promise<void>;
|
|
65
|
+
/** The logs that have stayed behind for LEDGER_STALL_ROUNDS rounds or more as of the last round, for whoami. */
|
|
66
|
+
stalled(): StalledLedgerLog[];
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=ledger-gaps.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ledger-gaps.d.ts","sourceRoot":"","sources":["../../src/core/ledger-gaps.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAE1E,uJAAuJ;AACvJ,eAAO,MAAM,mBAAmB,IAAI,CAAC;AAErC,oMAAoM;AACpM,eAAO,MAAM,2BAA2B,KAAK,CAAC;AAE9C,qUAAqU;AACrU,eAAO,MAAM,uBAAuB,MAAM,CAAC;AAO3C,iSAAiS;AACjS,eAAO,MAAM,2BAA2B,UAAY,CAAC;AAErD,gGAAgG;AAChG,MAAM,WAAW,gBAAgB;IAC/B,gCAAgC;IAChC,GAAG,EAAE,MAAM,CAAC;IACZ,wCAAwC;IACxC,SAAS,EAAE,MAAM,CAAC;IAClB,kDAAkD;IAClD,aAAa,EAAE,MAAM,CAAC;IACtB,uCAAuC;IACvC,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,6CAA6C;AAC7C,MAA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for the account ledger's replicated writer logs (agent-comms#344), with no wire change. A `data-have` frame already carries the head sequence of the log it names, so each machine can see how far every peer says a log goes. A machine that stays behind that head for several rounds in a row, while the entries it asks for do not arrive, has a log something is withholding or dropping: a revocation could be in the missing part.
|
|
3
|
+
*
|
|
4
|
+
* What is kept: for each log, each live source's own announced head. A source is a peer this side reached over a direct session or over the relay hub. Each replication round compares those heads with this side's own and counts the rounds a log has stayed behind without advancing. At LEDGER_STALL_ROUNDS the log is reported as stalled, and again only if the gap grew and LEDGER_REPORT_REPEAT_ROUNDS rounds have passed, and the entries are asked of every source that announced a higher head, not only the one that answered first. A log that catches up, or whose announcing sources have gone, is forgotten.
|
|
5
|
+
*
|
|
6
|
+
* What is bounded: the logs tracked (MAX_TRACKED_LEDGER_LOGS, preferring logs this side already holds), how far ahead of this side's head an announced head may be (MAX_ANNOUNCED_HEAD_DISTANCE), how many reports of an ignored announcement are remembered, and how often a repeated report is made. Reports of ignored announcements are remembered apart from the logs, so forgetting a log never makes a report repeat.
|
|
7
|
+
*
|
|
8
|
+
* What it cannot see: a single path that withholds everything, including the higher head, since the head is learned from the same frames; a log beyond the tracked limit that this side does not hold; a head more than MAX_ANNOUNCED_HEAD_DISTANCE ahead, which is ignored; a log that is slow but still advancing, which is never behind for LEDGER_STALL_ROUNDS rounds without moving; and a machine that reaches no peer of the account at all, whose rounds are not counted.
|
|
9
|
+
*/
|
|
10
|
+
import { bytesToHex } from "wire-mesh-core/domain/device-id";
|
|
11
|
+
/** How many consecutive replication rounds a log may stay behind an announced head, without a new entry arriving, before it is reported as stalled. */
|
|
12
|
+
export const LEDGER_STALL_ROUNDS = 3;
|
|
13
|
+
/** How many rounds pass before a gap that has grown since it was last reported is reported again, so a peer that raises its head every round gets one report per interval and not one per round. */
|
|
14
|
+
export const LEDGER_REPORT_REPEAT_ROUNDS = 10;
|
|
15
|
+
/** The most writer logs tracked at once. The account's logs are one per machine that ever wrote, so this is far above any real account. At the limit a log this side holds takes the place of one it does not, and any other log announced is not tracked, which is reported at most once per LEDGER_REPORT_REPEAT_ROUNDS rounds. */
|
|
16
|
+
export const MAX_TRACKED_LEDGER_LOGS = 256;
|
|
17
|
+
/** How many out-of-range reports are remembered per tracked log; the oldest is forgotten first. */
|
|
18
|
+
const REMEMBERED_REPORTS_PER_LOG = 4;
|
|
19
|
+
const MAX_REMEMBERED_REPORTS = REMEMBERED_REPORTS_PER_LOG * MAX_TRACKED_LEDGER_LOGS;
|
|
20
|
+
/** The furthest an announced head may be ahead of this side's own and still be believed. Heads count ledger entries, which are grants and revocations, and a reply carries a bounded batch, so a head further ahead than this is not an honest gap: it is not recorded, and is reported once. */
|
|
21
|
+
export const MAX_ANNOUNCED_HEAD_DISTANCE = 1_000_000;
|
|
22
|
+
export class LedgerGapTracker {
|
|
23
|
+
deps;
|
|
24
|
+
logs = new Map();
|
|
25
|
+
roundNumber = 0;
|
|
26
|
+
overLimitReportedAtRound;
|
|
27
|
+
/** The logs this side held at the last round, which a log announced at the tracking limit is preferred for. */
|
|
28
|
+
held = new Set();
|
|
29
|
+
/** The `log:source` of every out-of-range announcement reported, oldest first, kept apart from the logs so that a log forgotten and announced again is not reported again. */
|
|
30
|
+
reportedOutOfRange = new Set();
|
|
31
|
+
constructor(deps) {
|
|
32
|
+
this.deps = deps;
|
|
33
|
+
}
|
|
34
|
+
/** Records the head `source` announced for a log. Called for every `data-have` an account peer sends for one of the account's logs. */
|
|
35
|
+
noteHave(source, log, head) {
|
|
36
|
+
const key = bytesToHex(log);
|
|
37
|
+
let state = this.logs.get(key);
|
|
38
|
+
if (state === undefined) {
|
|
39
|
+
if (this.logs.size >= MAX_TRACKED_LEDGER_LOGS && !this.makeRoomFor(key)) {
|
|
40
|
+
this.reportOverLimit();
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
state = {
|
|
44
|
+
id: Uint8Array.from(log),
|
|
45
|
+
heads: new Map(),
|
|
46
|
+
lastLocal: undefined,
|
|
47
|
+
rounds: 0,
|
|
48
|
+
reportedGap: 0,
|
|
49
|
+
reportedAtRound: undefined,
|
|
50
|
+
};
|
|
51
|
+
this.logs.set(key, state);
|
|
52
|
+
}
|
|
53
|
+
state.heads.set(source, head);
|
|
54
|
+
}
|
|
55
|
+
/** Makes room for a log at the tracking limit by dropping a tracked log this side holds nothing of, and only when this side holds the new one. */
|
|
56
|
+
makeRoomFor(key) {
|
|
57
|
+
if (!this.held.has(key))
|
|
58
|
+
return false;
|
|
59
|
+
for (const other of this.logs.keys()) {
|
|
60
|
+
if (this.held.has(other))
|
|
61
|
+
continue;
|
|
62
|
+
this.logs.delete(other);
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
reportOverLimit() {
|
|
68
|
+
const last = this.overLimitReportedAtRound;
|
|
69
|
+
if (last !== undefined &&
|
|
70
|
+
this.roundNumber - last < LEDGER_REPORT_REPEAT_ROUNDS) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
this.overLimitReportedAtRound = this.roundNumber;
|
|
74
|
+
this.deps.onError(new Error(`the account ledger announces more than ${String(MAX_TRACKED_LEDGER_LOGS)} writer logs, which is more than any account has: the logs beyond them that this machine holds nothing of are ignored, so one of them that stays behind is not reported`));
|
|
75
|
+
}
|
|
76
|
+
/** Remembers that an out-of-range announcement was reported, and whether it had been before. */
|
|
77
|
+
firstReportOfOutOfRange(key, source) {
|
|
78
|
+
const id = `${key}:${source}`;
|
|
79
|
+
if (this.reportedOutOfRange.has(id))
|
|
80
|
+
return false;
|
|
81
|
+
this.reportedOutOfRange.add(id);
|
|
82
|
+
if (this.reportedOutOfRange.size > MAX_REMEMBERED_REPORTS) {
|
|
83
|
+
const [oldest] = this.reportedOutOfRange;
|
|
84
|
+
if (oldest !== undefined)
|
|
85
|
+
this.reportedOutOfRange.delete(oldest);
|
|
86
|
+
}
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* One replication round: compares every announced head with this side's (`localHeads`, by log id hex, absent for a log this side holds nothing of), counts the rounds each log stays behind without advancing, and on reaching LEDGER_STALL_ROUNDS reports it and asks every source that announced a higher head for the entries. Resolves once the requests have been sent.
|
|
91
|
+
*/
|
|
92
|
+
async round(localHeads, options = {}) {
|
|
93
|
+
this.roundNumber += 1;
|
|
94
|
+
this.held = new Set(localHeads.keys());
|
|
95
|
+
const requests = [];
|
|
96
|
+
for (const [key, state] of this.logs) {
|
|
97
|
+
const local = localHeads.get(key) ?? 0;
|
|
98
|
+
for (const [source, head] of [...state.heads]) {
|
|
99
|
+
if (!this.deps.isLive(source)) {
|
|
100
|
+
state.heads.delete(source);
|
|
101
|
+
}
|
|
102
|
+
else if (head - local > MAX_ANNOUNCED_HEAD_DISTANCE) {
|
|
103
|
+
state.heads.delete(source);
|
|
104
|
+
if (this.firstReportOfOutOfRange(key, source)) {
|
|
105
|
+
this.deps.onError(new Error(`a peer announced head ${String(head)} for account ledger log ${key}, which is out of range for a log this machine holds up to entry ${String(local)} of, and the announcement is ignored`));
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
this.reportedOutOfRange.delete(`${key}:${source}`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
const announced = Math.max(0, ...state.heads.values());
|
|
113
|
+
if (announced <= local) {
|
|
114
|
+
this.logs.delete(key);
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
if (options.offline === true)
|
|
118
|
+
continue;
|
|
119
|
+
if (state.lastLocal === local) {
|
|
120
|
+
state.rounds += 1;
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
state.rounds = 1;
|
|
124
|
+
state.reportedGap = 0;
|
|
125
|
+
}
|
|
126
|
+
state.lastLocal = local;
|
|
127
|
+
if (state.rounds < LEDGER_STALL_ROUNDS)
|
|
128
|
+
continue;
|
|
129
|
+
const gap = announced - local;
|
|
130
|
+
const due = state.reportedAtRound === undefined ||
|
|
131
|
+
this.roundNumber - state.reportedAtRound >= LEDGER_REPORT_REPEAT_ROUNDS;
|
|
132
|
+
if (gap > state.reportedGap && due) {
|
|
133
|
+
state.reportedGap = gap;
|
|
134
|
+
state.reportedAtRound = this.roundNumber;
|
|
135
|
+
this.deps.onError(new Error(`account ledger log ${key} has stayed behind for ${String(state.rounds)} rounds: this machine holds up to entry ${String(local)} and a peer announces ${String(announced)}; a grant or a revocation in the missing entries is not applied here, and the entries are being asked of every peer that announced them`));
|
|
136
|
+
}
|
|
137
|
+
for (const [source, head] of state.heads) {
|
|
138
|
+
if (head <= local)
|
|
139
|
+
continue;
|
|
140
|
+
requests.push(this.deps
|
|
141
|
+
.request(source, {
|
|
142
|
+
type: "data-request",
|
|
143
|
+
peer: state.id,
|
|
144
|
+
"from-seq": local,
|
|
145
|
+
})
|
|
146
|
+
.catch((error) => {
|
|
147
|
+
this.deps.onError(error instanceof Error ? error : new Error(String(error)));
|
|
148
|
+
}));
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
await Promise.all(requests);
|
|
152
|
+
}
|
|
153
|
+
/** The logs that have stayed behind for LEDGER_STALL_ROUNDS rounds or more as of the last round, for whoami. */
|
|
154
|
+
stalled() {
|
|
155
|
+
const out = [];
|
|
156
|
+
for (const [key, state] of this.logs) {
|
|
157
|
+
if (state.rounds < LEDGER_STALL_ROUNDS)
|
|
158
|
+
continue;
|
|
159
|
+
const announced = Math.max(0, ...state.heads.values());
|
|
160
|
+
out.push({
|
|
161
|
+
log: key,
|
|
162
|
+
localHead: state.lastLocal ?? 0,
|
|
163
|
+
announcedHead: announced,
|
|
164
|
+
rounds: state.rounds,
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
return out;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
//# sourceMappingURL=ledger-gaps.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ledger-gaps.js","sourceRoot":"","sources":["../../src/core/ledger-gaps.ts"],"names":[],"mappings":"AAA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CAAC;YACvD,GAAG,CAAC,IAAI,CAAC;gBACP,GAAG,EAAE,GAAG;gBACR,SAAS,EAAE,KAAK,CAAC,SAAS,IAAI,CAAC;gBAC/B,aAAa,EAAE,SAAS;gBACxB,MAAM,EAAE,KAAK,CAAC,MAAM;aACrB,CAAC,CAAC;QACL,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC;CACF"}
|
package/dist/core/tool.d.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* 2. Call handleAction(action)
|
|
7
7
|
* 3. Return the result string to the LLM
|
|
8
8
|
*/
|
|
9
|
+
import type { StalledLedgerLog } from "./ledger-gaps.js";
|
|
9
10
|
import type { AgentDetailsExchange } from "./agent-details.js";
|
|
10
11
|
import { type Naming } from "./naming.js";
|
|
11
12
|
import type { LanWebUiEntry } from "./lan-web-uis.js";
|
|
@@ -138,6 +139,8 @@ export interface CommsToolOptions {
|
|
|
138
139
|
readonly getNewerVersionIfAny?: () => string | undefined;
|
|
139
140
|
/** How many stored account ledger entries cannot be read, for whoami; omitted when the store has no account ledger. */
|
|
140
141
|
readonly getUnreadableLedgerEntries?: () => number;
|
|
142
|
+
/** The account ledger's writer logs this side has stayed behind for several rounds, for whoami; omitted when the transport has no account ledger. */
|
|
143
|
+
readonly getStalledLedgerLogs?: () => readonly StalledLedgerLog[];
|
|
141
144
|
/** Fetches a signer's armored PGP public key by fingerprint, used by gateway_redeem_connection_code when the caller supplies a fingerprint but not the key text itself. Defaults to the real keys.openpgp.org lookup (pgp-keyserver.ts); a test that would otherwise trigger real network I/O injects a fake resolver instead, the same reasoning bridge-mesh.ts's own fetchLatestVersion override already establishes for getNewerVersionIfAny above. */
|
|
142
145
|
readonly fetchPgpPublicKeyByFingerprintImpl?: (fingerprint: string) => Promise<string>;
|
|
143
146
|
}
|
|
@@ -149,6 +152,7 @@ export declare class CommsTool {
|
|
|
149
152
|
private readonly naming;
|
|
150
153
|
private readonly getNewerVersionIfAny;
|
|
151
154
|
private readonly getUnreadableLedgerEntries;
|
|
155
|
+
private readonly getStalledLedgerLogs;
|
|
152
156
|
private readonly fetchPgpPublicKeyByFingerprintImpl;
|
|
153
157
|
constructor(store: CommsStore & MeshOnlyFeatures, options?: Readonly<CommsToolOptions>);
|
|
154
158
|
/** The "Update available: ..." line appended to whoami/update output when a newer release is known, or undefined when there's nothing to report. */
|
|
@@ -158,6 +162,8 @@ export declare class CommsTool {
|
|
|
158
162
|
private update;
|
|
159
163
|
/** The namer for ctx's view: petnames and known self names when naming is wired, otherwise only what each caller passes. */
|
|
160
164
|
private namerFor;
|
|
165
|
+
/** The `Account ledger log <id> is behind` lines for whoami and update, one per writer log this side has stayed behind, at most MAX_STALLED_LEDGER_LINES of them and then one `Account ledger: <n> more logs are behind` line. The wording is part of the interface: the README states it. */
|
|
166
|
+
private stalledLedgerLines;
|
|
161
167
|
private whoami;
|
|
162
168
|
private webUrl;
|
|
163
169
|
private createRoom;
|
package/dist/core/tool.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool.d.ts","sourceRoot":"","sources":["../../src/core/tool.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;
|
|
1
|
+
{"version":3,"file":"tool.d.ts","sourceRoot":"","sources":["../../src/core/tool.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEzD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAA0B,KAAK,MAAM,EAAE,MAAM,aAAa,CAAC;AAElE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAStD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,KAAK,EACV,OAAO,EACP,aAAa,EACb,WAAW,EACX,cAAc,EACd,cAAc,EACd,gBAAgB,EAGjB,MAAM,YAAY,CAAC;AACp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