@leofcoin/chain 1.10.21 → 1.11.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.
- package/README.md +95 -0
- package/exports/browser/beacon-wire.js +2 -2
- package/exports/browser/{browser-CCfR9KOM-BGMMnVsR.js → browser-CCfR9KOM-CNWKLusu.js} +3 -3
- package/exports/browser/{browser-crypto-CH0ua22L.js → browser-crypto-B_UJguhk.js} +453 -35
- package/exports/browser/chain.js +1275 -996
- package/exports/browser/client-DbZBfpG6-C1cXgvfr.js +5943 -0
- package/exports/browser/{connection-monitor-D-krNiRH.js → connection-monitor-BzbeYGEt.js} +153 -24
- package/exports/browser/{index-dTQVgkpf-DOL2rIjp.js → index-dTQVgkpf-CkoAiRNX.js} +3 -3
- package/exports/browser/{index-DCbLvMKL.js → index-phv5KvaE.js} +238 -234
- package/exports/browser/{messages-DCePyqKC-BSvJxDWZ.js → messages-DZYCxoZI-B472zldo.js} +3 -3
- package/exports/browser/{node-browser-Ha4Lvntj.js → node-browser-BmyPBkL5.js} +55 -11
- package/exports/browser/node-browser.js +3 -3
- package/exports/browser/workers/block-worker.js +8 -9
- package/exports/browser/workers/machine-worker.js +141 -1195
- package/exports/{workers/worker-BDTWOCzS-COrAszCt.js → browser/workers/proposal.proto-8zgMfutf-B3So_tnS.js} +910 -398
- package/exports/chain.js +296 -1078
- package/exports/connection-monitor-BdFLRh-J.js +465 -0
- package/exports/connection-monitor.js +2 -324
- package/exports/{constants-Dy9i9S_o.js → constants-BQ6f-_OT.js} +1 -1
- package/exports/hash-format-state.js +3 -3
- package/exports/machine.js +550 -0
- package/exports/node.js +35 -2
- package/exports/state-checkpoint-BiQ1EXzo.js +110 -0
- package/exports/state-checkpoint.js +3 -0
- package/exports/workers/block-worker.js +8 -9
- package/exports/workers/machine-worker.js +141 -1195
- package/exports/{browser/workers/worker-BDTWOCzS-COrAszCt.js → workers/proposal.proto-8zgMfutf-B3So_tnS.js} +910 -398
- package/package.json +9 -7
- package/exports/browser/client-DKKzPSlb-C_1ug6ux.js +0 -2401
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { B as BinaryFormat, t as proto, u as proto$1, w as encodeFrames, x as decodeFrames, y as proto$2, z as proto$3, A as proto$4, C as Codec } from './browser-crypto-B_UJguhk.js';
|
|
2
2
|
|
|
3
|
-
class ValidatorMessage extends
|
|
3
|
+
class ValidatorMessage extends BinaryFormat {
|
|
4
4
|
get messageName() {
|
|
5
5
|
return "ValidatorMessage";
|
|
6
6
|
}
|
|
@@ -8,11 +8,11 @@ class ValidatorMessage extends FormatInterface {
|
|
|
8
8
|
if (buffer instanceof ValidatorMessage)
|
|
9
9
|
return buffer;
|
|
10
10
|
const name = "validator-message";
|
|
11
|
-
super(buffer, proto
|
|
11
|
+
super(buffer, proto, { name });
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
class BlockMessage extends
|
|
15
|
+
class BlockMessage extends BinaryFormat {
|
|
16
16
|
get messageName() {
|
|
17
17
|
return "BlockMessage";
|
|
18
18
|
}
|
|
@@ -20,7 +20,7 @@ class BlockMessage extends FormatInterface {
|
|
|
20
20
|
if (buffer instanceof BlockMessage)
|
|
21
21
|
return buffer;
|
|
22
22
|
const name = "block-message";
|
|
23
|
-
super(buffer, proto$
|
|
23
|
+
super(buffer, proto$1, { name });
|
|
24
24
|
}
|
|
25
25
|
encode(decoded) {
|
|
26
26
|
decoded = decoded || this.decoded;
|
|
@@ -39,17 +39,12 @@ class BlockMessage extends FormatInterface {
|
|
|
39
39
|
decode(encoded) {
|
|
40
40
|
encoded = encoded || this.encoded;
|
|
41
41
|
super.decode(encoded);
|
|
42
|
-
this.decoded.validators = decodeFrames(this.decoded.validators
|
|
42
|
+
this.decoded.validators = decodeFrames(this.decoded.validators).map((validator) => new ValidatorMessage(validator).decoded);
|
|
43
43
|
return this.decoded;
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
up: Number(),
|
|
49
|
-
down: Number()
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
class BWMessage extends FormatInterface {
|
|
47
|
+
class BWMessage extends BinaryFormat {
|
|
53
48
|
get messageName() {
|
|
54
49
|
return "BWMessage";
|
|
55
50
|
}
|
|
@@ -57,11 +52,11 @@ class BWMessage extends FormatInterface {
|
|
|
57
52
|
if (buffer instanceof BWMessage)
|
|
58
53
|
return buffer;
|
|
59
54
|
const name = "bw-message";
|
|
60
|
-
super(buffer, proto$
|
|
55
|
+
super(buffer, proto$2, { name });
|
|
61
56
|
}
|
|
62
57
|
}
|
|
63
58
|
|
|
64
|
-
class LastBlockMessage extends
|
|
59
|
+
class LastBlockMessage extends BinaryFormat {
|
|
65
60
|
get messageName() {
|
|
66
61
|
return "LastBlockMessage";
|
|
67
62
|
}
|
|
@@ -69,16 +64,11 @@ class LastBlockMessage extends FormatInterface {
|
|
|
69
64
|
if (buffer instanceof LastBlockMessage)
|
|
70
65
|
return buffer;
|
|
71
66
|
const name = "last-block-message";
|
|
72
|
-
super(buffer, proto$
|
|
67
|
+
super(buffer, proto$3, { name });
|
|
73
68
|
}
|
|
74
69
|
}
|
|
75
70
|
|
|
76
|
-
|
|
77
|
-
lastblock: Object(),
|
|
78
|
-
values: Object()
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
class StateMessage extends FormatInterface {
|
|
71
|
+
class StateMessage extends BinaryFormat {
|
|
82
72
|
get messageName() {
|
|
83
73
|
return "StateMessage";
|
|
84
74
|
}
|
|
@@ -86,7 +76,30 @@ class StateMessage extends FormatInterface {
|
|
|
86
76
|
if (buffer instanceof StateMessage)
|
|
87
77
|
return buffer;
|
|
88
78
|
const name = "state-message";
|
|
89
|
-
super(buffer, proto, { name });
|
|
79
|
+
super(buffer, proto$4, { name });
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const limit = 1800;
|
|
84
|
+
const transactionLimit = 2500;
|
|
85
|
+
const requestTimeout = 3e4;
|
|
86
|
+
const syncTimeout = 3e4;
|
|
87
|
+
class Protocol {
|
|
88
|
+
constructor(config) {
|
|
89
|
+
this.resolveTimeout = 1e4;
|
|
90
|
+
if (config?.resolveTimeout) this.resolveTimeout = config.resolveTimeout;
|
|
91
|
+
}
|
|
92
|
+
get limit() {
|
|
93
|
+
return limit;
|
|
94
|
+
}
|
|
95
|
+
get transactionLimit() {
|
|
96
|
+
return transactionLimit;
|
|
97
|
+
}
|
|
98
|
+
get requestTimeout() {
|
|
99
|
+
return requestTimeout;
|
|
100
|
+
}
|
|
101
|
+
get syncTimeout() {
|
|
102
|
+
return syncTimeout;
|
|
90
103
|
}
|
|
91
104
|
}
|
|
92
105
|
|
|
@@ -118,7 +131,7 @@ var networks$1 = /*#__PURE__*/Object.freeze({
|
|
|
118
131
|
default: networks
|
|
119
132
|
});
|
|
120
133
|
|
|
121
|
-
const PROTOCOL_VERSION = "0.
|
|
134
|
+
const PROTOCOL_VERSION = "0.5.0";
|
|
122
135
|
const REACHED_ONE_ZERO_ZERO = false;
|
|
123
136
|
const DEFAULT_NODE_OPTIONS = {
|
|
124
137
|
autoStart: false,
|
|
@@ -130,6 +143,122 @@ const DEFAULT_NODE_OPTIONS = {
|
|
|
130
143
|
|
|
131
144
|
const INITIAL_RECONNECT_DELAY = 5e3;
|
|
132
145
|
const MAX_RECONNECT_DELAY = 3e4;
|
|
146
|
+
const isChainStore = (store) => store === "block" || store === "transaction" || store === "transactionPool";
|
|
147
|
+
const guardProviderDiscovery = (peernet) => {
|
|
148
|
+
const handleData = peernet.handleData.bind(peernet);
|
|
149
|
+
peernet.handleData = async (peer, id, proto) => {
|
|
150
|
+
const { hash, store: storeName } = proto.decoded;
|
|
151
|
+
if (!isChainStore(storeName)) return handleData(peer, id, proto);
|
|
152
|
+
let data = new Uint8Array();
|
|
153
|
+
try {
|
|
154
|
+
const store = globalThis[`${storeName}Store`];
|
|
155
|
+
if (store && !("private" in store && store.private) && await store.has(hash)) {
|
|
156
|
+
const bytes = await store.get(hash);
|
|
157
|
+
if (!(bytes instanceof Uint8Array) || bytes.length === 0) {
|
|
158
|
+
throw new Error("local content is unavailable");
|
|
159
|
+
}
|
|
160
|
+
data = bytes;
|
|
161
|
+
} else {
|
|
162
|
+
console.warn(`Requested content unavailable in ${storeName}: ${hash}`);
|
|
163
|
+
}
|
|
164
|
+
} catch (error) {
|
|
165
|
+
console.error(`Local chain data read failed in ${storeName}: ${hash}`, error);
|
|
166
|
+
}
|
|
167
|
+
try {
|
|
168
|
+
const response = new peernet.protos["peernet-data-response"]({ hash, data });
|
|
169
|
+
const message = await peernet.prepareMessage(response);
|
|
170
|
+
await peernet.sendMessage(peer, id, message.encoded);
|
|
171
|
+
} catch (error) {
|
|
172
|
+
console.error(`Incoming chain data response failed in ${storeName}: ${hash}`, error);
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
peernet.walk = async (hash) => {
|
|
176
|
+
if (!hash) throw new Error("hash expected for provider discovery");
|
|
177
|
+
const request = new peernet.protos["peernet-dht"]({ hash });
|
|
178
|
+
const message = await peernet.prepareMessage(request);
|
|
179
|
+
const connections = peernet.connections;
|
|
180
|
+
const requests = Object.entries(connections).filter(
|
|
181
|
+
([id, peer]) => id !== peernet.id && peer.connected
|
|
182
|
+
).map(async ([id, peer]) => {
|
|
183
|
+
let timeout;
|
|
184
|
+
try {
|
|
185
|
+
const result = await Promise.race([
|
|
186
|
+
peer.request(message.encoded),
|
|
187
|
+
new Promise((_, reject) => {
|
|
188
|
+
timeout = setTimeout(() => reject(new Error("provider discovery timed out")), requestTimeout);
|
|
189
|
+
})
|
|
190
|
+
]);
|
|
191
|
+
if (!(result instanceof Uint8Array)) throw new TypeError("Peer response must be Uint8Array");
|
|
192
|
+
const bytes = result;
|
|
193
|
+
if (new Codec(bytes).name !== "peernet-dht-response") throw new Error("invalid provider response codec");
|
|
194
|
+
const response = new peernet.protos["peernet-dht-response"](bytes).decoded;
|
|
195
|
+
if (response.hash !== hash) throw new Error("provider response hash mismatch");
|
|
196
|
+
if (!response.has) throw new Error("peer does not provide content");
|
|
197
|
+
peernet.dht.addProvider({ id, address: peer.remoteAddress }, hash);
|
|
198
|
+
} catch (error) {
|
|
199
|
+
if (error.message !== "peer does not provide content") {
|
|
200
|
+
console.warn(`Provider discovery failed for ${id}:`, error?.message ?? error);
|
|
201
|
+
}
|
|
202
|
+
throw error;
|
|
203
|
+
} finally {
|
|
204
|
+
clearTimeout(timeout);
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
if (requests.length === 0) return;
|
|
208
|
+
try {
|
|
209
|
+
await Promise.any(requests);
|
|
210
|
+
} catch (error) {
|
|
211
|
+
if (!(error instanceof AggregateError)) throw error;
|
|
212
|
+
console.warn(`No connected provider found for ${hash}`);
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
const requestData = peernet.requestData.bind(peernet);
|
|
216
|
+
peernet.requestData = async (hash, store, options) => {
|
|
217
|
+
const storeName = typeof store === "string" ? store : store?.name;
|
|
218
|
+
if (!isChainStore(storeName)) {
|
|
219
|
+
return requestData(hash, store, options);
|
|
220
|
+
}
|
|
221
|
+
const probe = await peernet.prepareMessage(new peernet.protos["peernet-dht"]({ hash, store: storeName }));
|
|
222
|
+
const request = await peernet.prepareMessage(new peernet.protos["peernet-data"]({ hash, store: storeName }));
|
|
223
|
+
const connections = peernet.connections;
|
|
224
|
+
const requests = Object.entries(connections).filter(
|
|
225
|
+
([id, peer]) => id !== peernet.id && peer.connected
|
|
226
|
+
).map(async ([id, peer]) => {
|
|
227
|
+
let timeout;
|
|
228
|
+
try {
|
|
229
|
+
const fetch = async () => {
|
|
230
|
+
const availability = await peer.request(probe.encoded);
|
|
231
|
+
if (!(availability instanceof Uint8Array)) throw new TypeError("Peer response must be Uint8Array");
|
|
232
|
+
const probeBytes = availability;
|
|
233
|
+
if (new Codec(probeBytes).name !== "peernet-dht-response") throw new Error("invalid provider response codec");
|
|
234
|
+
const provider = new peernet.protos["peernet-dht-response"](probeBytes).decoded;
|
|
235
|
+
if (provider.hash !== hash || !provider.has) throw new Error("peer does not provide content in requested store");
|
|
236
|
+
const result = await peer.request(request.encoded);
|
|
237
|
+
const bytes = result instanceof Uint8Array ? result : new Uint8Array(Object.values(result));
|
|
238
|
+
if (new Codec(bytes).name !== "peernet-data-response") throw new Error("invalid data response codec");
|
|
239
|
+
const response = new peernet.protos["peernet-data-response"](bytes).decoded;
|
|
240
|
+
if (response.hash !== hash || !(response.data instanceof Uint8Array) || response.data.length === 0) {
|
|
241
|
+
throw new Error("invalid content response");
|
|
242
|
+
}
|
|
243
|
+
return response.data;
|
|
244
|
+
};
|
|
245
|
+
return await Promise.race([
|
|
246
|
+
fetch(),
|
|
247
|
+
new Promise((_, reject) => {
|
|
248
|
+
timeout = setTimeout(() => reject(new Error(`content request timed out for ${id}`)), requestTimeout);
|
|
249
|
+
})
|
|
250
|
+
]);
|
|
251
|
+
} finally {
|
|
252
|
+
clearTimeout(timeout);
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
try {
|
|
256
|
+
return await Promise.any(requests);
|
|
257
|
+
} catch (error) {
|
|
258
|
+
throw new Error(`Content unavailable in ${storeName}: ${hash}`, { cause: error });
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
};
|
|
133
262
|
const isSendablePeer = (peer) => {
|
|
134
263
|
if (!peer || typeof peer !== "object") return false;
|
|
135
264
|
const candidate = peer;
|
|
@@ -451,4 +580,4 @@ class ConnectionMonitor {
|
|
|
451
580
|
}
|
|
452
581
|
}
|
|
453
582
|
|
|
454
|
-
export { BlockMessage as B, ConnectionMonitor as C, DEFAULT_NODE_OPTIONS as D, LastBlockMessage as L,
|
|
583
|
+
export { BlockMessage as B, ConnectionMonitor as C, DEFAULT_NODE_OPTIONS as D, LastBlockMessage as L, Protocol as P, REACHED_ONE_ZERO_ZERO as R, StateMessage as S, ValidatorMessage as V, PROTOCOL_VERSION as a, BWMessage as b, guardProviderDiscovery as c, guardPeerMessages as g };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { M as MultiWallet, e as encrypt, b as base58$1 } from './node-browser-
|
|
2
|
-
import './browser-crypto-
|
|
3
|
-
import './connection-monitor-
|
|
1
|
+
import { M as MultiWallet, e as encrypt, b as base58$1 } from './node-browser-BmyPBkL5.js';
|
|
2
|
+
import './browser-crypto-B_UJguhk.js';
|
|
3
|
+
import './connection-monitor-BzbeYGEt.js';
|
|
4
4
|
import './index-CvKt4UDE.js';
|
|
5
5
|
import './sha2-BKcEJzgd.js';
|
|
6
6
|
|