@cogcoin/client 1.1.9 → 1.1.10
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/README.md +1 -1
- package/dist/bitcoind/managed-bitcoind-service-config.d.ts +13 -0
- package/dist/bitcoind/managed-bitcoind-service-config.js +165 -0
- package/dist/bitcoind/managed-bitcoind-service-lifecycle.d.ts +28 -0
- package/dist/bitcoind/managed-bitcoind-service-lifecycle.js +290 -0
- package/dist/bitcoind/managed-bitcoind-service-process.d.ts +8 -0
- package/dist/bitcoind/managed-bitcoind-service-process.js +48 -0
- package/dist/bitcoind/managed-bitcoind-service-replica.d.ts +8 -0
- package/dist/bitcoind/managed-bitcoind-service-replica.js +142 -0
- package/dist/bitcoind/managed-bitcoind-service-status.d.ts +42 -0
- package/dist/bitcoind/managed-bitcoind-service-status.js +178 -0
- package/dist/bitcoind/managed-bitcoind-service-types.d.ts +36 -0
- package/dist/bitcoind/managed-bitcoind-service-types.js +1 -0
- package/dist/bitcoind/service.d.ts +7 -63
- package/dist/bitcoind/service.js +7 -797
- package/dist/wallet/mining/engine-types.d.ts +1 -0
- package/dist/wallet/mining/engine-types.js +9 -1
- package/dist/wallet/mining/publish.js +3 -6
- package/dist/wallet/mining/runner.js +30 -18
- package/dist/wallet/mining/visualizer.js +7 -6
- package/dist/wallet/read/context.d.ts +4 -10
- package/dist/wallet/read/context.js +4 -227
- package/dist/wallet/read/local-state.d.ts +28 -0
- package/dist/wallet/read/local-state.js +233 -0
- package/dist/wallet/read/managed-bitcoind.d.ts +30 -0
- package/dist/wallet/read/managed-bitcoind.js +138 -0
- package/dist/wallet/read/managed-indexer.d.ts +23 -0
- package/dist/wallet/read/managed-indexer.js +87 -0
- package/dist/wallet/read/managed-services.d.ts +6 -21
- package/dist/wallet/read/managed-services.js +23 -196
- package/package.json +1 -1
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { loadBundledGenesisParameters } from "@cogcoin/indexer";
|
|
2
2
|
import { attachOrStartIndexerDaemon, INDEXER_DAEMON_BACKGROUND_FOLLOW_RECOVERY_FAILED, probeIndexerDaemon, readObservedIndexerDaemonStatus, readSnapshotWithRetry, } from "../../bitcoind/indexer-daemon.js";
|
|
3
|
-
import { deriveManagedBitcoindWalletStatus, resolveManagedBitcoindProbeDecision, } from "../../bitcoind/managed-runtime/bitcoind-policy.js";
|
|
4
|
-
import { deriveManagedIndexerWalletStatus, resolveIndexerDaemonProbeDecision, } from "../../bitcoind/managed-runtime/indexer-policy.js";
|
|
5
3
|
import { createRpcClient } from "../../bitcoind/node.js";
|
|
6
|
-
import { resolveCogcoinProcessingStartHeight } from "../../bitcoind/processing-start-height.js";
|
|
7
4
|
import { attachOrStartManagedBitcoindService, probeManagedBitcoindService, } from "../../bitcoind/service.js";
|
|
8
5
|
import { verifyManagedCoreWalletReplica } from "../lifecycle.js";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const NODE_CATCHING_UP_MESSAGE = "Bitcoin Core is still catching up to headers.";
|
|
6
|
+
import { deriveNodeHealthForTesting, openManagedWalletBitcoindReadState, } from "./managed-bitcoind.js";
|
|
7
|
+
import { openManagedWalletIndexerReadState, } from "./managed-indexer.js";
|
|
12
8
|
const defaultManagedWalletReadServiceDeps = {
|
|
13
9
|
loadBundledGenesisParameters,
|
|
14
10
|
probeManagedBitcoindService,
|
|
@@ -20,203 +16,34 @@ const defaultManagedWalletReadServiceDeps = {
|
|
|
20
16
|
readSnapshotWithRetry,
|
|
21
17
|
readObservedIndexerDaemonStatus,
|
|
22
18
|
};
|
|
23
|
-
function deriveNodeHealth(status, bitcoindHealth) {
|
|
24
|
-
if (bitcoindHealth !== "ready" || status === null || !status.ready) {
|
|
25
|
-
return {
|
|
26
|
-
health: "catching-up",
|
|
27
|
-
message: NODE_CATCHING_UP_MESSAGE,
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
const headerLead = status.nodeBestHeight !== null && status.nodeHeaderHeight !== null
|
|
31
|
-
? status.nodeHeaderHeight - status.nodeBestHeight
|
|
32
|
-
: null;
|
|
33
|
-
if (headerLead !== null && headerLead > 0) {
|
|
34
|
-
if (headerLead <= TOLERATED_NODE_HEADER_LEAD_BLOCKS) {
|
|
35
|
-
return {
|
|
36
|
-
health: "synced",
|
|
37
|
-
message: TOLERATED_NODE_HEADER_LEAD_MESSAGE,
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
return {
|
|
41
|
-
health: "catching-up",
|
|
42
|
-
message: NODE_CATCHING_UP_MESSAGE,
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
return {
|
|
46
|
-
health: "synced",
|
|
47
|
-
message: null,
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
export function deriveNodeHealthForTesting(status, bitcoindHealth) {
|
|
51
|
-
return deriveNodeHealth(status, bitcoindHealth);
|
|
52
|
-
}
|
|
53
|
-
async function attachNodeStatus(options, dependencies) {
|
|
54
|
-
try {
|
|
55
|
-
const probe = await dependencies.probeManagedBitcoindService({
|
|
56
|
-
dataDir: options.dataDir,
|
|
57
|
-
chain: "main",
|
|
58
|
-
startHeight: 0,
|
|
59
|
-
walletRootId: options.walletRootId,
|
|
60
|
-
startupTimeoutMs: options.startupTimeoutMs,
|
|
61
|
-
});
|
|
62
|
-
const decision = resolveManagedBitcoindProbeDecision(probe);
|
|
63
|
-
if (decision.action === "reject") {
|
|
64
|
-
return {
|
|
65
|
-
handle: null,
|
|
66
|
-
rpc: null,
|
|
67
|
-
status: null,
|
|
68
|
-
observedStatus: probe.status,
|
|
69
|
-
error: decision.error,
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
const genesis = await dependencies.loadBundledGenesisParameters();
|
|
73
|
-
const handle = await dependencies.attachOrStartManagedBitcoindService({
|
|
74
|
-
dataDir: options.dataDir,
|
|
75
|
-
chain: "main",
|
|
76
|
-
startHeight: resolveCogcoinProcessingStartHeight(genesis),
|
|
77
|
-
walletRootId: options.walletRootId,
|
|
78
|
-
startupTimeoutMs: options.startupTimeoutMs,
|
|
79
|
-
});
|
|
80
|
-
const rpc = dependencies.createRpcClient(handle.rpc);
|
|
81
|
-
const [chainInfo, serviceStatus] = await Promise.all([
|
|
82
|
-
rpc.getBlockchainInfo(),
|
|
83
|
-
handle.refreshServiceStatus?.(),
|
|
84
|
-
]);
|
|
85
|
-
const status = {
|
|
86
|
-
ready: true,
|
|
87
|
-
chain: chainInfo.chain,
|
|
88
|
-
pid: handle.pid,
|
|
89
|
-
walletRootId: handle.walletRootId ?? null,
|
|
90
|
-
nodeBestHeight: chainInfo.blocks,
|
|
91
|
-
nodeBestHashHex: chainInfo.bestblockhash,
|
|
92
|
-
nodeHeaderHeight: chainInfo.headers,
|
|
93
|
-
serviceUpdatedAtUnixMs: serviceStatus?.updatedAtUnixMs ?? null,
|
|
94
|
-
serviceStatus: serviceStatus ?? null,
|
|
95
|
-
walletReplica: serviceStatus?.walletReplica ?? null,
|
|
96
|
-
walletReplicaMessage: serviceStatus?.walletReplica?.message ?? null,
|
|
97
|
-
};
|
|
98
|
-
return {
|
|
99
|
-
handle,
|
|
100
|
-
rpc,
|
|
101
|
-
status,
|
|
102
|
-
observedStatus: serviceStatus ?? null,
|
|
103
|
-
error: null,
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
catch (error) {
|
|
107
|
-
return {
|
|
108
|
-
handle: null,
|
|
109
|
-
rpc: null,
|
|
110
|
-
status: null,
|
|
111
|
-
observedStatus: null,
|
|
112
|
-
error: error instanceof Error ? error.message : String(error),
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
19
|
export async function openManagedWalletReadServiceBundle(options, dependencies = defaultManagedWalletReadServiceDeps) {
|
|
117
|
-
const
|
|
20
|
+
const bitcoindState = await openManagedWalletBitcoindReadState({
|
|
118
21
|
dataDir: options.dataDir,
|
|
119
22
|
walletRootId: options.walletRootId,
|
|
23
|
+
localState: options.localState,
|
|
120
24
|
startupTimeoutMs: options.startupTimeoutMs,
|
|
121
25
|
}, dependencies);
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
walletReplica: verifiedReplica,
|
|
129
|
-
walletReplicaMessage: verifiedReplica.message ?? null,
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
const bitcoind = deriveManagedBitcoindWalletStatus({
|
|
133
|
-
status: node.observedStatus,
|
|
134
|
-
nodeStatus: node.status,
|
|
135
|
-
startupError: node.error,
|
|
136
|
-
});
|
|
137
|
-
const nodeDerived = deriveNodeHealth(node.status, bitcoind.health);
|
|
138
|
-
let daemonClient = null;
|
|
139
|
-
let daemonStatus = null;
|
|
140
|
-
let observedDaemonStatus = null;
|
|
141
|
-
let snapshot = null;
|
|
142
|
-
let indexerSource = "none";
|
|
143
|
-
let daemonError = null;
|
|
144
|
-
try {
|
|
145
|
-
const probe = await dependencies.probeIndexerDaemon({
|
|
146
|
-
dataDir: options.dataDir,
|
|
147
|
-
walletRootId: options.walletRootId,
|
|
148
|
-
});
|
|
149
|
-
const probeDecision = resolveIndexerDaemonProbeDecision({
|
|
150
|
-
probe,
|
|
151
|
-
expectedBinaryVersion: options.expectedIndexerBinaryVersion,
|
|
152
|
-
});
|
|
153
|
-
if (probeDecision.action !== "reject") {
|
|
154
|
-
await probe.client?.close().catch(() => undefined);
|
|
155
|
-
daemonClient = await dependencies.attachOrStartIndexerDaemon({
|
|
156
|
-
dataDir: options.dataDir,
|
|
157
|
-
databasePath: options.databasePath,
|
|
158
|
-
walletRootId: options.walletRootId,
|
|
159
|
-
startupTimeoutMs: options.startupTimeoutMs,
|
|
160
|
-
ensureBackgroundFollow: true,
|
|
161
|
-
expectedBinaryVersion: options.expectedIndexerBinaryVersion,
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
else {
|
|
165
|
-
observedDaemonStatus = probe.status;
|
|
166
|
-
indexerSource = probe.status === null ? "none" : "probe";
|
|
167
|
-
daemonError = probeDecision.error;
|
|
168
|
-
}
|
|
169
|
-
if (daemonClient !== null) {
|
|
170
|
-
const lease = await dependencies.readSnapshotWithRetry(daemonClient, options.walletRootId);
|
|
171
|
-
daemonStatus = lease.status;
|
|
172
|
-
observedDaemonStatus = lease.status;
|
|
173
|
-
snapshot = {
|
|
174
|
-
tip: lease.payload.tip,
|
|
175
|
-
state: deserializeIndexerState(Buffer.from(lease.payload.stateBase64, "base64")),
|
|
176
|
-
source: "lease",
|
|
177
|
-
daemonInstanceId: lease.payload.daemonInstanceId,
|
|
178
|
-
snapshotSeq: lease.payload.snapshotSeq,
|
|
179
|
-
openedAtUnixMs: lease.payload.openedAtUnixMs,
|
|
180
|
-
};
|
|
181
|
-
indexerSource = "lease";
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
catch (error) {
|
|
185
|
-
daemonError = error instanceof Error ? error.message : String(error);
|
|
186
|
-
if (daemonError === INDEXER_DAEMON_BACKGROUND_FOLLOW_RECOVERY_FAILED) {
|
|
187
|
-
await daemonClient?.close().catch(() => undefined);
|
|
188
|
-
await node.handle?.stop().catch(() => undefined);
|
|
189
|
-
throw error;
|
|
190
|
-
}
|
|
191
|
-
if (observedDaemonStatus === null) {
|
|
192
|
-
observedDaemonStatus = await dependencies.readObservedIndexerDaemonStatus({
|
|
193
|
-
dataDir: options.dataDir,
|
|
194
|
-
walletRootId: options.walletRootId,
|
|
195
|
-
}).catch(() => null);
|
|
196
|
-
if (observedDaemonStatus !== null) {
|
|
197
|
-
indexerSource = "status-file";
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
const indexer = deriveManagedIndexerWalletStatus({
|
|
202
|
-
daemonStatus,
|
|
203
|
-
observedStatus: observedDaemonStatus,
|
|
204
|
-
snapshot,
|
|
205
|
-
source: indexerSource,
|
|
26
|
+
const indexerState = await openManagedWalletIndexerReadState({
|
|
27
|
+
dataDir: options.dataDir,
|
|
28
|
+
databasePath: options.databasePath,
|
|
29
|
+
walletRootId: options.walletRootId,
|
|
30
|
+
startupTimeoutMs: options.startupTimeoutMs,
|
|
31
|
+
expectedIndexerBinaryVersion: options.expectedIndexerBinaryVersion,
|
|
206
32
|
now: options.now,
|
|
207
|
-
|
|
208
|
-
});
|
|
33
|
+
nodeHandle: bitcoindState.node.handle,
|
|
34
|
+
}, dependencies);
|
|
209
35
|
return {
|
|
210
|
-
node,
|
|
211
|
-
bitcoind,
|
|
212
|
-
nodeHealth:
|
|
213
|
-
nodeMessage:
|
|
214
|
-
daemonClient,
|
|
215
|
-
indexer,
|
|
216
|
-
snapshot,
|
|
36
|
+
node: bitcoindState.node,
|
|
37
|
+
bitcoind: bitcoindState.bitcoind,
|
|
38
|
+
nodeHealth: bitcoindState.nodeHealth,
|
|
39
|
+
nodeMessage: bitcoindState.nodeMessage,
|
|
40
|
+
daemonClient: indexerState.daemonClient,
|
|
41
|
+
indexer: indexerState.indexer,
|
|
42
|
+
snapshot: indexerState.snapshot,
|
|
217
43
|
async close() {
|
|
218
|
-
await daemonClient?.close().catch(() => undefined);
|
|
219
|
-
await node.handle?.stop().catch(() => undefined);
|
|
44
|
+
await indexerState.daemonClient?.close().catch(() => undefined);
|
|
45
|
+
await bitcoindState.node.handle?.stop().catch(() => undefined);
|
|
220
46
|
},
|
|
221
47
|
};
|
|
222
48
|
}
|
|
49
|
+
export { deriveNodeHealthForTesting };
|
package/package.json
CHANGED