@optimystic/db-p2p 0.27.0 → 0.29.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.
Files changed (67) hide show
  1. package/dist/src/cluster/block-transfer-service.d.ts +0 -10
  2. package/dist/src/cluster/block-transfer-service.d.ts.map +1 -1
  3. package/dist/src/cluster/block-transfer-service.js +4 -2
  4. package/dist/src/cluster/block-transfer-service.js.map +1 -1
  5. package/dist/src/cluster/cluster-policy.d.ts +101 -18
  6. package/dist/src/cluster/cluster-policy.d.ts.map +1 -1
  7. package/dist/src/cluster/cluster-policy.js +153 -30
  8. package/dist/src/cluster/cluster-policy.js.map +1 -1
  9. package/dist/src/cluster/quorum-restore.d.ts +4 -2
  10. package/dist/src/cluster/quorum-restore.d.ts.map +1 -1
  11. package/dist/src/cluster/quorum-restore.js +4 -2
  12. package/dist/src/cluster/quorum-restore.js.map +1 -1
  13. package/dist/src/cluster/service.d.ts +12 -9
  14. package/dist/src/cluster/service.d.ts.map +1 -1
  15. package/dist/src/cluster/service.js +6 -6
  16. package/dist/src/cluster/service.js.map +1 -1
  17. package/dist/src/dispute/service.d.ts +1 -4
  18. package/dist/src/dispute/service.d.ts.map +1 -1
  19. package/dist/src/dispute/service.js +2 -1
  20. package/dist/src/dispute/service.js.map +1 -1
  21. package/dist/src/libp2p-key-network.d.ts +38 -0
  22. package/dist/src/libp2p-key-network.d.ts.map +1 -1
  23. package/dist/src/libp2p-key-network.js +47 -1
  24. package/dist/src/libp2p-key-network.js.map +1 -1
  25. package/dist/src/libp2p-node-base.d.ts.map +1 -1
  26. package/dist/src/libp2p-node-base.js +22 -19
  27. package/dist/src/libp2p-node-base.js.map +1 -1
  28. package/dist/src/logger.d.ts +28 -1
  29. package/dist/src/logger.d.ts.map +1 -1
  30. package/dist/src/logger.js +143 -1
  31. package/dist/src/logger.js.map +1 -1
  32. package/dist/src/network/network-manager-service.d.ts +1 -4
  33. package/dist/src/network/network-manager-service.d.ts.map +1 -1
  34. package/dist/src/network/network-manager-service.js +2 -1
  35. package/dist/src/network/network-manager-service.js.map +1 -1
  36. package/dist/src/repo/coordinator-repo.d.ts +183 -13
  37. package/dist/src/repo/coordinator-repo.d.ts.map +1 -1
  38. package/dist/src/repo/coordinator-repo.js +686 -107
  39. package/dist/src/repo/coordinator-repo.js.map +1 -1
  40. package/dist/src/repo/service.d.ts +9 -6
  41. package/dist/src/repo/service.d.ts.map +1 -1
  42. package/dist/src/repo/service.js +4 -5
  43. package/dist/src/repo/service.js.map +1 -1
  44. package/dist/src/sync/service.d.ts +1 -2
  45. package/dist/src/sync/service.d.ts.map +1 -1
  46. package/dist/src/sync/service.js +2 -1
  47. package/dist/src/sync/service.js.map +1 -1
  48. package/dist/src/testing/mesh-harness.d.ts +7 -1
  49. package/dist/src/testing/mesh-harness.d.ts.map +1 -1
  50. package/dist/src/testing/mesh-harness.js +2 -1
  51. package/dist/src/testing/mesh-harness.js.map +1 -1
  52. package/package.json +2 -2
  53. package/readme.md +19 -0
  54. package/src/cluster/block-transfer-service.ts +4 -8
  55. package/src/cluster/cluster-policy.ts +196 -36
  56. package/src/cluster/quorum-restore.ts +4 -2
  57. package/src/cluster/service.ts +14 -9
  58. package/src/dispute/service.ts +3 -3
  59. package/src/libp2p-key-network.ts +50 -1
  60. package/src/libp2p-node-base.ts +22 -19
  61. package/src/logger.ts +196 -2
  62. package/src/network/network-manager-service.ts +414 -414
  63. package/src/protocol-client.ts +196 -196
  64. package/src/repo/coordinator-repo.ts +833 -122
  65. package/src/repo/service.ts +12 -9
  66. package/src/sync/service.ts +3 -5
  67. package/src/testing/mesh-harness.ts +8 -1
