@jsm-mit/tigi-sharded-package 0.6.0 → 0.8.0

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.
@@ -171,6 +171,7 @@ type Result =
171
171
  };
172
172
  type RequestView =
173
173
  record {
174
+ asOfNs: opt nat64;
174
175
  asked: nat32;
175
176
  createdNs: nat64;
176
177
  expiresNs: nat64;
@@ -218,6 +218,7 @@ export interface RequestView {
218
218
  'requestId' : RequestId,
219
219
  'expiresNs' : bigint,
220
220
  'asked' : number,
221
+ 'asOfNs' : [] | [bigint],
221
222
  'createdNs' : bigint,
222
223
  'offers' : Array<OfferView>,
223
224
  'state' : RequestStateView,
@@ -214,6 +214,7 @@ export const idlFactory = ({ IDL }) => {
214
214
  'requestId' : RequestId,
215
215
  'expiresNs' : IDL.Nat64,
216
216
  'asked' : IDL.Nat32,
217
+ 'asOfNs' : IDL.Opt(IDL.Nat64),
217
218
  'createdNs' : IDL.Nat64,
218
219
  'offers' : IDL.Vec(OfferView),
219
220
  'state' : RequestStateView,
@@ -110,6 +110,12 @@ export declare class RideRequest {
110
110
  private choosing;
111
111
  private lastSnapshot;
112
112
  private slots;
113
+ /** ZO-24: each worker's last answer, with the time of its state. */
114
+ private readonly heldViews;
115
+ /** ZO-24: the last ride shown (status and position never go back). */
116
+ private lastRide;
117
+ /** ZO-25: the next read of the request goes through consensus (after the rider's own action). */
118
+ private freshNext;
113
119
  private readonly rejected;
114
120
  private readonly notFree;
115
121
  private readonly refreshingUntilMs;
@@ -1 +1 @@
1
- {"version":3,"file":"rides-actor.d.ts","sourceRoot":"","sources":["../../src/actors/rides-actor.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAKpD,OAAO,EAAgJ,KAAK,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC7M,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAE9C,OAAO,EAA2B,KA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AA6F;YAC/E,UAAU;YASV,kBAAkB;YAalB,mBAAmB;YAOnB,WAAW;CAG5B"}
@@ -11,7 +11,7 @@ import { TigiGroup } from "../group/group.js";
11
11
  import { geohashesByWorker } from "../group/prefixes.js";
12
12
  import { cellsWithin, isValidGeo } from "../geo.js";
13
13
  import { driverChatPlaceAsyncUnsafe } from "../chat.js";
14
- import { cardOf, closeReasonOf, decodeToken, driverOfOfferId, encodeToken, mergedPhase, mergeOffers, moneyOf, msOf, offerIdOf, offerOf, phaseOf, placeOffers, rideOfRideRef, rideStatusOf, routeLineOf } from "../mappers.js";
14
+ import { cardOf, closeReasonOf, decodeToken, driverOfOfferId, encodeToken, fresherRide, freshViews, mergedPhase, mergeOffers, moneyOf, msOf, offerIdOf, offerOf, phaseOf, placeOffers, rideOfRideRef, rideStatusOf, routeLineOf } from "../mappers.js";
15
15
  /** U-29: the rider's radius, and the radius after `WIDEN_AFTER_MS` without offers. */
16
16
  export const SEARCH_RADIUS_METERS = 3_000;
17
17
  export const WIDE_RADIUS_METERS = 6_000;
@@ -155,6 +155,12 @@ export class RideRequest {
155
155
  choosing = false;
156
156
  lastSnapshot;
157
157
  slots = [];
158
+ /** ZO-24: each worker's last answer, with the time of its state. */
159
+ heldViews = new Map();
160
+ /** ZO-24: the last ride shown (status and position never go back). */
161
+ lastRide;
162
+ /** ZO-25: the next read of the request goes through consensus (after the rider's own action). */
163
+ freshNext = false;
158
164
  rejected = new Set();
159
165
  notFree = new Set();
160
166
  refreshingUntilMs = new Map();
@@ -262,6 +268,7 @@ export class RideRequest {
262
268
  */
263
269
  async rejectOfferAsyncUnsafe(offerId) {
264
270
  const done = await this.onOfferAsyncUnsafe(offerId, (actor, ref) => actor.rejectOffer(ref));
271
+ this.freshNext = true;
265
272
  this.offerWorkers.delete(offerId);
266
273
  // U-42: the entry stays in its place, as `gone: "rejected"`.
267
274
  this.rejected.add(offerId);
@@ -277,6 +284,7 @@ export class RideRequest {
277
284
  */
278
285
  async refreshOfferAsyncUnsafe(offerId) {
279
286
  const asked = await this.onOfferAsyncUnsafe(offerId, (actor, ref) => actor.refreshOffer(ref));
287
+ this.freshNext = true;
280
288
  // The offer is absent until its driver confirms again; its place waits (REFRESH_WAIT_MS).
281
289
  if (asked)
282
290
  this.refreshingUntilMs.set(offerId, Date.now() + REFRESH_WAIT_MS);
@@ -314,6 +322,7 @@ export class RideRequest {
314
322
  return { kind: "driverNotFree" };
315
323
  }
316
324
  const outcome = await this.onOfferAsyncUnsafe(offerId, (actor, ref) => actor.chooseOffer(ref));
325
+ this.freshNext = true;
317
326
  if ("ordered" in outcome) {
318
327
  this.orderedOfferId = offerId;
319
328
  return { kind: "ordered", answerByMs: msOf(outcome.ordered.answerByNs) };
@@ -400,6 +409,7 @@ export class RideRequest {
400
409
  */
401
410
  async giveUpAsyncUnsafe() {
402
411
  const results = await Promise.allSettled(this.state.workers.map((worker) => this.group.onWorkerAsyncUnsafe(worker, (actor) => actor.giveUp({ requestId: this.state.requestId }))));
412
+ this.freshNext = true;
403
413
  const failed = results.find((result) => result.status === "rejected" && errorKeyOf(result.reason) === undefined);
404
414
  if (failed?.status === "rejected")
405
415
  throw failed.reason;
@@ -412,7 +422,9 @@ export class RideRequest {
412
422
  */
413
423
  async getRideAsyncUnsafe() {
414
424
  const accepted = await this.acceptedAsyncUnsafe();
415
- return getRideOfAsyncUnsafe(this.identity, this.options, accepted, this.state.requestId);
425
+ // ZO-24: an answer from an older state never moves the ride back.
426
+ this.lastRide = fresherRide(this.lastRide, await getRideOfAsyncUnsafe(this.identity, this.options, accepted, this.state.requestId));
427
+ return this.lastRide;
416
428
  }
417
429
  /**
418
430
  * K-4, U-13: the rider cancels in the driver canister only, before `inProgress`, once.
@@ -423,6 +435,7 @@ export class RideRequest {
423
435
  async cancelRideAsyncUnsafe() {
424
436
  const accepted = await this.acceptedAsyncUnsafe();
425
437
  await executeProtocolAsyncUnsafe(async () => (await this.driverAsync(accepted.canister)).cancelRide({ requestId: this.state.requestId, driverKey: accepted.driverKey }));
438
+ this.freshNext = true;
426
439
  }
427
440
  /**
428
441
  * U-11, PR-23: the driver's licence, from the acceptance to the end of the ride.
@@ -459,7 +472,9 @@ export class RideRequest {
459
472
  */
460
473
  async rateDriverAsyncUnsafe(stars) {
461
474
  const accepted = await this.acceptedAsyncUnsafe();
462
- return this.group.onWorkerAsyncUnsafe(accepted.worker, (actor) => actor.rateDriver({ requestId: this.state.requestId, stars }));
475
+ const rated = await this.group.onWorkerAsyncUnsafe(accepted.worker, (actor) => actor.rateDriver({ requestId: this.state.requestId, stars }));
476
+ this.freshNext = true;
477
+ return rated;
463
478
  }
464
479
  // ----- inside -----
465
480
  /** U-42: the driver of this offer is busy — the entry is gone, and its place in the worker goes to the next driver (ZO-12, best-effort). */
@@ -469,24 +484,32 @@ export class RideRequest {
469
484
  void this.onOfferAsyncUnsafe(offerId, (actor, ref) => actor.rejectOffer(ref)).catch(() => undefined);
470
485
  }
471
486
  async readAllAsyncUnsafe(workers) {
472
- const results = await Promise.allSettled(workers.map(async (worker) => ({ worker, view: await this.group.onWorkerAsyncUnsafe(worker, (actor) => actor.getRequest({ requestId: this.state.requestId })) })));
487
+ // ZO-25: the first read after the rider's own action goes through consensus.
488
+ const fresh = this.freshNext;
489
+ this.freshNext = false;
490
+ const read = (worker) => (fresh ? this.group.onWorkerFreshAsyncUnsafe(worker, (actor) => actor.getRequest({ requestId: this.state.requestId })) : this.group.onWorkerAsyncUnsafe(worker, (actor) => actor.getRequest({ requestId: this.state.requestId })));
491
+ const results = await Promise.allSettled(workers.map(async (worker) => ({ worker, view: await read(worker) })));
473
492
  const answers = [];
493
+ const failed = [];
474
494
  let failure;
475
495
  let notFound = 0;
476
- for (const result of results) {
496
+ results.forEach((result, index) => {
477
497
  if (result.status === "fulfilled")
478
498
  answers.push(result.value);
479
499
  else if (errorKeyOf(result.reason) === "NotFound")
480
500
  notFound += 1;
481
- else
501
+ else {
482
502
  failure ??= result.reason;
483
- }
503
+ failed.push(workers[index]);
504
+ }
505
+ });
484
506
  // One silent worker does not hide the rest; nobody answering is an error.
485
507
  if (answers.length === 0 && failure !== undefined)
486
508
  throw failure;
487
509
  if (answers.length === 0 && notFound > 0)
488
510
  throw canisterError("NotFound", "no worker holds this request");
489
- return answers;
511
+ // ZO-24: an older state than the held one, or a silent worker, keeps the held answer.
512
+ return freshViews(this.heldViews, answers, failed, Date.now());
490
513
  }
491
514
  async mergeAsync(answers) {
492
515
  const simulator = await this.simulatorIdAsync();
@@ -1,10 +1,17 @@
1
1
  import { type ActorSubclass, type Identity } from "@icp-sdk/core/agent";
2
+ import type { IDL } from "@icp-sdk/core/candid";
2
3
  import { Principal } from "@icp-sdk/core/principal";
3
4
  import type { _SERVICE as CoreService } from "../../declarations/core/core.did.js";
4
5
  import type { _SERVICE as WorkerService } from "../../declarations/worker/worker.did.js";
5
6
  import type { _SERVICE as CoordinatorService } from "../../declarations/coordinator/coordinator.did.js";
6
7
  import { type GroupOptions, type MotokoResult } from "./canister-actor.js";
7
8
  import { type PrefixEntryView } from "./prefixes.js";
9
+ /**
10
+ * ZO-25: the worker's interface with `getRequest` as an update call — the subnet answers from
11
+ * the state after every finished call, so no replica a round behind answers a read made right
12
+ * after the rider's own action with the state from before it.
13
+ */
14
+ export declare const workerFreshIdl: IDL.InterfaceFactory;
8
15
  export type CoreActor = ActorSubclass<CoreService>;
9
16
  export type WorkerActor = ActorSubclass<WorkerService>;
10
17
  export type CoordinatorActor = ActorSubclass<CoordinatorService>;
@@ -37,6 +44,8 @@ export declare class TigiGroup {
37
44
  private constructor();
38
45
  coordinatorAsync(): Promise<CoordinatorActor>;
39
46
  workerAsync(workerId: string): Promise<WorkerActor>;
47
+ /** ZO-25: a worker whose `getRequest` goes through consensus. */
48
+ workerFreshAsync(workerId: string): Promise<WorkerActor>;
40
49
  coreAsync(): Promise<CoreActor>;
41
50
  /**
42
51
  * The core's id, from the coordinator, kept for good.
@@ -55,6 +64,8 @@ export declare class TigiGroup {
55
64
  workerForAsyncUnsafe(geohash: string): Promise<string | undefined>;
56
65
  /** One call to one worker, its Result unwrapped. */
57
66
  onWorkerAsyncUnsafe<T>(workerId: string, callAsync: (worker: WorkerActor) => Promise<MotokoResult<T>>): Promise<T>;
67
+ /** ZO-25: one call through consensus to one worker, its Result unwrapped. */
68
+ onWorkerFreshAsyncUnsafe<T>(workerId: string, callAsync: (worker: WorkerActor) => Promise<MotokoResult<T>>): Promise<T>;
58
69
  /** The same read in every worker, in the order of the list. */
59
70
  onAllWorkersAsyncUnsafe<T>(callAsync: (worker: WorkerActor) => Promise<MotokoResult<T>>): Promise<T[]>;
60
71
  }
@@ -1 +1 @@
1
- {"version":3,"file":"group.d.ts","sourceRoot":"","sources":["../../src/group/group.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEpD,OAAO,KAAK,EAAE,QAAQ,IAAI,WAAW,EAAE,MAAM,qCAAqC,CAAC;AAEnF,OAAO,KAAK,EAAE,QAAQ,IAAI,aAAa,EAAE,MAAM,yCAAyC,CAAC;AAEzF,OAAO,KAAK,EAAE,QAAQ,IAAI,kBAAkB,EAAE,MAAM,mDAAmD,CAAC;AACxG,OAAO,EAAmE,KAAK,YAAY,EAAE,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAC5I,OAAO,EAAgB,KAAK,eAAe,EAAE,MAAM,eAAe,CAAC;AAEnE,MAAM,MAAM,SAAS,GAAG,aAAa,CAAC,WAAW,CAAC,CAAC;AACnD,MAAM,MAAM,WAAW,GAAG,aAAa,CAAC,aAAa,CAAC,CAAC;AACvD,MAAM,MAAM,gBAAgB,GAAG,aAAa,CAAC,kBAAkB,CAAC,CAAC;AAEjE,kFAAkF;AAClF,eAAO,MAAM,UAAU,QAAS,CAAC;AAOjC;;;;;;;;;;GAUG;AACH,qBAAa,SAAS;aA4BE,aAAa,EAA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CAAC,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAIpI,+DAA+D;IAClD,uBAAuB,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC;CAItH;AAED,wEAAwE;AACxE,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAEnD"}
@@ -5,6 +5,15 @@ import { idlFactory as workerIdl } from "../../declarations/worker/worker.did.js
5
5
  import { idlFactory as coordinatorIdl } from "../../declarations/coordinator/coordinator.did.js";
6
6
  import { executeAsyncUnsafe, MAINNET_HOST, rawActorAsync, transportAsync } from "./canister-actor.js";
7
7
  import { longestMatch } from "./prefixes.js";
8
+ /**
9
+ * ZO-25: the worker's interface with `getRequest` as an update call — the subnet answers from
10
+ * the state after every finished call, so no replica a round behind answers a read made right
11
+ * after the rider's own action with the state from before it.
12
+ */
13
+ export const workerFreshIdl = (args) => {
14
+ const service = workerIdl(args);
15
+ return args.IDL.Service(Object.fromEntries(service._fields.map(([name, func]) => [name, name === "getRequest" ? args.IDL.Func(func.argTypes, func.retTypes, []) : func])));
16
+ };
8
17
  /** The list of workers and the prefix map are asked for again after this long. */
9
18
  export const MAP_TTL_MS = 30_000;
10
19
  /**
@@ -56,6 +65,10 @@ export class TigiGroup {
56
65
  async workerAsync(workerId) {
57
66
  return rawActorAsync(workerIdl, workerId, this.identity, this.options);
58
67
  }
68
+ /** ZO-25: a worker whose `getRequest` goes through consensus. */
69
+ async workerFreshAsync(workerId) {
70
+ return rawActorAsync(workerFreshIdl, workerId, this.identity, this.options);
71
+ }
59
72
  async coreAsync() {
60
73
  return rawActorAsync(coreIdl, await this.getCoreIdAsyncUnsafe(), this.identity, this.options);
61
74
  }
@@ -108,6 +121,10 @@ export class TigiGroup {
108
121
  async onWorkerAsyncUnsafe(workerId, callAsync) {
109
122
  return executeAsyncUnsafe(async () => callAsync(await this.workerAsync(workerId)));
110
123
  }
124
+ /** ZO-25: one call through consensus to one worker, its Result unwrapped. */
125
+ async onWorkerFreshAsyncUnsafe(workerId, callAsync) {
126
+ return executeAsyncUnsafe(async () => callAsync(await this.workerFreshAsync(workerId)));
127
+ }
111
128
  /** The same read in every worker, in the order of the list. */
112
129
  async onAllWorkersAsyncUnsafe(callAsync) {
113
130
  const workers = await this.getWorkersAsyncUnsafe();
package/dist/mappers.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { CarrierKind as CandidCarrierKind, DriverCard, Money as CandidMoney, RideStatus, RouteLine } from "../declarations/tigi-driver/tigi-driver.did.js";
2
2
  import type { OfferView as CandidOfferView, RequestView as CandidRequestView } from "../declarations/worker/worker.did.js";
3
3
  import type { RateRideOutcome as CandidRateRideOutcome, RideView as CandidHistoryRide } from "../declarations/core/core.did.js";
4
- import type { CarrierKind, CloseReason, DriverCardView, Money, OfferView, RateRideOutcome, RequestPhase, RideHistoryEntry, RideStatusView, RouteLineView } from "./interfaces.js";
4
+ import type { CarrierKind, CloseReason, DriverCardView, Money, OfferView, RateRideOutcome, RequestPhase, RideHistoryEntry, RideStatusView, RideView, RouteLineView } from "./interfaces.js";
5
5
  export declare const NS_PER_MS = 1000000n;
6
6
  export declare function msOf(ns: bigint): number;
7
7
  export declare function moneyOf(money: CandidMoney): Money;
@@ -85,4 +85,32 @@ export declare function phaseOf(view: CandidRequestView): RequestPhase;
85
85
  * then an order waiting anywhere, then a search anywhere; closed only when closed in all.
86
86
  */
87
87
  export declare function mergedPhase(phases: RequestPhase[]): RequestPhase;
88
+ /** ZO-24: a worker's answer that failed is stood in for by its last one this long. */
89
+ export declare const STAND_IN_MS = 10000;
90
+ /** ZO-24: the last answer of one worker, with the time of its state. */
91
+ export interface HeldView<V> {
92
+ asOfNs: bigint;
93
+ view: V;
94
+ atMs: number;
95
+ }
96
+ /**
97
+ * ZO-24: a query goes to any replica of the subnet, and one a round behind answers from an
98
+ * older state (an offer flashing away and back). Per worker: an answer older than the held
99
+ * one is replaced by the held one; a worker that failed this time keeps its held answer for
100
+ * `STAND_IN_MS` (one silent worker does not blink its offers away). Updates `held`.
101
+ */
102
+ export declare function freshViews<V extends {
103
+ asOfNs: [] | [bigint];
104
+ }>(held: Map<string, HeldView<V>>, answers: {
105
+ worker: string;
106
+ view: V;
107
+ }[], failed: string[], nowMs: number): {
108
+ worker: string;
109
+ view: V;
110
+ }[];
111
+ /**
112
+ * ZO-24: a ride never goes back — an answer from an older state keeps the newer status, and
113
+ * the position stays the newer one (by `positionAtMs`).
114
+ */
115
+ export declare function fresherRide(before: RideView | undefined, next: RideView): RideView;
88
116
  //# sourceMappingURL=mappers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mappers.d.ts","sourceRoot":"","sources":["../src/mappers.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,IAAI,iBAAiB,EAAE,UAAU,EAAE,KAAK,IAAI,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,gDAAgD,CAAC;AAChK,OAAO,KAAK,EAAE,SAAS,IAAI,eAAe,EAAE,WAAW,IAAI,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AAC3H,OAAO,KAAK,EAAE,eAAe,IAAI,qBAAqB,EAAE,QAAQ,IAAI,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAEhI,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,cAAc,EAAE,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,YAAY,EAAW,gBAAgB,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAG3L,eAAO,MAAM,SAAS,WAAa,CAAC;AAEpC,wBAAgB,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAEvC;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,WAAW,GAA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;CAChB;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS;IAAE,MAAM,EAAE,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;CAAE,EAAE,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,CAAC,CAAA;CAAE,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,CAAC,CAAA;CAAE,EAAE,CActM;AAID;;;GAGG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,QAAQ,GAAG,SAAS,EAAE,IAAI,EAAE,QAAQ,GAAG,QAAQ,CAQlF"}
package/dist/mappers.js CHANGED
@@ -227,3 +227,46 @@ export function mergedPhase(phases) {
227
227
  }
228
228
  return "closed";
229
229
  }
230
+ // ---------------------------------------------------------------- ZO-24: fresh reads
231
+ /** ZO-24: a worker's answer that failed is stood in for by its last one this long. */
232
+ export const STAND_IN_MS = 10_000;
233
+ /**
234
+ * ZO-24: a query goes to any replica of the subnet, and one a round behind answers from an
235
+ * older state (an offer flashing away and back). Per worker: an answer older than the held
236
+ * one is replaced by the held one; a worker that failed this time keeps its held answer for
237
+ * `STAND_IN_MS` (one silent worker does not blink its offers away). Updates `held`.
238
+ */
239
+ export function freshViews(held, answers, failed, nowMs) {
240
+ const fresh = answers.map(({ worker, view }) => {
241
+ const asOf = view.asOfNs[0];
242
+ const before = held.get(worker);
243
+ if (asOf === undefined)
244
+ return { worker, view };
245
+ if (before && before.asOfNs > asOf)
246
+ return { worker, view: before.view };
247
+ held.set(worker, { asOfNs: asOf, view, atMs: nowMs });
248
+ return { worker, view };
249
+ });
250
+ for (const worker of failed) {
251
+ const before = held.get(worker);
252
+ if (before && nowMs - before.atMs <= STAND_IN_MS)
253
+ fresh.push({ worker, view: before.view });
254
+ }
255
+ return fresh;
256
+ }
257
+ const RIDE_STEP = { accepted: 0, driverArrived: 1, inProgress: 2, completed: 3, cancelledByDriver: 3, cancelledByRider: 3 };
258
+ /**
259
+ * ZO-24: a ride never goes back — an answer from an older state keeps the newer status, and
260
+ * the position stays the newer one (by `positionAtMs`).
261
+ */
262
+ export function fresherRide(before, next) {
263
+ if (!before || before.requestId !== next.requestId)
264
+ return next;
265
+ let ride = next;
266
+ if (RIDE_STEP[next.status.kind] < RIDE_STEP[before.status.kind])
267
+ ride = { ...ride, status: before.status };
268
+ if (before.positionAtMs !== undefined && (next.positionAtMs === undefined || next.positionAtMs < before.positionAtMs)) {
269
+ ride = { ...ride, driverPosition: before.driverPosition, positionAtMs: before.positionAtMs, etaToPickupSec: before.etaToPickupSec };
270
+ }
271
+ return ride;
272
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsm-mit/tigi-sharded-package",
3
- "version": "0.6.0",
3
+ "version": "0.8.0",
4
4
  "description": "The one package of the Tigi network group: takes the coordinator's id and hides the coordinator, the core and the workers — for a consumer the group is one canister; plus the rider's few driver-canister endpoints (U-14).",
5
5
  "homepage": "https://github.com/JSM-Tigi/tigi-sharded/tree/master/package#readme",
6
6
  "repository": {
@@ -59,11 +59,11 @@
59
59
  "tigiSharded": {
60
60
  "repo": "tigi-sharded",
61
61
  "repoUrl": "https://github.com/JSM-Tigi/tigi-sharded",
62
- "commit": "148160dc78284db42f421146b0b68d5404bb6926"
62
+ "commit": "5ec9ad29681d2cf1bca3013f21bdafaf8ca55488"
63
63
  },
64
64
  "tigiDriverRust": {
65
65
  "repo": "tigi-driver-rust",
66
66
  "repoUrl": "https://github.com/JSM-Tigi/tigi-driver-rust",
67
- "commit": "d39d7dc2b06358a570c3f07cbba17900297047a3"
67
+ "commit": "2b94213452793026865ac2a51412984eb40c7c8d"
68
68
  }
69
69
  }