@sip-protocol/sdk 0.7.3 → 0.7.4
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/LICENSE +21 -0
- package/README.md +267 -0
- package/dist/{TransportWebUSB-TQ7WZ4LE.mjs → TransportWebUSB-YQMAGJAJ.mjs} +12 -9
- package/dist/browser.d.mts +10 -4
- package/dist/browser.d.ts +10 -4
- package/dist/browser.js +47556 -19603
- package/dist/browser.mjs +628 -48
- package/dist/chunk-4GRJ5MAW.mjs +152 -0
- package/dist/chunk-5D7A3L3W.mjs +717 -0
- package/dist/chunk-64AYA5F5.mjs +7834 -0
- package/dist/chunk-GMDGB22A.mjs +379 -0
- package/dist/chunk-I534WKN7.mjs +328 -0
- package/dist/chunk-IBZVA5Y7.mjs +1003 -0
- package/dist/chunk-PRRZAWJE.mjs +223 -0
- package/dist/{chunk-UJCSKKID.mjs → chunk-XGB3TDIC.mjs} +13 -1
- package/dist/{chunk-3M3HNQCW.mjs → chunk-YWGJ77A2.mjs} +28656 -13103
- package/dist/{chunk-6WGN57S2.mjs → chunk-Z3K7W5S3.mjs} +48 -0
- package/dist/constants-LHAAUC2T.mjs +51 -0
- package/dist/dist-2OGQ7FED.mjs +3957 -0
- package/dist/dist-IFHPYLDX.mjs +254 -0
- package/dist/fulfillment_proof-ANHVPKTB.mjs +21 -0
- package/dist/funding_proof-ICFZ5LHY.mjs +21 -0
- package/dist/{index-DIBZHOOQ.d.ts → index-DXh2IGkz.d.ts} +21239 -10304
- package/dist/{index-8MQz13eJ.d.mts → index-DeE1ZzA4.d.mts} +21239 -10304
- package/dist/index.d.mts +9 -3
- package/dist/index.d.ts +9 -3
- package/dist/index.js +48396 -19623
- package/dist/index.mjs +537 -19
- package/dist/interface-Bf7w1PLW.d.mts +679 -0
- package/dist/interface-Bf7w1PLW.d.ts +679 -0
- package/dist/{noir-DKfEzWy9.d.mts → noir-kzbLVTei.d.mts} +31 -21
- package/dist/{noir-DKfEzWy9.d.ts → noir-kzbLVTei.d.ts} +31 -21
- package/dist/proofs/halo2.d.mts +151 -0
- package/dist/proofs/halo2.d.ts +151 -0
- package/dist/proofs/halo2.js +350 -0
- package/dist/proofs/halo2.mjs +11 -0
- package/dist/proofs/kimchi.d.mts +160 -0
- package/dist/proofs/kimchi.d.ts +160 -0
- package/dist/proofs/kimchi.js +431 -0
- package/dist/proofs/kimchi.mjs +13 -0
- package/dist/proofs/noir.d.mts +1 -1
- package/dist/proofs/noir.d.ts +1 -1
- package/dist/proofs/noir.js +74 -18
- package/dist/proofs/noir.mjs +84 -24
- package/dist/solana-U3MEGU7W.mjs +280 -0
- package/dist/validity_proof-3POXLPNY.mjs +21 -0
- package/package.json +54 -21
- package/src/adapters/index.ts +41 -0
- package/src/adapters/jupiter.ts +571 -0
- package/src/adapters/near-intents.ts +135 -0
- package/src/advisor/advisor.ts +653 -0
- package/src/advisor/index.ts +54 -0
- package/src/advisor/tools.ts +303 -0
- package/src/advisor/types.ts +164 -0
- package/src/chains/ethereum/announcement.ts +536 -0
- package/src/chains/ethereum/bnb-optimizations.ts +474 -0
- package/src/chains/ethereum/commitment.ts +522 -0
- package/src/chains/ethereum/constants.ts +462 -0
- package/src/chains/ethereum/deployment.ts +596 -0
- package/src/chains/ethereum/gas-estimation.ts +538 -0
- package/src/chains/ethereum/index.ts +268 -0
- package/src/chains/ethereum/optimizations.ts +614 -0
- package/src/chains/ethereum/privacy-adapter.ts +855 -0
- package/src/chains/ethereum/registry.ts +584 -0
- package/src/chains/ethereum/rpc.ts +905 -0
- package/src/chains/ethereum/stealth.ts +491 -0
- package/src/chains/ethereum/token.ts +790 -0
- package/src/chains/ethereum/transfer.ts +637 -0
- package/src/chains/ethereum/types.ts +456 -0
- package/src/chains/ethereum/viewing-key.ts +455 -0
- package/src/chains/near/commitment.ts +608 -0
- package/src/chains/near/constants.ts +284 -0
- package/src/chains/near/function-call.ts +871 -0
- package/src/chains/near/history.ts +654 -0
- package/src/chains/near/implicit-account.ts +840 -0
- package/src/chains/near/index.ts +393 -0
- package/src/chains/near/native-transfer.ts +658 -0
- package/src/chains/near/nep141.ts +775 -0
- package/src/chains/near/privacy-adapter.ts +889 -0
- package/src/chains/near/resolver.ts +971 -0
- package/src/chains/near/rpc.ts +1016 -0
- package/src/chains/near/stealth.ts +419 -0
- package/src/chains/near/types.ts +317 -0
- package/src/chains/near/viewing-key.ts +876 -0
- package/src/chains/solana/anchor-transfer.ts +386 -0
- package/src/chains/solana/commitment.ts +577 -0
- package/src/chains/solana/constants.ts +126 -12
- package/src/chains/solana/ephemeral-keys.ts +543 -0
- package/src/chains/solana/index.ts +252 -1
- package/src/chains/solana/key-derivation.ts +418 -0
- package/src/chains/solana/kit-compat.ts +334 -0
- package/src/chains/solana/optimizations.ts +560 -0
- package/src/chains/solana/privacy-adapter.ts +605 -0
- package/src/chains/solana/providers/generic.ts +47 -6
- package/src/chains/solana/providers/helius-enhanced-types.ts +336 -0
- package/src/chains/solana/providers/helius-enhanced.ts +623 -0
- package/src/chains/solana/providers/helius.ts +186 -33
- package/src/chains/solana/providers/index.ts +31 -0
- package/src/chains/solana/providers/interface.ts +61 -18
- package/src/chains/solana/providers/quicknode.ts +409 -0
- package/src/chains/solana/providers/triton.ts +426 -0
- package/src/chains/solana/providers/webhook.ts +338 -67
- package/src/chains/solana/rpc-client.ts +1150 -0
- package/src/chains/solana/scan.ts +83 -66
- package/src/chains/solana/sol-transfer.ts +732 -0
- package/src/chains/solana/spl-transfer.ts +886 -0
- package/src/chains/solana/stealth-scanner.ts +703 -0
- package/src/chains/solana/sunspot-verifier.ts +453 -0
- package/src/chains/solana/transaction-builder.ts +755 -0
- package/src/chains/solana/transfer.ts +74 -5
- package/src/chains/solana/types.ts +57 -6
- package/src/chains/solana/utils.ts +110 -0
- package/src/chains/solana/viewing-key.ts +807 -0
- package/src/compliance/fireblocks.ts +921 -0
- package/src/compliance/index.ts +23 -0
- package/src/compliance/range-sas.ts +398 -33
- package/src/config/endpoints.ts +100 -0
- package/src/crypto.ts +11 -8
- package/src/errors.ts +82 -0
- package/src/evm/erc4337-relayer.ts +830 -0
- package/src/evm/index.ts +47 -0
- package/src/fees/calculator.ts +396 -0
- package/src/fees/index.ts +87 -0
- package/src/fees/near-contract.ts +429 -0
- package/src/fees/types.ts +268 -0
- package/src/index.ts +686 -1
- package/src/intent.ts +6 -3
- package/src/logger.ts +324 -0
- package/src/network/index.ts +80 -0
- package/src/network/proxy.ts +691 -0
- package/src/optimizations/index.ts +541 -0
- package/src/oracle/types.ts +1 -0
- package/src/privacy-backends/arcium-types.ts +727 -0
- package/src/privacy-backends/arcium.ts +719 -0
- package/src/privacy-backends/combined-privacy.ts +866 -0
- package/src/privacy-backends/cspl-token.ts +595 -0
- package/src/privacy-backends/cspl-types.ts +512 -0
- package/src/privacy-backends/cspl.ts +907 -0
- package/src/privacy-backends/health.ts +488 -0
- package/src/privacy-backends/inco-types.ts +323 -0
- package/src/privacy-backends/inco.ts +616 -0
- package/src/privacy-backends/index.ts +254 -4
- package/src/privacy-backends/interface.ts +649 -6
- package/src/privacy-backends/lru-cache.ts +343 -0
- package/src/privacy-backends/magicblock.ts +458 -0
- package/src/privacy-backends/mock.ts +258 -0
- package/src/privacy-backends/privacycash.ts +13 -17
- package/src/privacy-backends/private-swap.ts +570 -0
- package/src/privacy-backends/rate-limiter.ts +683 -0
- package/src/privacy-backends/registry.ts +414 -2
- package/src/privacy-backends/router.ts +283 -3
- package/src/privacy-backends/shadowwire.ts +449 -0
- package/src/privacy-backends/sip-native.ts +3 -0
- package/src/privacy-logger.ts +191 -0
- package/src/production-safety.ts +373 -0
- package/src/proofs/aggregator.ts +1029 -0
- package/src/proofs/browser-composer.ts +1150 -0
- package/src/proofs/browser.ts +113 -25
- package/src/proofs/cache/index.ts +127 -0
- package/src/proofs/cache/interface.ts +545 -0
- package/src/proofs/cache/key-generator.ts +188 -0
- package/src/proofs/cache/lru-cache.ts +481 -0
- package/src/proofs/cache/multi-tier-cache.ts +575 -0
- package/src/proofs/cache/persistent-cache.ts +788 -0
- package/src/proofs/compliance-proof.ts +872 -0
- package/src/proofs/composer/base.ts +923 -0
- package/src/proofs/composer/index.ts +25 -0
- package/src/proofs/composer/interface.ts +518 -0
- package/src/proofs/composer/types.ts +383 -0
- package/src/proofs/converters/halo2.ts +452 -0
- package/src/proofs/converters/index.ts +208 -0
- package/src/proofs/converters/interface.ts +363 -0
- package/src/proofs/converters/kimchi.ts +462 -0
- package/src/proofs/converters/noir.ts +451 -0
- package/src/proofs/fallback.ts +888 -0
- package/src/proofs/halo2.ts +42 -0
- package/src/proofs/index.ts +471 -0
- package/src/proofs/interface.ts +13 -0
- package/src/proofs/kimchi.ts +42 -0
- package/src/proofs/lazy.ts +1004 -0
- package/src/proofs/mock.ts +25 -1
- package/src/proofs/noir.ts +110 -29
- package/src/proofs/orchestrator.ts +960 -0
- package/src/proofs/parallel/concurrency.ts +297 -0
- package/src/proofs/parallel/dependency-graph.ts +602 -0
- package/src/proofs/parallel/executor.ts +420 -0
- package/src/proofs/parallel/index.ts +131 -0
- package/src/proofs/parallel/interface.ts +685 -0
- package/src/proofs/parallel/worker-pool.ts +644 -0
- package/src/proofs/providers/halo2.ts +560 -0
- package/src/proofs/providers/index.ts +34 -0
- package/src/proofs/providers/kimchi.ts +641 -0
- package/src/proofs/validator.ts +881 -0
- package/src/proofs/verifier.ts +867 -0
- package/src/quantum/index.ts +112 -0
- package/src/quantum/winternitz-vault.ts +639 -0
- package/src/quantum/wots.ts +611 -0
- package/src/settlement/backends/direct-chain.ts +1 -0
- package/src/settlement/index.ts +9 -0
- package/src/settlement/router.ts +732 -46
- package/src/solana/index.ts +72 -0
- package/src/solana/jito-relayer.ts +687 -0
- package/src/solana/noir-verifier-types.ts +430 -0
- package/src/solana/noir-verifier.ts +816 -0
- package/src/stealth/address-derivation.ts +193 -0
- package/src/stealth/ed25519.ts +431 -0
- package/src/stealth/index.ts +233 -0
- package/src/stealth/meta-address.ts +221 -0
- package/src/stealth/secp256k1.ts +368 -0
- package/src/stealth/utils.ts +194 -0
- package/src/stealth.ts +50 -1504
- package/src/sync/index.ts +106 -0
- package/src/sync/manager.ts +504 -0
- package/src/sync/mock-provider.ts +318 -0
- package/src/sync/oblivious.ts +625 -0
- package/src/tokens/index.ts +15 -0
- package/src/tokens/registry.ts +301 -0
- package/src/utils/deprecation.ts +94 -0
- package/src/utils/index.ts +9 -0
- package/src/wallet/ethereum/index.ts +68 -0
- package/src/wallet/ethereum/metamask-privacy.ts +420 -0
- package/src/wallet/ethereum/multi-wallet.ts +646 -0
- package/src/wallet/ethereum/privacy-adapter.ts +700 -0
- package/src/wallet/ethereum/types.ts +3 -1
- package/src/wallet/ethereum/walletconnect-adapter.ts +675 -0
- package/src/wallet/hardware/index.ts +10 -0
- package/src/wallet/hardware/ledger-privacy.ts +414 -0
- package/src/wallet/index.ts +71 -0
- package/src/wallet/near/adapter.ts +626 -0
- package/src/wallet/near/index.ts +86 -0
- package/src/wallet/near/meteor-wallet.ts +1153 -0
- package/src/wallet/near/my-near-wallet.ts +790 -0
- package/src/wallet/near/wallet-selector.ts +702 -0
- package/src/wallet/solana/adapter.ts +6 -4
- package/src/wallet/solana/index.ts +13 -0
- package/src/wallet/solana/privacy-adapter.ts +567 -0
- package/src/wallet/sui/types.ts +6 -4
- package/src/zcash/rpc-client.ts +13 -6
- package/dist/chunk-2XIVXWHA.mjs +0 -1930
- package/dist/chunk-3INS3PR5.mjs +0 -884
- package/dist/chunk-3OVABDRH.mjs +0 -17096
- package/dist/chunk-7RFRWDCW.mjs +0 -1504
- package/dist/chunk-DLDWZFYC.mjs +0 -1495
- package/dist/chunk-E6SZWREQ.mjs +0 -57
- package/dist/chunk-F6F73W35.mjs +0 -16166
- package/dist/chunk-G33LB27A.mjs +0 -16166
- package/dist/chunk-HGU6HZRC.mjs +0 -231
- package/dist/chunk-L2K34JCU.mjs +0 -1496
- package/dist/chunk-OFDBEIEK.mjs +0 -16166
- package/dist/chunk-SF7YSLF5.mjs +0 -1515
- package/dist/chunk-SN4ZDTVW.mjs +0 -16166
- package/dist/chunk-WWUSGOXE.mjs +0 -17129
- package/dist/constants-VOI7BSLK.mjs +0 -27
- package/dist/index-B71aXVzk.d.ts +0 -13264
- package/dist/index-BYZbDjal.d.ts +0 -11390
- package/dist/index-CHB3KuOB.d.mts +0 -11859
- package/dist/index-CzWPI6Le.d.ts +0 -11859
- package/dist/index-pOIIuwfV.d.mts +0 -13264
- package/dist/index-xbWjohNq.d.mts +0 -11390
- package/dist/solana-4O4K45VU.mjs +0 -46
- package/dist/solana-5EMCTPTS.mjs +0 -46
- package/dist/solana-NDABAZ6P.mjs +0 -56
- package/dist/solana-Q4NAVBTS.mjs +0 -46
- package/dist/solana-ZYO63LY5.mjs +0 -46
|
@@ -0,0 +1,685 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parallel Proof Generation - Interface Definitions
|
|
3
|
+
*
|
|
4
|
+
* @module proofs/parallel
|
|
5
|
+
* @description Types and interfaces for optimized parallel proof generation
|
|
6
|
+
*
|
|
7
|
+
* M20-12: Optimize proof generation parallelization (#307)
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { ProofSystem, SingleProof } from '@sip-protocol/types'
|
|
11
|
+
|
|
12
|
+
// ─── Dependency Graph Types ──────────────────────────────────────────────────
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Node in the proof dependency graph
|
|
16
|
+
*/
|
|
17
|
+
export interface DependencyNode {
|
|
18
|
+
/** Unique identifier for this proof task */
|
|
19
|
+
readonly id: string
|
|
20
|
+
/** Circuit ID to execute */
|
|
21
|
+
readonly circuitId: string
|
|
22
|
+
/** Proof system to use */
|
|
23
|
+
readonly system: ProofSystem
|
|
24
|
+
/** IDs of proofs this depends on (must complete first) */
|
|
25
|
+
readonly dependencies: readonly string[]
|
|
26
|
+
/** Estimated computation cost (relative units) */
|
|
27
|
+
readonly estimatedCost: number
|
|
28
|
+
/** Estimated memory requirements in bytes */
|
|
29
|
+
readonly estimatedMemory: number
|
|
30
|
+
/** Private inputs for proof generation */
|
|
31
|
+
readonly privateInputs: Record<string, unknown>
|
|
32
|
+
/** Public inputs for proof generation */
|
|
33
|
+
readonly publicInputs: Record<string, unknown>
|
|
34
|
+
/** Optional priority (higher = scheduled first among peers) */
|
|
35
|
+
readonly priority?: number
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Edge in the dependency graph
|
|
40
|
+
*/
|
|
41
|
+
export interface DependencyEdge {
|
|
42
|
+
/** Source node ID (dependency) */
|
|
43
|
+
readonly from: string
|
|
44
|
+
/** Target node ID (depends on source) */
|
|
45
|
+
readonly to: string
|
|
46
|
+
/** How the dependency output is used */
|
|
47
|
+
readonly connectionType: 'proof' | 'commitment' | 'witness'
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Complete dependency graph for parallel execution
|
|
52
|
+
*/
|
|
53
|
+
export interface DependencyGraph {
|
|
54
|
+
/** All proof nodes */
|
|
55
|
+
readonly nodes: Map<string, DependencyNode>
|
|
56
|
+
/** All edges between nodes */
|
|
57
|
+
readonly edges: DependencyEdge[]
|
|
58
|
+
/** Root nodes (no dependencies) */
|
|
59
|
+
readonly roots: readonly string[]
|
|
60
|
+
/** Leaf nodes (no dependents) */
|
|
61
|
+
readonly leaves: readonly string[]
|
|
62
|
+
/** Maximum depth of the graph */
|
|
63
|
+
readonly maxDepth: number
|
|
64
|
+
/** Total estimated computation cost */
|
|
65
|
+
readonly totalCost: number
|
|
66
|
+
/** Critical path (longest chain) node IDs */
|
|
67
|
+
readonly criticalPath: readonly string[]
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Analysis result from dependency graph
|
|
72
|
+
*/
|
|
73
|
+
export interface GraphAnalysis {
|
|
74
|
+
/** The constructed graph */
|
|
75
|
+
readonly graph: DependencyGraph
|
|
76
|
+
/** Suggested parallelism level */
|
|
77
|
+
readonly suggestedParallelism: number
|
|
78
|
+
/** Execution levels (nodes that can run in parallel) */
|
|
79
|
+
readonly executionLevels: readonly string[][]
|
|
80
|
+
/** Whether graph has cycles (invalid) */
|
|
81
|
+
readonly hasCycles: boolean
|
|
82
|
+
/** Cycle path if cycles detected */
|
|
83
|
+
readonly cyclePath?: readonly string[]
|
|
84
|
+
/** Bottleneck nodes (high cost on critical path) */
|
|
85
|
+
readonly bottlenecks: readonly string[]
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// ─── Worker Pool Types ───────────────────────────────────────────────────────
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Worker status
|
|
92
|
+
*/
|
|
93
|
+
export type WorkerStatus = 'idle' | 'busy' | 'terminating' | 'terminated' | 'error'
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Worker information
|
|
97
|
+
*/
|
|
98
|
+
export interface WorkerInfo {
|
|
99
|
+
/** Worker ID */
|
|
100
|
+
readonly id: string
|
|
101
|
+
/** Current status */
|
|
102
|
+
readonly status: WorkerStatus
|
|
103
|
+
/** Task currently being executed (if any) */
|
|
104
|
+
readonly currentTask?: string
|
|
105
|
+
/** Number of tasks completed */
|
|
106
|
+
readonly tasksCompleted: number
|
|
107
|
+
/** Total execution time in ms */
|
|
108
|
+
readonly totalExecutionTime: number
|
|
109
|
+
/** Average task time in ms */
|
|
110
|
+
readonly averageTaskTime: number
|
|
111
|
+
/** Memory usage estimate in bytes */
|
|
112
|
+
readonly memoryUsage: number
|
|
113
|
+
/** When the worker was created */
|
|
114
|
+
readonly createdAt: number
|
|
115
|
+
/** Last activity timestamp */
|
|
116
|
+
readonly lastActiveAt: number
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Worker pool configuration
|
|
121
|
+
*/
|
|
122
|
+
export interface WorkerPoolConfig {
|
|
123
|
+
/** Minimum number of workers to maintain */
|
|
124
|
+
readonly minWorkers: number
|
|
125
|
+
/** Maximum number of workers */
|
|
126
|
+
readonly maxWorkers: number
|
|
127
|
+
/** Worker idle timeout in ms before termination */
|
|
128
|
+
readonly idleTimeoutMs: number
|
|
129
|
+
/** Maximum memory per worker in bytes */
|
|
130
|
+
readonly maxMemoryPerWorker: number
|
|
131
|
+
/** Enable work stealing between workers */
|
|
132
|
+
readonly enableWorkStealing: boolean
|
|
133
|
+
/** Work stealing interval in ms */
|
|
134
|
+
readonly workStealingIntervalMs: number
|
|
135
|
+
/** Task queue high water mark */
|
|
136
|
+
readonly taskQueueHighWaterMark: number
|
|
137
|
+
/** Use Web Workers in browser (if available) */
|
|
138
|
+
readonly useWebWorkers: boolean
|
|
139
|
+
/** Worker script URL for Web Workers */
|
|
140
|
+
readonly workerScriptUrl?: string
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Default worker pool configuration
|
|
145
|
+
*/
|
|
146
|
+
export const DEFAULT_WORKER_POOL_CONFIG: WorkerPoolConfig = {
|
|
147
|
+
minWorkers: 1,
|
|
148
|
+
maxWorkers: 4,
|
|
149
|
+
idleTimeoutMs: 30000,
|
|
150
|
+
maxMemoryPerWorker: 512 * 1024 * 1024, // 512MB
|
|
151
|
+
enableWorkStealing: true,
|
|
152
|
+
workStealingIntervalMs: 100,
|
|
153
|
+
taskQueueHighWaterMark: 100,
|
|
154
|
+
useWebWorkers: true,
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Worker pool statistics
|
|
159
|
+
*/
|
|
160
|
+
export interface WorkerPoolStats {
|
|
161
|
+
/** Current number of workers */
|
|
162
|
+
readonly workerCount: number
|
|
163
|
+
/** Number of busy workers */
|
|
164
|
+
readonly busyWorkers: number
|
|
165
|
+
/** Number of idle workers */
|
|
166
|
+
readonly idleWorkers: number
|
|
167
|
+
/** Tasks in queue */
|
|
168
|
+
readonly queuedTasks: number
|
|
169
|
+
/** Tasks completed */
|
|
170
|
+
readonly completedTasks: number
|
|
171
|
+
/** Tasks failed */
|
|
172
|
+
readonly failedTasks: number
|
|
173
|
+
/** Total tasks submitted */
|
|
174
|
+
readonly totalTasks: number
|
|
175
|
+
/** Average task execution time in ms */
|
|
176
|
+
readonly averageTaskTime: number
|
|
177
|
+
/** Work steals performed */
|
|
178
|
+
readonly workSteals: number
|
|
179
|
+
/** Current memory usage estimate in bytes */
|
|
180
|
+
readonly memoryUsage: number
|
|
181
|
+
/** Peak memory usage in bytes */
|
|
182
|
+
readonly peakMemoryUsage: number
|
|
183
|
+
/** Pool uptime in ms */
|
|
184
|
+
readonly uptime: number
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// ─── Task Types ──────────────────────────────────────────────────────────────
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Task status
|
|
191
|
+
*/
|
|
192
|
+
export type TaskStatus = 'pending' | 'queued' | 'running' | 'completed' | 'failed' | 'cancelled'
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Task priority levels
|
|
196
|
+
*/
|
|
197
|
+
export type TaskPriority = 'low' | 'normal' | 'high' | 'critical'
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Proof generation task
|
|
201
|
+
*/
|
|
202
|
+
export interface ProofTask {
|
|
203
|
+
/** Unique task ID */
|
|
204
|
+
readonly id: string
|
|
205
|
+
/** Dependency node this task executes */
|
|
206
|
+
readonly node: DependencyNode
|
|
207
|
+
/** Task priority */
|
|
208
|
+
readonly priority: TaskPriority
|
|
209
|
+
/** Current status */
|
|
210
|
+
status: TaskStatus
|
|
211
|
+
/** Assigned worker ID (if running) */
|
|
212
|
+
workerId?: string
|
|
213
|
+
/** Task creation timestamp */
|
|
214
|
+
readonly createdAt: number
|
|
215
|
+
/** Task start timestamp */
|
|
216
|
+
startedAt?: number
|
|
217
|
+
/** Task completion timestamp */
|
|
218
|
+
completedAt?: number
|
|
219
|
+
/** Result proof (if completed) */
|
|
220
|
+
result?: SingleProof
|
|
221
|
+
/** Error (if failed) */
|
|
222
|
+
error?: Error
|
|
223
|
+
/** Retry count */
|
|
224
|
+
retryCount: number
|
|
225
|
+
/** Maximum retries allowed */
|
|
226
|
+
readonly maxRetries: number
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Task submission options
|
|
231
|
+
*/
|
|
232
|
+
export interface TaskSubmitOptions {
|
|
233
|
+
/** Task priority */
|
|
234
|
+
readonly priority?: TaskPriority
|
|
235
|
+
/** Maximum retries */
|
|
236
|
+
readonly maxRetries?: number
|
|
237
|
+
/** Timeout in ms */
|
|
238
|
+
readonly timeoutMs?: number
|
|
239
|
+
/** Callback on completion */
|
|
240
|
+
readonly onComplete?: (task: ProofTask) => void
|
|
241
|
+
/** Callback on failure */
|
|
242
|
+
readonly onError?: (task: ProofTask, error: Error) => void
|
|
243
|
+
/** Callback on progress */
|
|
244
|
+
readonly onProgress?: (task: ProofTask, progress: number) => void
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// ─── Concurrency Control Types ───────────────────────────────────────────────
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* System resource information
|
|
251
|
+
*/
|
|
252
|
+
export interface SystemResources {
|
|
253
|
+
/** Number of logical CPU cores */
|
|
254
|
+
readonly cpuCores: number
|
|
255
|
+
/** Available memory in bytes */
|
|
256
|
+
readonly availableMemory: number
|
|
257
|
+
/** Total system memory in bytes */
|
|
258
|
+
readonly totalMemory: number
|
|
259
|
+
/** CPU usage percentage (0-100) */
|
|
260
|
+
readonly cpuUsage: number
|
|
261
|
+
/** Memory usage percentage (0-100) */
|
|
262
|
+
readonly memoryUsage: number
|
|
263
|
+
/** Whether running in browser */
|
|
264
|
+
readonly isBrowser: boolean
|
|
265
|
+
/** Whether Web Workers are supported */
|
|
266
|
+
readonly supportsWebWorkers: boolean
|
|
267
|
+
/** Whether SharedArrayBuffer is supported */
|
|
268
|
+
readonly supportsSharedArrayBuffer: boolean
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Concurrency configuration
|
|
273
|
+
*/
|
|
274
|
+
export interface ConcurrencyConfig {
|
|
275
|
+
/** Maximum concurrent proofs */
|
|
276
|
+
readonly maxConcurrentProofs: number
|
|
277
|
+
/** Maximum memory usage in bytes */
|
|
278
|
+
readonly maxMemoryUsage: number
|
|
279
|
+
/** CPU usage threshold to reduce concurrency (0-100) */
|
|
280
|
+
readonly cpuThreshold: number
|
|
281
|
+
/** Memory usage threshold to reduce concurrency (0-100) */
|
|
282
|
+
readonly memoryThreshold: number
|
|
283
|
+
/** Minimum concurrency level (never go below) */
|
|
284
|
+
readonly minConcurrency: number
|
|
285
|
+
/** Enable adaptive concurrency adjustment */
|
|
286
|
+
readonly enableAdaptive: boolean
|
|
287
|
+
/** Adaptive adjustment interval in ms */
|
|
288
|
+
readonly adaptiveIntervalMs: number
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Default concurrency configuration
|
|
293
|
+
*/
|
|
294
|
+
export const DEFAULT_CONCURRENCY_CONFIG: ConcurrencyConfig = {
|
|
295
|
+
maxConcurrentProofs: 4,
|
|
296
|
+
maxMemoryUsage: 2 * 1024 * 1024 * 1024, // 2GB
|
|
297
|
+
cpuThreshold: 80,
|
|
298
|
+
memoryThreshold: 85,
|
|
299
|
+
minConcurrency: 1,
|
|
300
|
+
enableAdaptive: true,
|
|
301
|
+
adaptiveIntervalMs: 1000,
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Concurrency adjustment decision
|
|
306
|
+
*/
|
|
307
|
+
export interface ConcurrencyDecision {
|
|
308
|
+
/** Recommended concurrency level */
|
|
309
|
+
readonly recommendedConcurrency: number
|
|
310
|
+
/** Reason for adjustment */
|
|
311
|
+
readonly reason: 'cpu_high' | 'memory_high' | 'resources_available' | 'no_change'
|
|
312
|
+
/** Current system resources */
|
|
313
|
+
readonly resources: SystemResources
|
|
314
|
+
/** Timestamp */
|
|
315
|
+
readonly timestamp: number
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// ─── Work Stealing Types ─────────────────────────────────────────────────────
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Work stealing statistics for a worker
|
|
322
|
+
*/
|
|
323
|
+
export interface WorkerStealingStats {
|
|
324
|
+
/** Worker ID */
|
|
325
|
+
readonly workerId: string
|
|
326
|
+
/** Tasks stolen from this worker */
|
|
327
|
+
readonly tasksStolen: number
|
|
328
|
+
/** Tasks acquired from other workers */
|
|
329
|
+
readonly tasksAcquired: number
|
|
330
|
+
/** Average queue length */
|
|
331
|
+
readonly averageQueueLength: number
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Work stealing event
|
|
336
|
+
*/
|
|
337
|
+
export interface WorkStealEvent {
|
|
338
|
+
/** Timestamp */
|
|
339
|
+
readonly timestamp: number
|
|
340
|
+
/** Worker that stole the task */
|
|
341
|
+
readonly thief: string
|
|
342
|
+
/** Worker that lost the task */
|
|
343
|
+
readonly victim: string
|
|
344
|
+
/** Task ID stolen */
|
|
345
|
+
readonly taskId: string
|
|
346
|
+
/** Victim's queue length at time of steal */
|
|
347
|
+
readonly victimQueueLength: number
|
|
348
|
+
/** Thief's queue length at time of steal */
|
|
349
|
+
readonly thiefQueueLength: number
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
// ─── Parallel Execution Types ────────────────────────────────────────────────
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Parallel execution options
|
|
356
|
+
*/
|
|
357
|
+
export interface ParallelExecutionOptions {
|
|
358
|
+
/** Worker pool configuration */
|
|
359
|
+
readonly poolConfig?: Partial<WorkerPoolConfig>
|
|
360
|
+
/** Concurrency configuration */
|
|
361
|
+
readonly concurrencyConfig?: Partial<ConcurrencyConfig>
|
|
362
|
+
/** Maximum execution time in ms */
|
|
363
|
+
readonly timeoutMs?: number
|
|
364
|
+
/** Enable progress events */
|
|
365
|
+
readonly enableProgress?: boolean
|
|
366
|
+
/** Progress callback */
|
|
367
|
+
readonly onProgress?: (event: ParallelProgressEvent) => void
|
|
368
|
+
/** Batch size for submitting tasks */
|
|
369
|
+
readonly batchSize?: number
|
|
370
|
+
/** Preserve order of results */
|
|
371
|
+
readonly preserveOrder?: boolean
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* Progress event for parallel execution
|
|
376
|
+
*/
|
|
377
|
+
export interface ParallelProgressEvent {
|
|
378
|
+
/** Event type */
|
|
379
|
+
readonly type: 'task_started' | 'task_completed' | 'task_failed' | 'batch_completed' | 'all_completed'
|
|
380
|
+
/** Task ID (if applicable) */
|
|
381
|
+
readonly taskId?: string
|
|
382
|
+
/** Number of tasks completed */
|
|
383
|
+
readonly completed: number
|
|
384
|
+
/** Total number of tasks */
|
|
385
|
+
readonly total: number
|
|
386
|
+
/** Completion percentage (0-100) */
|
|
387
|
+
readonly percentage: number
|
|
388
|
+
/** Elapsed time in ms */
|
|
389
|
+
readonly elapsedMs: number
|
|
390
|
+
/** Estimated time remaining in ms */
|
|
391
|
+
readonly estimatedRemainingMs?: number
|
|
392
|
+
/** Current parallelism level */
|
|
393
|
+
readonly currentParallelism: number
|
|
394
|
+
/** Worker pool stats */
|
|
395
|
+
readonly poolStats?: WorkerPoolStats
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* Result of parallel execution
|
|
400
|
+
*/
|
|
401
|
+
export interface ParallelExecutionResult {
|
|
402
|
+
/** All generated proofs (in dependency order) */
|
|
403
|
+
readonly proofs: SingleProof[]
|
|
404
|
+
/** Map of node ID to proof */
|
|
405
|
+
readonly proofMap: Map<string, SingleProof>
|
|
406
|
+
/** Execution statistics */
|
|
407
|
+
readonly stats: ParallelExecutionStats
|
|
408
|
+
/** Any errors encountered */
|
|
409
|
+
readonly errors: ParallelExecutionError[]
|
|
410
|
+
/** Whether execution completed successfully */
|
|
411
|
+
readonly success: boolean
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
/**
|
|
415
|
+
* Execution statistics
|
|
416
|
+
*/
|
|
417
|
+
export interface ParallelExecutionStats {
|
|
418
|
+
/** Total execution time in ms */
|
|
419
|
+
readonly totalTimeMs: number
|
|
420
|
+
/** Time spent on critical path in ms */
|
|
421
|
+
readonly criticalPathTimeMs: number
|
|
422
|
+
/** Maximum parallelism achieved */
|
|
423
|
+
readonly maxParallelism: number
|
|
424
|
+
/** Average parallelism level */
|
|
425
|
+
readonly averageParallelism: number
|
|
426
|
+
/** Number of tasks completed */
|
|
427
|
+
readonly tasksCompleted: number
|
|
428
|
+
/** Number of tasks failed */
|
|
429
|
+
readonly tasksFailed: number
|
|
430
|
+
/** Number of work steals */
|
|
431
|
+
readonly workSteals: number
|
|
432
|
+
/** Peak memory usage in bytes */
|
|
433
|
+
readonly peakMemoryUsage: number
|
|
434
|
+
/** Speedup factor vs sequential */
|
|
435
|
+
readonly speedupFactor: number
|
|
436
|
+
/** Efficiency (speedup / parallelism) */
|
|
437
|
+
readonly efficiency: number
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* Error during parallel execution
|
|
442
|
+
*/
|
|
443
|
+
export interface ParallelExecutionError {
|
|
444
|
+
/** Task ID that failed */
|
|
445
|
+
readonly taskId: string
|
|
446
|
+
/** Error message */
|
|
447
|
+
readonly message: string
|
|
448
|
+
/** Error stack */
|
|
449
|
+
readonly stack?: string
|
|
450
|
+
/** Retry count at failure */
|
|
451
|
+
readonly retryCount: number
|
|
452
|
+
/** Whether task was retried */
|
|
453
|
+
readonly wasRetried: boolean
|
|
454
|
+
/** Timestamp */
|
|
455
|
+
readonly timestamp: number
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
// ─── Scheduler Types ─────────────────────────────────────────────────────────
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* Scheduling strategy
|
|
462
|
+
*/
|
|
463
|
+
export type SchedulingStrategy =
|
|
464
|
+
| 'fifo' // First in, first out
|
|
465
|
+
| 'priority' // By priority then creation time
|
|
466
|
+
| 'shortest_first' // Shortest estimated time first
|
|
467
|
+
| 'critical_path' // Critical path tasks first
|
|
468
|
+
| 'balanced' // Balance load across workers
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* Scheduler configuration
|
|
472
|
+
*/
|
|
473
|
+
export interface SchedulerConfig {
|
|
474
|
+
/** Scheduling strategy */
|
|
475
|
+
readonly strategy: SchedulingStrategy
|
|
476
|
+
/** Enable preemption of low priority tasks */
|
|
477
|
+
readonly enablePreemption: boolean
|
|
478
|
+
/** Preemption threshold (only preempt if new task priority exceeds by this) */
|
|
479
|
+
readonly preemptionThreshold: number
|
|
480
|
+
/** Enable task batching */
|
|
481
|
+
readonly enableBatching: boolean
|
|
482
|
+
/** Batch timeout in ms */
|
|
483
|
+
readonly batchTimeoutMs: number
|
|
484
|
+
/** Maximum batch size */
|
|
485
|
+
readonly maxBatchSize: number
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
/**
|
|
489
|
+
* Default scheduler configuration
|
|
490
|
+
*/
|
|
491
|
+
export const DEFAULT_SCHEDULER_CONFIG: SchedulerConfig = {
|
|
492
|
+
strategy: 'balanced',
|
|
493
|
+
enablePreemption: false,
|
|
494
|
+
preemptionThreshold: 2,
|
|
495
|
+
enableBatching: true,
|
|
496
|
+
batchTimeoutMs: 50,
|
|
497
|
+
maxBatchSize: 10,
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
// ─── Interface Definitions ───────────────────────────────────────────────────
|
|
501
|
+
|
|
502
|
+
/**
|
|
503
|
+
* Dependency graph analyzer interface
|
|
504
|
+
*/
|
|
505
|
+
export interface IDependencyAnalyzer {
|
|
506
|
+
/**
|
|
507
|
+
* Analyze a set of proof requests and build dependency graph
|
|
508
|
+
*/
|
|
509
|
+
analyze(nodes: DependencyNode[]): GraphAnalysis
|
|
510
|
+
|
|
511
|
+
/**
|
|
512
|
+
* Add a node to an existing graph
|
|
513
|
+
*/
|
|
514
|
+
addNode(graph: DependencyGraph, node: DependencyNode): DependencyGraph
|
|
515
|
+
|
|
516
|
+
/**
|
|
517
|
+
* Remove a node from the graph
|
|
518
|
+
*/
|
|
519
|
+
removeNode(graph: DependencyGraph, nodeId: string): DependencyGraph
|
|
520
|
+
|
|
521
|
+
/**
|
|
522
|
+
* Get execution order respecting dependencies
|
|
523
|
+
*/
|
|
524
|
+
getExecutionOrder(graph: DependencyGraph): readonly string[]
|
|
525
|
+
|
|
526
|
+
/**
|
|
527
|
+
* Find nodes ready to execute (dependencies satisfied)
|
|
528
|
+
*/
|
|
529
|
+
getReadyNodes(graph: DependencyGraph, completed: Set<string>): readonly string[]
|
|
530
|
+
|
|
531
|
+
/**
|
|
532
|
+
* Validate graph is acyclic
|
|
533
|
+
*/
|
|
534
|
+
validateAcyclic(graph: DependencyGraph): boolean
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
/**
|
|
538
|
+
* Worker pool interface
|
|
539
|
+
*/
|
|
540
|
+
export interface IWorkerPool {
|
|
541
|
+
/**
|
|
542
|
+
* Submit a task to the pool
|
|
543
|
+
*/
|
|
544
|
+
submit(task: ProofTask, options?: TaskSubmitOptions): Promise<SingleProof>
|
|
545
|
+
|
|
546
|
+
/**
|
|
547
|
+
* Get current pool statistics
|
|
548
|
+
*/
|
|
549
|
+
getStats(): WorkerPoolStats
|
|
550
|
+
|
|
551
|
+
/**
|
|
552
|
+
* Get information about all workers
|
|
553
|
+
*/
|
|
554
|
+
getWorkers(): readonly WorkerInfo[]
|
|
555
|
+
|
|
556
|
+
/**
|
|
557
|
+
* Scale pool to target worker count
|
|
558
|
+
*/
|
|
559
|
+
scale(targetWorkers: number): Promise<void>
|
|
560
|
+
|
|
561
|
+
/**
|
|
562
|
+
* Pause task execution
|
|
563
|
+
*/
|
|
564
|
+
pause(): void
|
|
565
|
+
|
|
566
|
+
/**
|
|
567
|
+
* Resume task execution
|
|
568
|
+
*/
|
|
569
|
+
resume(): void
|
|
570
|
+
|
|
571
|
+
/**
|
|
572
|
+
* Shutdown the pool
|
|
573
|
+
*/
|
|
574
|
+
shutdown(): Promise<void>
|
|
575
|
+
|
|
576
|
+
/**
|
|
577
|
+
* Check if pool is running
|
|
578
|
+
*/
|
|
579
|
+
isRunning(): boolean
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
/**
|
|
583
|
+
* Concurrency manager interface
|
|
584
|
+
*/
|
|
585
|
+
export interface IConcurrencyManager {
|
|
586
|
+
/**
|
|
587
|
+
* Get current system resources
|
|
588
|
+
*/
|
|
589
|
+
getResources(): SystemResources
|
|
590
|
+
|
|
591
|
+
/**
|
|
592
|
+
* Calculate optimal concurrency level
|
|
593
|
+
*/
|
|
594
|
+
calculateOptimalConcurrency(): ConcurrencyDecision
|
|
595
|
+
|
|
596
|
+
/**
|
|
597
|
+
* Start adaptive monitoring
|
|
598
|
+
*/
|
|
599
|
+
startMonitoring(): void
|
|
600
|
+
|
|
601
|
+
/**
|
|
602
|
+
* Stop adaptive monitoring
|
|
603
|
+
*/
|
|
604
|
+
stopMonitoring(): void
|
|
605
|
+
|
|
606
|
+
/**
|
|
607
|
+
* Get current concurrency limit
|
|
608
|
+
*/
|
|
609
|
+
getCurrentLimit(): number
|
|
610
|
+
|
|
611
|
+
/**
|
|
612
|
+
* Manually set concurrency limit
|
|
613
|
+
*/
|
|
614
|
+
setLimit(limit: number): void
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
/**
|
|
618
|
+
* Work stealing scheduler interface
|
|
619
|
+
*/
|
|
620
|
+
export interface IWorkStealingScheduler {
|
|
621
|
+
/**
|
|
622
|
+
* Assign a task to a worker
|
|
623
|
+
*/
|
|
624
|
+
assign(task: ProofTask): string | null
|
|
625
|
+
|
|
626
|
+
/**
|
|
627
|
+
* Attempt to steal work from another worker
|
|
628
|
+
*/
|
|
629
|
+
steal(thief: string): ProofTask | null
|
|
630
|
+
|
|
631
|
+
/**
|
|
632
|
+
* Get stealing statistics
|
|
633
|
+
*/
|
|
634
|
+
getStealingStats(): readonly WorkerStealingStats[]
|
|
635
|
+
|
|
636
|
+
/**
|
|
637
|
+
* Get steal events history
|
|
638
|
+
*/
|
|
639
|
+
getStealHistory(limit?: number): readonly WorkStealEvent[]
|
|
640
|
+
|
|
641
|
+
/**
|
|
642
|
+
* Clear a worker's queue (worker terminated)
|
|
643
|
+
*/
|
|
644
|
+
clearWorkerQueue(workerId: string): readonly ProofTask[]
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
/**
|
|
648
|
+
* Main parallel executor interface
|
|
649
|
+
*/
|
|
650
|
+
export interface IParallelExecutor {
|
|
651
|
+
/**
|
|
652
|
+
* Execute proofs in parallel with dependency resolution
|
|
653
|
+
*/
|
|
654
|
+
execute(nodes: DependencyNode[], options?: ParallelExecutionOptions): Promise<ParallelExecutionResult>
|
|
655
|
+
|
|
656
|
+
/**
|
|
657
|
+
* Cancel ongoing execution
|
|
658
|
+
*/
|
|
659
|
+
cancel(): Promise<void>
|
|
660
|
+
|
|
661
|
+
/**
|
|
662
|
+
* Get current execution status
|
|
663
|
+
*/
|
|
664
|
+
getStatus(): {
|
|
665
|
+
readonly running: boolean
|
|
666
|
+
readonly progress: number
|
|
667
|
+
readonly completed: number
|
|
668
|
+
readonly total: number
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
/**
|
|
672
|
+
* Get the dependency analyzer
|
|
673
|
+
*/
|
|
674
|
+
getAnalyzer(): IDependencyAnalyzer
|
|
675
|
+
|
|
676
|
+
/**
|
|
677
|
+
* Get the worker pool
|
|
678
|
+
*/
|
|
679
|
+
getPool(): IWorkerPool
|
|
680
|
+
|
|
681
|
+
/**
|
|
682
|
+
* Get the concurrency manager
|
|
683
|
+
*/
|
|
684
|
+
getConcurrencyManager(): IConcurrencyManager
|
|
685
|
+
}
|