@optimystic/db-p2p 0.0.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.
Files changed (189) hide show
  1. package/dist/index.min.js +52 -0
  2. package/dist/index.min.js.map +7 -0
  3. package/dist/src/cluster/client.d.ts +12 -0
  4. package/dist/src/cluster/client.d.ts.map +1 -0
  5. package/dist/src/cluster/client.js +65 -0
  6. package/dist/src/cluster/client.js.map +1 -0
  7. package/dist/src/cluster/cluster-repo.d.ts +79 -0
  8. package/dist/src/cluster/cluster-repo.d.ts.map +1 -0
  9. package/dist/src/cluster/cluster-repo.js +613 -0
  10. package/dist/src/cluster/cluster-repo.js.map +1 -0
  11. package/dist/src/cluster/partition-detector.d.ts +59 -0
  12. package/dist/src/cluster/partition-detector.d.ts.map +1 -0
  13. package/dist/src/cluster/partition-detector.js +129 -0
  14. package/dist/src/cluster/partition-detector.js.map +1 -0
  15. package/dist/src/cluster/service.d.ts +49 -0
  16. package/dist/src/cluster/service.d.ts.map +1 -0
  17. package/dist/src/cluster/service.js +107 -0
  18. package/dist/src/cluster/service.js.map +1 -0
  19. package/dist/src/index.d.ts +29 -0
  20. package/dist/src/index.d.ts.map +1 -0
  21. package/dist/src/index.js +29 -0
  22. package/dist/src/index.js.map +1 -0
  23. package/dist/src/it-utility.d.ts +4 -0
  24. package/dist/src/it-utility.d.ts.map +1 -0
  25. package/dist/src/it-utility.js +32 -0
  26. package/dist/src/it-utility.js.map +1 -0
  27. package/dist/src/libp2p-key-network.d.ts +59 -0
  28. package/dist/src/libp2p-key-network.d.ts.map +1 -0
  29. package/dist/src/libp2p-key-network.js +278 -0
  30. package/dist/src/libp2p-key-network.js.map +1 -0
  31. package/dist/src/libp2p-node.d.ts +28 -0
  32. package/dist/src/libp2p-node.d.ts.map +1 -0
  33. package/dist/src/libp2p-node.js +270 -0
  34. package/dist/src/libp2p-node.js.map +1 -0
  35. package/dist/src/logger.d.ts +3 -0
  36. package/dist/src/logger.d.ts.map +1 -0
  37. package/dist/src/logger.js +6 -0
  38. package/dist/src/logger.js.map +1 -0
  39. package/dist/src/network/get-network-manager.d.ts +4 -0
  40. package/dist/src/network/get-network-manager.d.ts.map +1 -0
  41. package/dist/src/network/get-network-manager.js +17 -0
  42. package/dist/src/network/get-network-manager.js.map +1 -0
  43. package/dist/src/network/network-manager-service.d.ts +82 -0
  44. package/dist/src/network/network-manager-service.d.ts.map +1 -0
  45. package/dist/src/network/network-manager-service.js +283 -0
  46. package/dist/src/network/network-manager-service.js.map +1 -0
  47. package/dist/src/peer-utils.d.ts +2 -0
  48. package/dist/src/peer-utils.d.ts.map +1 -0
  49. package/dist/src/peer-utils.js +28 -0
  50. package/dist/src/peer-utils.js.map +1 -0
  51. package/dist/src/protocol-client.d.ts +12 -0
  52. package/dist/src/protocol-client.d.ts.map +1 -0
  53. package/dist/src/protocol-client.js +34 -0
  54. package/dist/src/protocol-client.js.map +1 -0
  55. package/dist/src/repo/client.d.ts +17 -0
  56. package/dist/src/repo/client.d.ts.map +1 -0
  57. package/dist/src/repo/client.js +82 -0
  58. package/dist/src/repo/client.js.map +1 -0
  59. package/dist/src/repo/cluster-coordinator.d.ts +59 -0
  60. package/dist/src/repo/cluster-coordinator.d.ts.map +1 -0
  61. package/dist/src/repo/cluster-coordinator.js +539 -0
  62. package/dist/src/repo/cluster-coordinator.js.map +1 -0
  63. package/dist/src/repo/coordinator-repo.d.ts +29 -0
  64. package/dist/src/repo/coordinator-repo.d.ts.map +1 -0
  65. package/dist/src/repo/coordinator-repo.js +102 -0
  66. package/dist/src/repo/coordinator-repo.js.map +1 -0
  67. package/dist/src/repo/redirect.d.ts +14 -0
  68. package/dist/src/repo/redirect.d.ts.map +1 -0
  69. package/dist/src/repo/redirect.js +9 -0
  70. package/dist/src/repo/redirect.js.map +1 -0
  71. package/dist/src/repo/service.d.ts +52 -0
  72. package/dist/src/repo/service.d.ts.map +1 -0
  73. package/dist/src/repo/service.js +181 -0
  74. package/dist/src/repo/service.js.map +1 -0
  75. package/dist/src/repo/types.d.ts +7 -0
  76. package/dist/src/repo/types.d.ts.map +1 -0
  77. package/dist/src/repo/types.js +2 -0
  78. package/dist/src/repo/types.js.map +1 -0
  79. package/dist/src/routing/libp2p-known-peers.d.ts +4 -0
  80. package/dist/src/routing/libp2p-known-peers.d.ts.map +1 -0
  81. package/dist/src/routing/libp2p-known-peers.js +19 -0
  82. package/dist/src/routing/libp2p-known-peers.js.map +1 -0
  83. package/dist/src/routing/responsibility.d.ts +14 -0
  84. package/dist/src/routing/responsibility.d.ts.map +1 -0
  85. package/dist/src/routing/responsibility.js +45 -0
  86. package/dist/src/routing/responsibility.js.map +1 -0
  87. package/dist/src/routing/simple-cluster-coordinator.d.ts +23 -0
  88. package/dist/src/routing/simple-cluster-coordinator.d.ts.map +1 -0
  89. package/dist/src/routing/simple-cluster-coordinator.js +59 -0
  90. package/dist/src/routing/simple-cluster-coordinator.js.map +1 -0
  91. package/dist/src/storage/arachnode-fret-adapter.d.ts +65 -0
  92. package/dist/src/storage/arachnode-fret-adapter.d.ts.map +1 -0
  93. package/dist/src/storage/arachnode-fret-adapter.js +93 -0
  94. package/dist/src/storage/arachnode-fret-adapter.js.map +1 -0
  95. package/dist/src/storage/block-storage.d.ts +31 -0
  96. package/dist/src/storage/block-storage.d.ts.map +1 -0
  97. package/dist/src/storage/block-storage.js +154 -0
  98. package/dist/src/storage/block-storage.js.map +1 -0
  99. package/dist/src/storage/file-storage.d.ts +30 -0
  100. package/dist/src/storage/file-storage.d.ts.map +1 -0
  101. package/dist/src/storage/file-storage.js +127 -0
  102. package/dist/src/storage/file-storage.js.map +1 -0
  103. package/dist/src/storage/helpers.d.ts +3 -0
  104. package/dist/src/storage/helpers.d.ts.map +1 -0
  105. package/dist/src/storage/helpers.js +28 -0
  106. package/dist/src/storage/helpers.js.map +1 -0
  107. package/dist/src/storage/i-block-storage.d.ts +32 -0
  108. package/dist/src/storage/i-block-storage.d.ts.map +1 -0
  109. package/dist/src/storage/i-block-storage.js +2 -0
  110. package/dist/src/storage/i-block-storage.js.map +1 -0
  111. package/dist/src/storage/i-raw-storage.d.ts +20 -0
  112. package/dist/src/storage/i-raw-storage.d.ts.map +1 -0
  113. package/dist/src/storage/i-raw-storage.js +2 -0
  114. package/dist/src/storage/i-raw-storage.js.map +1 -0
  115. package/dist/src/storage/memory-storage.d.ts +27 -0
  116. package/dist/src/storage/memory-storage.d.ts.map +1 -0
  117. package/dist/src/storage/memory-storage.js +87 -0
  118. package/dist/src/storage/memory-storage.js.map +1 -0
  119. package/dist/src/storage/restoration-coordinator-v2.d.ts +63 -0
  120. package/dist/src/storage/restoration-coordinator-v2.d.ts.map +1 -0
  121. package/dist/src/storage/restoration-coordinator-v2.js +157 -0
  122. package/dist/src/storage/restoration-coordinator-v2.js.map +1 -0
  123. package/dist/src/storage/ring-selector.d.ts +56 -0
  124. package/dist/src/storage/ring-selector.d.ts.map +1 -0
  125. package/dist/src/storage/ring-selector.js +118 -0
  126. package/dist/src/storage/ring-selector.js.map +1 -0
  127. package/dist/src/storage/storage-monitor.d.ts +23 -0
  128. package/dist/src/storage/storage-monitor.d.ts.map +1 -0
  129. package/dist/src/storage/storage-monitor.js +40 -0
  130. package/dist/src/storage/storage-monitor.js.map +1 -0
  131. package/dist/src/storage/storage-repo.d.ts +17 -0
  132. package/dist/src/storage/storage-repo.d.ts.map +1 -0
  133. package/dist/src/storage/storage-repo.js +267 -0
  134. package/dist/src/storage/storage-repo.js.map +1 -0
  135. package/dist/src/storage/struct.d.ts +29 -0
  136. package/dist/src/storage/struct.d.ts.map +1 -0
  137. package/dist/src/storage/struct.js +2 -0
  138. package/dist/src/storage/struct.js.map +1 -0
  139. package/dist/src/sync/client.d.ts +27 -0
  140. package/dist/src/sync/client.d.ts.map +1 -0
  141. package/dist/src/sync/client.js +32 -0
  142. package/dist/src/sync/client.js.map +1 -0
  143. package/dist/src/sync/protocol.d.ts +58 -0
  144. package/dist/src/sync/protocol.d.ts.map +1 -0
  145. package/dist/src/sync/protocol.js +12 -0
  146. package/dist/src/sync/protocol.js.map +1 -0
  147. package/dist/src/sync/service.d.ts +62 -0
  148. package/dist/src/sync/service.d.ts.map +1 -0
  149. package/dist/src/sync/service.js +168 -0
  150. package/dist/src/sync/service.js.map +1 -0
  151. package/package.json +73 -0
  152. package/readme.md +497 -0
  153. package/src/cluster/client.ts +63 -0
  154. package/src/cluster/cluster-repo.ts +711 -0
  155. package/src/cluster/partition-detector.ts +158 -0
  156. package/src/cluster/service.ts +156 -0
  157. package/src/index.ts +30 -0
  158. package/src/it-utility.ts +36 -0
  159. package/src/libp2p-key-network.ts +334 -0
  160. package/src/libp2p-node.ts +335 -0
  161. package/src/logger.ts +9 -0
  162. package/src/network/get-network-manager.ts +17 -0
  163. package/src/network/network-manager-service.ts +334 -0
  164. package/src/peer-utils.ts +24 -0
  165. package/src/protocol-client.ts +54 -0
  166. package/src/repo/client.ts +112 -0
  167. package/src/repo/cluster-coordinator.ts +592 -0
  168. package/src/repo/coordinator-repo.ts +137 -0
  169. package/src/repo/redirect.ts +17 -0
  170. package/src/repo/service.ts +219 -0
  171. package/src/repo/types.ts +7 -0
  172. package/src/routing/libp2p-known-peers.ts +26 -0
  173. package/src/routing/responsibility.ts +63 -0
  174. package/src/routing/simple-cluster-coordinator.ts +70 -0
  175. package/src/storage/arachnode-fret-adapter.ts +128 -0
  176. package/src/storage/block-storage.ts +182 -0
  177. package/src/storage/file-storage.ts +163 -0
  178. package/src/storage/helpers.ts +29 -0
  179. package/src/storage/i-block-storage.ts +40 -0
  180. package/src/storage/i-raw-storage.ts +30 -0
  181. package/src/storage/memory-storage.ts +108 -0
  182. package/src/storage/restoration-coordinator-v2.ts +191 -0
  183. package/src/storage/ring-selector.ts +155 -0
  184. package/src/storage/storage-monitor.ts +59 -0
  185. package/src/storage/storage-repo.ts +320 -0
  186. package/src/storage/struct.ts +34 -0
  187. package/src/sync/client.ts +42 -0
  188. package/src/sync/protocol.ts +71 -0
  189. package/src/sync/service.ts +229 -0