@@ -1,22 +1,19 @@
1
1
  import { pipe } from 'it-pipe'
2
2
  import { decode as lpDecode, encode as lpEncode } from 'it-length-prefixed'
3
- import type { Startable, Logger, Stream, Connection, StreamHandler, PeerId, Libp2p } from '@libp2p/interface'
3
+ import type { Startable, Stream, Connection, StreamHandler, PeerId, Libp2p } from '@libp2p/interface'
4
4
  import type { IRepo, RepoMessage } from '@optimystic/db-core'
5
5
  import { blockIdsForTransforms } from '@optimystic/db-core'
6
6
  import { peersEqual } from '../peer-utils.js'
7
7
  import { encodePeers, type RedirectPayload } from './redirect.js'
8
8
  import { MAX_BLOCK_MESSAGE_BYTES } from '../protocol-limits.js'
9
9
  import type { Uint8ArrayList } from 'uint8arraylist'
10
- import { createLogger } from '../logger.js'
10
+ import { createLogger, type Logger } from '../logger.js'
11
11
  import { publishableAddrsForPeer, type AddressLog, type DirectionalConnection } from '../peer-address-book.js'
12
12
  import { createInboundStreamAuthorization, type InboundStreamAuthorization, type InboundStreamAuthorizationInit } from '../inbound-authorization.js'
13
13
  import { registerProtocolHandler } from '../network/register-protocol-handler.js'
14
14
 
15
- const debugLog = createLogger('repo-service')
16
-
17
15
  // Define Components interface
