@optimystic/db-core 1.7.0 → 1.8.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.
@@ -144,12 +144,17 @@ export class NetworkTransactor implements ITransactor, IBlockChangeNotifier {
144
144
  );
145
145
 
146
146
  const expiration = Date.now() + this.timeoutMs;
147
+ // Both rounds forward the caller's floors for the batch's blocks. A repo that predates the
148
+ // field ignores it and answers as before; the `belowFloor` check below is what holds the floor
149
+ // either way, so forwarding adds a chance of a first answer that meets it, never a guarantee.
150
+ const askRepo = (batch: CoordinatorBatch<BlockId[], GetBlockResults>) =>
151
+ this.getRepo(batch.peerId).get(downstreamGets(batch.payload, blockGets), { expiration, dialTimeoutMs: this.dialTimeoutMs });
147
152
 
148
153
  let error: Error | undefined;
149
154
  try {
150
155
  await processBatches(
151
156
  batches,
152
- (batch) => this.getRepo(batch.peerId).get({ blockIds: batch.payload, context: blockGets.context }, { expiration, dialTimeoutMs: this.dialTimeoutMs }),
157
+ askRepo,
153
158
  batch => batch.payload,
154
159
  (gets, blockId, mergeWithGets) => [...(mergeWithGets ?? []), ...gets.filter(bid => bid === blockId)],
155
160
  expiration,
@@ -254,7 +259,7 @@ export class NetworkTransactor implements ITransactor, IBlockChangeNotifier {
254
259
  b.subsumedBy = [...(b.subsumedBy ?? []), ...retries];
255
260
  await processBatches(
256
261
  retries,
257
- (batch) => this.getRepo(batch.peerId).get({ blockIds: batch.payload, context: blockGets.context }, { expiration, dialTimeoutMs: this.dialTimeoutMs }),
262
+ askRepo,
258
263
  batch => batch.payload,
259
264
  (gets, blockId, mergeWithGets) => [...(mergeWithGets ?? []), ...gets.filter(id => id === blockId)],
260
265
  expiration,
@@ -1489,6 +1494,19 @@ function pendRequestForBatch(action: PendRequest, payload: Transforms): PendRequ
1489
1494
  return { ...rest, transforms: payload, ...baseRevsFor(baseRevs, blockIdsForTransforms(payload)) };
1490
1495
  }
1491
1496
 
1497
+ /** The read one coordinator batch sends downstream: the batch's ids, the caller's context, and the
1498
+ * caller's floors for those ids alone (see {@link BlockGets.floors}). The `floors` key is left off
1499
+ * entirely when no block in the batch has one, so an unfloored read goes out exactly as it did before
1500
+ * floors travelled. Same send-time rule as {@link digestsFor}, for the same reason. */
1501
+ function downstreamGets(batchBlockIds: BlockId[], blockGets: BlockGets): BlockGets {
1502
+ const floors = blockGets.floors === undefined ? {} : subsetOf(blockGets.floors, batchBlockIds);
1503
+ return {
1504
+ blockIds: batchBlockIds,
1505
+ context: blockGets.context,
1506
+ ...(isRecordEmpty(floors) ? {} : { floors }),
1507
+ };
1508
+ }
1509
+
1492
1510
  /**
1493
1511
  * The owning collection id for an action ref, read from any fetched block's header. A
1494
1512
  * committed-then-invalidated action still has a materialized (compensating) block whose header carries