@@ -0,0 +1,59 @@
1
+ import type { ClusterRecord, IKeyNetwork, RepoMessage, BlockId, MessageOptions, ClusterConsensusConfig } from "@optimystic/db-core";
2
+ import { ClusterClient } from "../cluster/client.js";
3
+ import type { PeerId } from "@libp2p/interface";
4
+ import type { FretService } from "p2p-fret";
5
+ /** Manages distributed transactions across clusters */
6
+ export declare class ClusterCoordinator {
7
+ private readonly keyNetwork;
8
+ private readonly createClusterClient;
9
+ private readonly cfg;
10
+ private readonly localCluster?;
11
+ private readonly fretService?;
12
+ private transactions;
13
+ private readonly retryInitialIntervalMs;
14
+ private readonly retryBackoffFactor;
15
+ private readonly retryMaxIntervalMs;
16
+ private readonly retryMaxAttempts;
17
+ constructor(keyNetwork: IKeyNetwork, createClusterClient: (peerId: PeerId) => ClusterClient, cfg: ClusterConsensusConfig & {
18
+ clusterSize: number;
19
+ }, localCluster?: {
20
+ update: (record: ClusterRecord) => Promise<ClusterRecord>;
21
+ peerId: PeerId;
22
+ } | undefined, fretService?: FretService | undefined);
23
+ /**
24
+ * Creates a base 58 BTC string hash for a message to uniquely identify a transaction
25
+ */
26
+ private createMessageHash;
27
+ /**
28
+ * Gets all peers in the cluster for a specific block ID
29
+ */
30
+ private getClusterForBlock;
31
+ private makeRecord;
32
+ /**
33
+ * Initiates a 2-phase transaction for a specific block ID
34
+ */
35
+ executeClusterTransaction(blockId: BlockId, message: RepoMessage, options?: MessageOptions): Promise<any>;
36
+ /**
37
+ * Executes the full transaction process
38
+ */
39
+ private executeTransaction;
40
+ getClusterSize(blockId: BlockId): Promise<number>;
41
+ /**
42
+ * Validate that a small cluster size is legitimate by querying remote peers
43
+ * for their network size estimates. Returns true if estimates roughly agree.
44
+ */
45
+ private validateSmallCluster;
46
+ /**
47
+ * Collects promises from all peers in the cluster
48
+ */
49
+ private collectPromises;
50
+ /**
51
+ * Commits the transaction to all peers in the cluster
52
+ */
53
+ private commitTransaction;
54
+ private updateTransactionRecord;
55
+ private scheduleCommitRetry;
56
+ private retryCommits;
57
+ private clearRetry;
58
+ }
59
+ //# sourceMappingURL=cluster-coordinator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cluster-coordinator.d.ts","sourceRoot":"","sources":["../../../src/repo/cluster-coordinator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,WAAW,EAAE,OAAO,EAAgB,cAAc,EAAa,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAG7J,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAGhD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAwB5C,uDAAuD;AACvD,qBAAa,kBAAkB;IAS7B,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,mBAAmB;IACpC,OAAO,CAAC,QAAQ,CAAC,GAAG;IACpB,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC;IAC9B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC;IAX9B,OAAO,CAAC,YAAY,CAAmD;IACvE,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAAQ;IAC/C,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAK;IACxC,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAS;IAC5C,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAK;gBAGpB,UAAU,EAAE,WAAW,EACvB,mBAAmB,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,aAAa,EACtD,GAAG,EAAE,sBAAsB,GAAG;QAAE,WAAW,EAAE,MAAM,CAAA;KAAE,EACrD,YAAY,CAAC,EAAE;QAAE,MAAM,EAAE,CAAC,MAAM,EAAE,aAAa,KAAK,OAAO,CAAC,aAAa,CAAC,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,YAAA,EAC5F,WAAW,CAAC,EAAE,WAAW,YAAA;IAG3C;;OAEG;YACW,iBAAiB;IAM/B;;OAEG;YACW,kBAAkB;IAahC,OAAO,CAAC,UAAU;IA6BlB;;OAEG;IACG,yBAAyB,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,GAAG,CAAC;IAmE/G;;OAEG;YACW,kBAAkB;IAkE1B,cAAc,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC;IAKvD;;;OAGG;YACW,oBAAoB;IAmClC;;OAEG;YACW,eAAe;IAqF7B;;OAEG;YACW,iBAAiB;IAiG/B,OAAO,CAAC,uBAAuB;IAgB/B,OAAO,CAAC,mBAAmB;YAgCb,YAAY;IAkD1B,OAAO,CAAC,UAAU;CAkBlB"}
@@ -0,0 +1,539 @@
1
+ import { peerIdFromString } from "@libp2p/peer-id";
2
+ import { base58btc } from "multiformats/bases/base58";
3
+ import { sha256 } from "multiformats/hashes/sha2";
4
+ import { Pending } from "@optimystic/db-core";
5
+ import { createLogger } from '../logger.js';
6
+ const log = createLogger('cluster');
7
+ /** Manages distributed transactions across clusters */
8
+ export class ClusterCoordinator {
9
+ keyNetwork;
10
+ createClusterClient;
11
+ cfg;
12
+ localCluster;
13
+ fretService;
14
+ // TODO: move this into a state management interface so that transaction state can be persisted
15
+ transactions = new Map();
16
+ retryInitialIntervalMs = 2000;
17
+ retryBackoffFactor = 2;
18
+ retryMaxIntervalMs = 30000;
19
+ retryMaxAttempts = 5;
20
+ constructor(keyNetwork, createClusterClient, cfg, localCluster, fretService) {
21
+ this.keyNetwork = keyNetwork;
22
+ this.createClusterClient = createClusterClient;
23
+ this.cfg = cfg;
24
+ this.localCluster = localCluster;
25
+ this.fretService = fretService;
26
+ }
27
+ /**
28
+ * Creates a base 58 BTC string hash for a message to uniquely identify a transaction
29
+ */
30
+ async createMessageHash(message) {
31
+ const msgBytes = new TextEncoder().encode(JSON.stringify(message));
32
+ const hashBytes = await sha256.digest(msgBytes);
33
+ return base58btc.encode(hashBytes.digest);
34
+ }
35
+ /**
36
+ * Gets all peers in the cluster for a specific block ID
37
+ */
38
+ async getClusterForBlock(blockId) {
39
+ const blockIdBytes = new TextEncoder().encode(blockId);
40
+ try {
41
+ const peers = await this.keyNetwork.findCluster(blockIdBytes);
42
+ const peerIds = Object.keys(peers ?? {});
43
+ log('cluster-tx:cluster-members', { blockId, peerIds });
44
+ return peers;
45
+ }
46
+ catch (e) {
47
+ log('WARN findCluster failed for %s: %o', blockId, e);
48
+ return {};
49
+ }
50
+ }
51
+ makeRecord(peers, messageHash, message) {
52
+ const peerCount = Object.keys(peers ?? {}).length;
53
+ const record = {
54
+ messageHash,
55
+ peers,
56
+ message,
57
+ coordinatingBlockIds: message.coordinatingBlockIds,
58
+ promises: {},
59
+ commits: {},
60
+ suggestedClusterSize: peerCount || undefined,
61
+ minRequiredSize: this.cfg.allowClusterDownsize ? undefined : this.cfg.clusterSize
62
+ };
63
+ // Add network size hint if available
64
+ if (this.fretService) {
65
+ try {
66
+ const estimate = this.fretService.getNetworkSizeEstimate();
67
+ if (estimate.size_estimate > 0) {
68
+ record.networkSizeHint = estimate.size_estimate;
69
+ record.networkSizeConfidence = estimate.confidence;
70
+ }
71
+ }
72
+ catch (err) {
73
+ // Ignore errors getting size estimate
74
+ }
75
+ }
76
+ return record;
77
+ }
78
+ /**
79
+ * Initiates a 2-phase transaction for a specific block ID
80
+ */
81
+ async executeClusterTransaction(blockId, message, options) {
82
+ // Get the cluster peers for this block
83
+ const peers = await this.getClusterForBlock(blockId);
84
+ // Create a unique hash for this transaction
85
+ const messageHash = await this.createMessageHash(message);
86
+ // Create a cluster record for this transaction
87
+ const record = this.makeRecord(peers, messageHash, message);
88
+ log('cluster-tx:start', {
89
+ messageHash,
90
+ blockId,
91
+ peerCount: Object.keys(peers ?? {}).length,
92
+ allowDownsize: this.cfg.allowClusterDownsize,
93
+ configuredSize: this.cfg.clusterSize,
94
+ suggestedSize: record.suggestedClusterSize,
95
+ minRequiredSize: record.minRequiredSize
96
+ });
97
+ // Create a new pending transaction
98
+ const transactionPromise = this.executeTransaction(peers, record);
99
+ const pending = new Pending(transactionPromise);
100
+ // Store the transaction state
101
+ const state = {
102
+ messageHash,
103
+ record,
104
+ pending,
105
+ lastUpdate: Date.now()
106
+ };
107
+ this.transactions.set(messageHash, state);
108
+ log('cluster-tx:transaction-store', {
109
+ messageHash,
110
+ transactionKeys: Array.from(this.transactions.keys())
111
+ });
112
+ // Wait for the transaction to complete
113
+ try {
114
+ const result = await pending.result();
115
+ return result;
116
+ }
117
+ finally {
118
+ const stored = this.transactions.get(messageHash);
119
+ const retrySnapshot = stored?.retry ? {
120
+ attempt: stored.retry.attempt,
121
+ pending: Array.from(stored.retry.pendingPeers ?? [])
122
+ } : undefined;
123
+ log('cluster-tx:complete', {
124
+ messageHash,
125
+ finalPromises: stored ? Object.keys(stored.record.promises ?? {}) : undefined,
126
+ finalCommits: stored ? Object.keys(stored.record.commits ?? {}) : undefined,
127
+ retry: retrySnapshot
128
+ });
129
+ // Don't remove transaction immediately if retries are scheduled
130
+ // Let the retry completion or abort handle cleanup
131
+ if (!stored?.retry) {
132
+ // Wait a bit before cleanup to allow any in-flight responses to arrive
133
+ setTimeout(() => {
134
+ this.transactions.delete(messageHash);
135
+ log('cluster-tx:transaction-remove', {
136
+ messageHash,
137
+ remaining: Array.from(this.transactions.keys())
138
+ });
139
+ }, 100);
140
+ }
141
+ }
142
+ }
143
+ /**
144
+ * Executes the full transaction process
145
+ */
146
+ async executeTransaction(peers, record) {
147
+ const peerCount = Object.keys(peers).length;
148
+ // Validate against minimum cluster size
149
+ if (peerCount < this.cfg.minAbsoluteClusterSize) {
150
+ const validated = await this.validateSmallCluster(peerCount, peers);
151
+ if (!validated) {
152
+ log('cluster-tx:reject-too-small', {
153
+ peerCount,
154
+ minRequired: this.cfg.minAbsoluteClusterSize
155
+ });
156
+ throw new Error(`Cluster size ${peerCount} below minimum ${this.cfg.minAbsoluteClusterSize} and not validated`);
157
+ }
158
+ log('cluster-tx:small-cluster-validated', { peerCount });
159
+ }
160
+ // Check configured cluster size
161
+ if (!this.cfg.allowClusterDownsize && peerCount < this.cfg.clusterSize) {
162
+ log('cluster-tx:reject-downsize', { peerCount, required: this.cfg.clusterSize });
163
+ throw new Error(`Cluster size ${peerCount} below configured minimum ${this.cfg.clusterSize}`);
164
+ }
165
+ // Collect promises with super-majority requirement
166
+ const promised = await this.collectPromises(peers, record);
167
+ const superMajority = Math.ceil(peerCount * this.cfg.superMajorityThreshold);
168
+ // Count approvals and rejections separately
169
+ const promises = promised.record.promises;
170
+ const approvalCount = Object.values(promises).filter(sig => sig.type === 'approve').length;
171
+ const rejectionCount = Object.values(promises).filter(sig => sig.type === 'reject').length;
172
+ // Check if rejections make super-majority impossible
173
+ // If more than (peerCount - superMajority) nodes reject, we can never reach super-majority
174
+ const maxAllowedRejections = peerCount - superMajority;
175
+ if (rejectionCount > maxAllowedRejections) {
176
+ const rejectReasons = Object.entries(promises)
177
+ .filter(([_, sig]) => sig.type === 'reject')
178
+ .map(([peerId, sig]) => `${peerId}: ${sig.rejectReason ?? 'unknown'}`)
179
+ .join('; ');
180
+ log('cluster-tx:rejected-by-validators', {
181
+ messageHash: record.messageHash,
182
+ peerCount,
183
+ rejections: rejectionCount,
184
+ maxAllowed: maxAllowedRejections,
185
+ reasons: rejectReasons
186
+ });
187
+ this.updateTransactionRecord(promised.record, 'rejected-by-validators');
188
+ throw new Error(`Transaction rejected by validators (${rejectionCount}/${peerCount} rejected): ${rejectReasons}`);
189
+ }
190
+ if (peerCount > 1 && approvalCount < superMajority) {
191
+ log('cluster-tx:supermajority-failed', {
192
+ messageHash: record.messageHash,
193
+ peerCount,
194
+ approvals: approvalCount,
195
+ rejections: rejectionCount,
196
+ superMajority,
197
+ threshold: this.cfg.superMajorityThreshold
198
+ });
199
+ this.updateTransactionRecord(promised.record, 'supermajority-failed');
200
+ throw new Error(`Failed to get super-majority: ${approvalCount}/${peerCount} approvals (needed ${superMajority}, ${rejectionCount} rejections)`);
201
+ }
202
+ return await this.commitTransaction(promised.record);
203
+ }
204
+ async getClusterSize(blockId) {
205
+ const peers = await this.getClusterForBlock(blockId);
206
+ return Object.keys(peers ?? {}).length;
207
+ }
208
+ /**
209
+ * Validate that a small cluster size is legitimate by querying remote peers
210
+ * for their network size estimates. Returns true if estimates roughly agree.
211
+ */
212
+ async validateSmallCluster(localSize, peers) {
213
+ // If we have FRET and it shows confident estimate
214
+ if (this.fretService) {
215
+ try {
216
+ const estimate = this.fretService.getNetworkSizeEstimate();
217
+ if (estimate.confidence > 0.5) {
218
+ // Check if FRET estimate roughly matches observed cluster size
219
+ const orderOfMagnitude = Math.floor(Math.log10(estimate.size_estimate + 1));
220
+ const localOrderOfMagnitude = Math.floor(Math.log10(localSize + 1));
221
+ // If within same order of magnitude, accept it
222
+ if (Math.abs(orderOfMagnitude - localOrderOfMagnitude) <= 1) {
223
+ log('cluster-tx:small-cluster-validated-by-fret', {
224
+ localSize,
225
+ fretEstimate: estimate.size_estimate,
226
+ confidence: estimate.confidence,
227
+ sources: estimate.sources
228
+ });
229
+ return true;
230
+ }
231
+ }
232
+ }
233
+ catch (err) {
234
+ // Ignore errors
235
+ }
236
+ }
237
+ // Fallback: accept small clusters in development/testing scenarios
238
+ // In production, FRET should provide validation
239
+ log('cluster-tx:small-cluster-accepted-without-validation', {
240
+ localSize,
241
+ reason: 'no-confident-network-size-estimate'
242
+ });
243
+ return true;
244
+ }
245
+ /**
246
+ * Collects promises from all peers in the cluster
247
+ */
248
+ async collectPromises(peers, record) {
249
+ const peerIds = Object.keys(peers);
250
+ const summary = [];
251
+ // For each peer, create a client and request a promise
252
+ const promiseRequests = peerIds.map(peerIdStr => {
253
+ const isLocal = this.localCluster && peerIdStr === this.localCluster.peerId.toString();
254
+ log('cluster-tx:promise-request', { messageHash: record.messageHash, peerId: peerIdStr, isLocal });
255
+ const promise = isLocal
256
+ ? this.localCluster.update(record)
257
+ : this.createClusterClient(peerIdFromString(peerIdStr)).update(record);
258
+ return new Pending(promise);
259
+ });
260
+ // Wait for all promises to complete
261
+ const results = await Promise.all(promiseRequests.map((p, idx) => p.result().then(res => {
262
+ const peerIdStr = peerIds[idx];
263
+ log('cluster-tx:promise-response', {
264
+ messageHash: record.messageHash,
265
+ peerId: peerIdStr,
266
+ success: true,
267
+ returnedPromises: Object.keys(res.promises ?? {}),
268
+ returnedCommits: Object.keys(res.commits ?? {})
269
+ });
270
+ summary.push({ peerId: peerIdStr, success: true });
271
+ return res;
272
+ }).catch(err => {
273
+ const peerIdStr = peerIds[idx];
274
+ log('cluster-tx:promise-response', { messageHash: record.messageHash, peerId: peerIdStr, success: false, error: err });
275
+ summary.push({ peerId: peerIdStr, success: false, error: err instanceof Error ? err.message : String(err) });
276
+ return null;
277
+ })));
278
+ const successes = summary.filter(entry => entry.success).map(entry => entry.peerId);
279
+ const failures = summary.filter(entry => !entry.success);
280
+ log('cluster-tx:promise-summary', {
281
+ messageHash: record.messageHash,
282
+ successes,
283
+ failures
284
+ });
285
+ log('cluster-tx:promise-merge-begin', {
286
+ messageHash: record.messageHash,
287
+ initialPromises: Object.keys(record.promises ?? {}),
288
+ transactionsKeys: Array.from(this.transactions.keys()),
289
+ hasTransaction: this.transactions.has(record.messageHash)
290
+ });
291
+ // Merge all promises into the record
292
+ for (const result of results.filter(Boolean)) {
293
+ log('cluster-tx:promise-merge-input', {
294
+ messageHash: record.messageHash,
295
+ resultFrom: Object.keys(result.promises ?? {}),
296
+ recordBefore: Object.keys(record.promises ?? {})
297
+ });
298
+ const resultPromises = Object.keys(result.promises ?? {});
299
+ log('cluster-tx:promise-merge-result', {
300
+ messageHash: record.messageHash,
301
+ peerPromises: resultPromises
302
+ });
303
+ if (typeof record.suggestedClusterSize === 'number' && typeof result.suggestedClusterSize === 'number') {
304
+ const expected = result.suggestedClusterSize;
305
+ const actual = Object.keys(peers).length;
306
+ const maxDiff = Math.ceil(Math.max(1, expected * this.cfg.clusterSizeTolerance));
307
+ if (Math.abs(actual - expected) > maxDiff) {
308
+ log('cluster-tx:size-variance', { expected, actual, tolerance: this.cfg.clusterSizeTolerance });
309
+ }
310
+ }
311
+ record.promises = { ...record.promises, ...result.promises };
312
+ log('cluster-tx:promise-merge-after', {
313
+ messageHash: record.messageHash,
314
+ mergedPromises: Object.keys(record.promises ?? {})
315
+ });
316
+ }
317
+ log('cluster-tx:promise-merge', {
318
+ messageHash: record.messageHash,
319
+ mergedPromises: Object.keys(record.promises ?? {})
320
+ });
321
+ log('cluster-tx:promise-merge-end', {
322
+ messageHash: record.messageHash,
323
+ finalPromises: Object.keys(record.promises ?? {}),
324
+ transactionsEntry: this.transactions.get(record.messageHash)
325
+ });
326
+ this.updateTransactionRecord(record, 'after-promises');
327
+ return { record };
328
+ }
329
+ /**
330
+ * Commits the transaction to all peers in the cluster
331
+ */
332
+ async commitTransaction(record) {
333
+ // For each peer, create a client and send the commit
334
+ const peerIds = Object.keys(record.peers);
335
+ const summary = [];
336
+ // Send the record with promises to all peers
337
+ // Each peer will add its own commit signature
338
+ const commitPayload = {
339
+ ...record
340
+ };
341
+ const commitRequests = peerIds.map(peerIdStr => {
342
+ const isLocal = this.localCluster && peerIdStr === this.localCluster.peerId.toString();
343
+ log('cluster-tx:commit-request', { messageHash: record.messageHash, peerId: peerIdStr, isLocal });
344
+ const promise = isLocal
345
+ ? this.localCluster.update(commitPayload)
346
+ : this.createClusterClient(peerIdFromString(peerIdStr)).update(commitPayload);
347
+ return new Pending(promise);
348
+ });
349
+ // Wait for all commits to complete
350
+ const results = await Promise.all(commitRequests.map((p, idx) => p.result().then(res => {
351
+ const peerIdStr = peerIds[idx];
352
+ log('cluster-tx:commit-response', { messageHash: record.messageHash, peerId: peerIdStr, success: true });
353
+ summary.push({ peerId: peerIdStr, success: true });
354
+ return res;
355
+ }).catch(err => {
356
+ const peerIdStr = peerIds[idx];
357
+ log('cluster-tx:commit-response', { messageHash: record.messageHash, peerId: peerIdStr, success: false, error: err });
358
+ summary.push({ peerId: peerIdStr, success: false, error: err instanceof Error ? err.message : String(err) });
359
+ return null;
360
+ })));
361
+ const commitSuccesses = summary.filter(entry => entry.success).map(entry => entry.peerId);
362
+ const commitFailures = summary.filter(entry => !entry.success);
363
+ log('cluster-tx:commit-summary', {
364
+ messageHash: record.messageHash,
365
+ successes: commitSuccesses,
366
+ failures: commitFailures
367
+ });
368
+ log('cluster-tx:commit-merge-begin', {
369
+ messageHash: record.messageHash,
370
+ initialCommits: Object.keys(record.commits ?? {}),
371
+ transactionsEntry: this.transactions.get(record.messageHash)
372
+ });
373
+ // Merge all commits into the record
374
+ for (const result of results.filter(Boolean)) {
375
+ log('cluster-tx:commit-merge-input', {
376
+ messageHash: record.messageHash,
377
+ resultFrom: Object.keys(result.commits ?? {}),
378
+ recordBefore: Object.keys(record.commits ?? {})
379
+ });
380
+ log('cluster-tx:commit-merge-result', {
381
+ messageHash: record.messageHash,
382
+ peerCommits: Object.keys(result.commits ?? {})
383
+ });
384
+ record.commits = { ...record.commits, ...result.commits };
385
+ log('cluster-tx:commit-merge-after', {
386
+ messageHash: record.messageHash,
387
+ mergedCommits: Object.keys(record.commits ?? {})
388
+ });
389
+ }
390
+ log('cluster-tx:commit-merge', {
391
+ messageHash: record.messageHash,
392
+ mergedCommits: Object.keys(record.commits ?? {})
393
+ });
394
+ log('cluster-tx:commit-merge-end', {
395
+ messageHash: record.messageHash,
396
+ finalCommits: Object.keys(record.commits ?? {}),
397
+ transactionsEntry: this.transactions.get(record.messageHash)
398
+ });
399
+ this.updateTransactionRecord(record, 'after-commit');
400
+ // Check for simple majority (>50%) - this proves commitment
401
+ const peerCount = Object.keys(record.peers).length;
402
+ const simpleMajority = Math.floor(peerCount * this.cfg.simpleMajorityThreshold) + 1;
403
+ const commitCount = Object.keys(record.commits).length;
404
+ if (commitCount >= simpleMajority) {
405
+ log('cluster-tx:commit-majority-reached', {
406
+ messageHash: record.messageHash,
407
+ commitCount,
408
+ simpleMajority,
409
+ peerCount,
410
+ threshold: this.cfg.simpleMajorityThreshold
411
+ });
412
+ // Simple majority proves commitment - we can return success
413
+ // Background propagation to remaining peers will continue
414
+ }
415
+ const missingPeers = commitFailures.map(entry => entry.peerId);
416
+ if (missingPeers.length > 0) {
417
+ this.scheduleCommitRetry(record.messageHash, record, missingPeers);
418
+ }
419
+ else {
420
+ this.clearRetry(record.messageHash);
421
+ }
422
+ return record;
423
+ }
424
+ updateTransactionRecord(record, stage) {
425
+ const state = this.transactions.get(record.messageHash);
426
+ if (!state) {
427
+ log('cluster-tx:transaction-update-miss', { messageHash: record.messageHash, stage });
428
+ return;
429
+ }
430
+ state.record = { ...record };
431
+ state.lastUpdate = Date.now();
432
+ log('cluster-tx:transaction-update', {
433
+ messageHash: record.messageHash,
434
+ stage,
435
+ promises: Object.keys(record.promises ?? {}),
436
+ commits: Object.keys(record.commits ?? {})
437
+ });
438
+ }
439
+ scheduleCommitRetry(messageHash, record, missingPeers) {
440
+ const state = this.transactions.get(messageHash);
441
+ if (!state) {
442
+ return;
443
+ }
444
+ const existing = state.retry;
445
+ const nextAttempt = (existing?.attempt ?? 0) + 1;
446
+ if (nextAttempt > this.retryMaxAttempts) {
447
+ log('cluster-tx:retry-abort', { messageHash, missingPeers });
448
+ return;
449
+ }
450
+ if (missingPeers.length === 0) {
451
+ this.clearRetry(messageHash);
452
+ return;
453
+ }
454
+ const pendingPeers = new Set(missingPeers);
455
+ const baseInterval = existing ? Math.min(existing.intervalMs * this.retryBackoffFactor, this.retryMaxIntervalMs) : this.retryInitialIntervalMs;
456
+ if (existing?.timer) {
457
+ clearTimeout(existing.timer);
458
+ }
459
+ const timer = setTimeout(() => {
460
+ void this.retryCommits(messageHash);
461
+ }, baseInterval);
462
+ state.retry = {
463
+ pendingPeers,
464
+ attempt: nextAttempt,
465
+ intervalMs: baseInterval,
466
+ timer
467
+ };
468
+ log('cluster-tx:retry-scheduled', { messageHash, attempt: nextAttempt, missingPeers, delayMs: baseInterval });
469
+ }
470
+ async retryCommits(messageHash) {
471
+ const state = this.transactions.get(messageHash);
472
+ if (!state?.retry) {
473
+ return;
474
+ }
475
+ const { pendingPeers, attempt } = state.retry;
476
+ if (pendingPeers.size === 0) {
477
+ this.clearRetry(messageHash);
478
+ return;
479
+ }
480
+ const peerIds = Array.from(pendingPeers);
481
+ const record = state.record;
482
+ log('cluster-tx:retry-start', { messageHash, attempt, peerIds });
483
+ const results = await Promise.all(peerIds.map(async (peerIdStr) => {
484
+ const isLocal = this.localCluster && peerIdStr === this.localCluster.peerId.toString();
485
+ const payload = {
486
+ ...record,
487
+ commits: record.commits
488
+ };
489
+ try {
490
+ const res = isLocal
491
+ ? await this.localCluster.update(payload)
492
+ : await this.createClusterClient(peerIdFromString(peerIdStr)).update(payload);
493
+ state.record.commits = { ...state.record.commits, ...res.commits };
494
+ return { peerId: peerIdStr, success: true };
495
+ }
496
+ catch (err) {
497
+ return {
498
+ peerId: peerIdStr,
499
+ success: false,
500
+ error: err instanceof Error ? err.message : String(err)
501
+ };
502
+ }
503
+ }));
504
+ const successes = results.filter(r => r.success).map(r => r.peerId);
505
+ const failures = results.filter(r => !r.success);
506
+ for (const peerId of successes) {
507
+ pendingPeers.delete(peerId);
508
+ }
509
+ log('cluster-tx:retry-complete', { messageHash, attempt, successes, failures });
510
+ if (pendingPeers.size === 0) {
511
+ log('cluster-tx:retry-finished', { messageHash });
512
+ this.clearRetry(messageHash);
513
+ return;
514
+ }
515
+ if (!this.transactions.has(messageHash)) {
516
+ return;
517
+ }
518
+ this.scheduleCommitRetry(messageHash, state.record, Array.from(pendingPeers));
519
+ }
520
+ clearRetry(messageHash) {
521
+ const state = this.transactions.get(messageHash);
522
+ if (!state?.retry) {
523
+ return;
524
+ }
525
+ if (state.retry.timer) {
526
+ clearTimeout(state.retry.timer);
527
+ }
528
+ state.retry = undefined;
529
+ // Clean up the transaction after retry is complete
530
+ setTimeout(() => {
531
+ this.transactions.delete(messageHash);
532
+ log('cluster-tx:transaction-remove', {
533
+ messageHash,
534
+ remaining: Array.from(this.transactions.keys())
535
+ });
536
+ }, 100);
537
+ }
538
+ }
539
+ //# sourceMappingURL=cluster-coordinator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cluster-coordinator.js","sourceRoot":"","sources":["../../../src/repo/cluster-coordinator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAEnD,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAElD,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAE9C,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAI3C,MAAM,GAAG,GAAG,YAAY,CAAC,SAAS,CAAC,CAAA;AAsBnC,uDAAuD;AACvD,MAAM,OAAO,kBAAkB;IASZ;IACA;IACA;IACA;IACA;IAZlB,+FAA+F;IACvF,YAAY,GAAyC,IAAI,GAAG,EAAE,CAAC;IACtD,sBAAsB,GAAG,IAAI,CAAC;IAC9B,kBAAkB,GAAG,CAAC,CAAC;IACvB,kBAAkB,GAAG,KAAK,CAAC;IAC3B,gBAAgB,GAAG,CAAC,CAAC;IAEtC,YACkB,UAAuB,EACvB,mBAAsD,EACtD,GAAqD,EACrD,YAA4F,EAC5F,WAAyB;QAJzB,eAAU,GAAV,UAAU,CAAa;QACvB,wBAAmB,GAAnB,mBAAmB,CAAmC;QACtD,QAAG,GAAH,GAAG,CAAkD;QACrD,iBAAY,GAAZ,YAAY,CAAgF;QAC5F,gBAAW,GAAX,WAAW,CAAc;IACvC,CAAC;IAEL;;OAEG;IACK,KAAK,CAAC,iBAAiB,CAAC,OAAoB;QACnD,MAAM,QAAQ,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;QACnE,MAAM,SAAS,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