18
16
  interface BaseComponents {
19
- logger: { forComponent: (name: string) => Logger },
20
17
  registrar: {
21
18
  handle: (protocol: string, handler: StreamHandler, options: any) => Promise<void>
22
19
  unhandle: (protocol: string) => Promise<void>
@@ -52,6 +49,12 @@ export type RepoServiceInit = InboundStreamAuthorizationInit & {
52
49
  protocolPrefix?: string,
53
50
  maxInboundStreams?: number,
54
51
  maxOutboundStreams?: number,
52
+ /**
53
+ * Sub-namespace this service logs under, i.e. the `<x>` in `optimystic:db-p2p:<x>`.
54
+ * NOT a full namespace: an embedder cannot use this to move the service's lines outside the
55
+ * `optimystic:db-p2p:*` tree `docs/debugging.md` tells operators to filter on.
56
+ * Default: `repo-service`.
57
+ */
55
58
  logPrefix?: string,
56
59
  kBucketSize?: number,
57
60
  /**
@@ -94,8 +97,8 @@ export class RepoService implements Startable {
94
97
  private readonly authorization: InboundStreamAuthorization | undefined
95
98
  /**
96
99
  * Sink for this service's `peer-address-book:*` lines — same reasoning as `ClusterService`'s:
97
- * `this.log.error` would strand them under `db-p2p:repo-service:error`, outside the
98
- * `optimystic:db-p2p:*` tree every other address-book line lives in.
100
+ * `this.log.error` would scatter one tag family across whichever service happened to be the
101
+ * ingress point, instead of keeping it filterable as the single `peer-address-book` namespace.
99
102
  */
100
103
  private readonly addressLog: AddressLog
101
104
 
@@ -105,7 +108,7 @@ export class RepoService implements Startable {
105
108
  this.protocol = computed
106
109
  this.maxInboundStreams = init.maxInboundStreams ?? 32
107
110
  this.maxOutboundStreams = init.maxOutboundStreams ?? 64
108
- this.log = components.logger.forComponent(init.logPrefix ?? 'db-p2p:repo-service')
111
+ this.log = createLogger(init.logPrefix ?? 'repo-service')
109
112
  this.addressLog = createLogger('peer-address-book', components.peerId?.toString())
110
113
  this.repo = components.repo
111
114
  this.running = false
@@ -246,7 +249,7 @@ export class RepoService implements Startable {
246
249
 
247
250
  if (!smallMesh && !isMember) {
248
251
  const peers = cluster.filter((p: PeerId) => !peersEqual(p, selfId))
249
- debugLog('redirect op=%s blockKey=%s cluster=%d', opName, blockKey, cluster.length)
252
+ this.log('redirect op=%s blockKey=%s cluster=%d', opName, blockKey, cluster.length)
250
253
  return encodePeers(await Promise.all(peers.map(async (pid: PeerId) => ({
251
254
  id: pid.toString(),
252
255
  addrs: await this.getPeerAddrs(pid)
@@ -1,4 +1,4 @@
1
- import type { ComponentLogger, Connection, Startable } from '@libp2p/interface';
1
+ import type { Connection, Startable } from '@libp2p/interface';
2
2
  import { buildSyncProtocol, type SyncRequest, type SyncResponse } from './protocol.js';
3
3
  import { pipe } from 'it-pipe';
4
4
  import { toString as u8ToString } from 'uint8arrays/to-string';
@@ -9,13 +9,13 @@ import { createInboundStreamAuthorization, type InboundStreamAuthorization, type
9
9
  import { serveBlockArchive, type ArchiveServingRepo } from '../storage/block-archive.js';
10
10
  import { registerProtocolHandler } from '../network/register-protocol-handler.js';
11
11
  import type { BlockArchive } from '../storage/struct.js';
12
+ import { createLogger, type Logger } from '../logger.js';
12
13
 
13
14
  export interface SyncServiceInit extends InboundStreamAuthorizationInit {
14
15
  protocolPrefix?: string;
15
16
  }
16
17
 
17
18
  export interface SyncServiceComponents {
18
- logger: ComponentLogger;
19
19
  registrar: { handle: (...args: any[]) => Promise<void>, unhandle: (...args: any[]) => Promise<void> };
20
20
  /**
21
21
  * The local store this node answers repair fetches out of. Declared as `ArchiveServingRepo`
@@ -28,8 +28,6 @@ export interface SyncServiceComponents {
28
28
  repo: ArchiveServingRepo;
29
29
  }
30
30
 
31
- type Logger = ReturnType<ComponentLogger['forComponent']>;
32
-
33
31
  /**
34
32
  * Service for handling incoming sync requests from other cluster peers.
35
33
  *
@@ -53,7 +51,7 @@ export class SyncService implements Startable {
53
51
  components: SyncServiceComponents,
54
52
  init: SyncServiceInit = {}
55
53
  ) {
56
- this.log = components.logger.forComponent('db-p2p:sync-service');
54
+ this.log = createLogger('sync-service');
57
55
  this.protocol = buildSyncProtocol(init.protocolPrefix ?? '');
58
56
  this.repo = components.repo;
59
57
  this.registrar = components.registrar;
@@ -485,6 +485,12 @@ export async function nonResponsibleNodes(mesh: Mesh, blockId: string): Promise<
485
485
  export interface BuildTransactorOptions {
486
486
  timeoutMs?: number;
487
487
  abortOrCancelTimeoutMs?: number;
488
+ /**
489
+ * Wraps each node's repo before the transactor sees it, so a test can inject a transport-shaped
490
+ * failure into one RPC (a dropped sweep commit, a refused pend) and leave every other call — and
491
+ * therefore all of the production code after the injection — untouched.
492
+ */
493
+ wrapRepo?: (repo: IRepo, node: MeshNode) => IRepo;
488
494
  }
489
495
 
490
496
  /**
@@ -496,7 +502,8 @@ export interface BuildTransactorOptions {
496
502
  export const buildNetworkTransactor = (mesh: Mesh, options: BuildTransactorOptions = {}): ITransactor => {
497
503
  const repoByPeer = new Map<string, IRepo>();
498
504
  for (const node of mesh.nodes) {
499
- repoByPeer.set(node.peerId.toString(), node.coordinatorRepo as unknown as IRepo);
505
+ const repo = node.coordinatorRepo as unknown as IRepo;
506
+ repoByPeer.set(node.peerId.toString(), options.wrapRepo ? options.wrapRepo(repo, node) : repo);
500
507
  }
501
508
  return new NetworkTransactor({
502
509
  timeoutMs: options.timeoutMs ?? 5_000,