@inversealtruism/cairnx-core 0.2.8 → 0.2.9
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/CHANGELOG.md +22 -0
- package/CONVENTION.md +22 -0
- package/README.md +4 -0
- package/dist/index.cjs +62 -19
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +62 -19
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## Unreleased
|
|
4
|
+
|
|
5
|
+
- The replay runs as a fold (one step per event, an end at the tip that alone reads the tip) and its expiry sweep
|
|
6
|
+
applies each expiry at the first height it is due, one batch per such height in ascending order, where 0.2.8 applied
|
|
7
|
+
every due expiry in one batch before each event; it does so only while each event height and the tip it has read is
|
|
8
|
+
a safe integer, and from the first value outside that domain (an input no chain produces) it runs one batch per
|
|
9
|
+
sweep, as 0.2.8 does. No rule changed. For inputs made of plain values (what JSON carries) 0.2.9 returns what 0.2.8
|
|
10
|
+
returns, and throws where 0.2.8 throws: derived in CONVENTION.md section 5 and checked by
|
|
11
|
+
`scripts/seal-differential.mjs`, which finds the whole result, codes and moves included, identical to npm's 0.2.8 on
|
|
12
|
+
each input of its differential, among them 3,000 sequences built so that offers, bids, reservations and recapture
|
|
13
|
+
reservations end between events, 3,000 whose heights, expiries and tips no chain produces (numbers that are not safe
|
|
14
|
+
integers, strings, null, booleans, arrays, objects, and also undefined and BigInts) and a dense walk of 1,699,031
|
|
15
|
+
tips. Outside plain values two inputs are known to differ: an event whose `height` is a getter that answers
|
|
16
|
+
differently on later reads (0.2.8 applies the event, 0.2.9 skips it, since the fold reads the height once more), and
|
|
17
|
+
an events array with an `undefined` entry after an event whose handler throws (both throw a TypeError, with another
|
|
18
|
+
text; `test/fold.test.ts`). Heights and the tip are consensus only as a chain produces them, non-negative integers
|
|
19
|
+
below 2^53: outside that, released cores answer differently (0.2.4 and 0.2.7 on a string height), so a caller checks
|
|
20
|
+
them before the call. No export changed. `conformance/fuzz-resolve.mjs` checks the property of section 5 in the
|
|
21
|
+
Python reference by adding events that write nothing, and gains `--expiry` and `--malformed` with a floor per kind
|
|
22
|
+
and per type; `test/sweep.test.ts` pins twelve constructed streams; check mode asserts that each expiry lands at the
|
|
23
|
+
first height it is due.
|
|
24
|
+
|
|
3
25
|
## 0.2.8
|
|
4
26
|
|
|
5
27
|
- Token moves in the applied log (CONVENTION section 41, no gate): an applied mint, transfer or fill that moved tokens
|
package/CONVENTION.md
CHANGED
|
@@ -230,6 +230,28 @@ epoch. For an offer or bid anchored below V22 that sweep applies the §24 cap on
|
|
|
230
230
|
(40 100), that is from tip 40 099 on. A name's `expired` (§17) is read at the tip's own epoch: it is present when
|
|
231
231
|
`epochOf(tipHeight) > paidThroughEpoch + NAME_GRACE_EPOCHS`.
|
|
232
232
|
|
|
233
|
+
For the heights a chain produces (block heights, non-negative integers below 2^53) the state at a tip does not depend
|
|
234
|
+
on the heights at which sweeps ran between events: an item only becomes due as the height grows, whether it is due
|
|
235
|
+
reads that item alone, and an expiry writes the item's status and what it releases (an addition to one seller's
|
|
236
|
+
balance, or the unlock of one name) or deletes one reservation. A resolver may apply each expiry at the first height
|
|
237
|
+
it is due, or every due expiry before each event, as cairnx-core 0.2.8 and the Python reference do. So an event that
|
|
238
|
+
writes nothing (§40.1) changes no state: at most it adds a sweep at its height and runs the flush of the previous
|
|
239
|
+
block's deferred cancels (§16) that the next event at a new height would run before its own sweep; below activation,
|
|
240
|
+
or repeated at V29 or above, it adds neither.
|
|
241
|
+
|
|
242
|
+
`resolve()` takes heights and tips of any value, and outside that domain the heights at which sweeps run can matter:
|
|
243
|
+
an offer whose event height is NaN has a NaN cap (§24) from V21 on, so it is due below V21 and at no height from V21
|
|
244
|
+
on, and a commit at the string height "90000" gives a reservation the deadline "90000820", which a sweep compares as
|
|
245
|
+
text at a string height and as a number at a number one. cairnx-core from 0.2.9 applies each expiry at the first
|
|
246
|
+
height it is due only while every event height and the tip it has read is a safe integer (`Number.isSafeInteger`).
|
|
247
|
+
Inside that domain being due only grows with height, so batches at the due heights give the state of one batch per
|
|
248
|
+
sweep; the first height or tip outside it ends the batches before any sweep reads it; from then on every sweep is the
|
|
249
|
+
one before each event and at `tipHeight + 1`, as in 0.2.8. That gives the state 0.2.8 gives for inputs made of plain
|
|
250
|
+
values (what JSON carries); a getter or a conversion with side effects, which the fold reads a different number of
|
|
251
|
+
times, is outside that statement. Outside the domain the result is not consensus: released cores have answered
|
|
252
|
+
differently (0.2.4 and 0.2.7 on a string height), so a caller checks that event heights and the tip are safe integers
|
|
253
|
+
before the call.
|
|
254
|
+
|
|
233
255
|
**Canonical state (format 2, normative):** the canonical surface is
|
|
234
256
|
`{tipHeight, tokens, balances, names, offers, bids, feesPaid}`: the event log is excluded.
|
|
235
257
|
Serialization is **canonical JSON** in the state form of §5.1: object keys sorted in ordinal (code-unit) order at every
|
package/README.md
CHANGED
|
@@ -318,6 +318,10 @@ const state = resolve(events, tipHeight);
|
|
|
318
318
|
console.log(state.names, state.tokens.CAIRN, state.balances.CAIRN);
|
|
319
319
|
```
|
|
320
320
|
|
|
321
|
+
For inputs made of plain values (what JSON carries), a release that changes no rule (`CONSENSUS_CHANGES.md`) returns
|
|
322
|
+
what the previous core returned and throws where it threw, and only event heights and a tip that are safe integers,
|
|
323
|
+
as a chain produces them, are consensus, so check both before the call (`CONVENTION.md` section 5).
|
|
324
|
+
|
|
321
325
|
### What a resolver result proves
|
|
322
326
|
|
|
323
327
|
- Display: an answer read from someone's API. It is worth the trust you place in that API.
|
package/dist/index.cjs
CHANGED
|
@@ -977,6 +977,10 @@ var MinQueue = class {
|
|
|
977
977
|
get size() {
|
|
978
978
|
return this.ids.length;
|
|
979
979
|
}
|
|
980
|
+
/** The smallest stored key, or undefined when the queue is empty. */
|
|
981
|
+
peekKey() {
|
|
982
|
+
return this.keys[0];
|
|
983
|
+
}
|
|
980
984
|
/** Adds an entry. A NaN key is not stored: no comparison with NaN is true, so such an item is never due. */
|
|
981
985
|
push(key, id) {
|
|
982
986
|
if (key !== key) return;
|
|
@@ -1062,6 +1066,7 @@ function createStore(opts = {}) {
|
|
|
1062
1066
|
s.add(v);
|
|
1063
1067
|
};
|
|
1064
1068
|
const regimeHeight = () => maxSweep >= V21_HEIGHT ? V21_HEIGHT : V21_HEIGHT - 1;
|
|
1069
|
+
let splitSweep = true;
|
|
1065
1070
|
const addOffer = (o) => {
|
|
1066
1071
|
if (!offers.has(o.id)) offerAt.set(o.id, ++stamp);
|
|
1067
1072
|
offers.set(o.id, o);
|
|
@@ -1202,11 +1207,27 @@ function createStore(opts = {}) {
|
|
|
1202
1207
|
stats.visits += popped.length;
|
|
1203
1208
|
return [...new Set(popped)].filter(isDue).sort((a, b) => at.get(a) - at.get(b));
|
|
1204
1209
|
};
|
|
1210
|
+
const nextDue = () => {
|
|
1211
|
+
let d = maxSweep >= V21_HEIGHT ? Infinity : V21_HEIGHT;
|
|
1212
|
+
const ko = offerQ.peekKey(), kb = bidQ.peekKey(), kn = nameQ.peekKey(), kr = recaptureQ.peekKey();
|
|
1213
|
+
if (ko !== void 0) d = Math.min(d, (ko + 1) * import_csd_codec.EPOCH_LEN);
|
|
1214
|
+
if (kb !== void 0) d = Math.min(d, (kb + 1) * import_csd_codec.EPOCH_LEN);
|
|
1215
|
+
if (kn !== void 0) d = Math.min(d, kn + 1);
|
|
1216
|
+
if (kr !== void 0) d = Math.min(d, kr + 1);
|
|
1217
|
+
return d;
|
|
1218
|
+
};
|
|
1205
1219
|
const sweep = (height, expireOffer) => {
|
|
1206
1220
|
if (!(height >= maxSweep)) {
|
|
1207
1221
|
walkSweep(height, expireOffer);
|
|
1208
1222
|
return;
|
|
1209
1223
|
}
|
|
1224
|
+
if (splitSweep) for (let d = nextDue(); d < height; d = nextDue()) {
|
|
1225
|
+
if (!(d > maxSweep)) break;
|
|
1226
|
+
sweepAt(d, expireOffer);
|
|
1227
|
+
}
|
|
1228
|
+
sweepAt(height, expireOffer);
|
|
1229
|
+
};
|
|
1230
|
+
const sweepAt = (height, expireOffer) => {
|
|
1210
1231
|
if (!(maxSweep >= V21_HEIGHT) && height >= V21_HEIGHT) {
|
|
1211
1232
|
stats.visits += openOffers.size + openBids.size;
|
|
1212
1233
|
for (const id of openOffers) {
|
|
@@ -1233,6 +1254,13 @@ function createStore(opts = {}) {
|
|
|
1233
1254
|
same(`expired bids at ${height}`, dueBids, want.bids);
|
|
1234
1255
|
same(`expired reservations at ${height}`, dueNames, want.names);
|
|
1235
1256
|
same(`expired recaptures at ${height}`, dueRecaptures, want.recaptures);
|
|
1257
|
+
const early = !splitSweep ? [] : [
|
|
1258
|
+
...dueOffers.filter((id) => offerDue(offers.get(id), height - 1)),
|
|
1259
|
+
...dueBids.filter((id) => bidDue(bids.get(id), height - 1)),
|
|
1260
|
+
...dueNames.filter((nm) => nameDue(names.get(nm), height - 1)),
|
|
1261
|
+
...dueRecaptures.filter((nm) => height - 1 > recaptures.get(nm).finalizeBy)
|
|
1262
|
+
];
|
|
1263
|
+
if (early.length) throw new Error(`replay index check: expired at ${height}, due before it: ${early.join(", ")}`);
|
|
1236
1264
|
}
|
|
1237
1265
|
for (const id of dueOffers) {
|
|
1238
1266
|
const o = offers.get(id);
|
|
@@ -1382,6 +1410,9 @@ function createStore(opts = {}) {
|
|
|
1382
1410
|
putRecapture,
|
|
1383
1411
|
deleteRecapture,
|
|
1384
1412
|
sweep,
|
|
1413
|
+
endSplit: () => {
|
|
1414
|
+
splitSweep = false;
|
|
1415
|
+
},
|
|
1385
1416
|
pendingCount,
|
|
1386
1417
|
recaptureCount,
|
|
1387
1418
|
liveHoldCount,
|
|
@@ -1993,27 +2024,31 @@ function resolve(events, tipHeight) {
|
|
|
1993
2024
|
return replay(events, tipHeight);
|
|
1994
2025
|
}
|
|
1995
2026
|
function replay(events, tipHeight, opts = {}) {
|
|
1996
|
-
const
|
|
2027
|
+
const fold = createFold(opts);
|
|
2028
|
+
for (const e of [...events].sort(applyOrder)) fold.apply(e);
|
|
2029
|
+
return fold.finish(tipHeight);
|
|
2030
|
+
}
|
|
2031
|
+
function createFold(opts) {
|
|
1997
2032
|
const seenIds = /* @__PURE__ */ new Set();
|
|
1998
|
-
const applied = [];
|
|
1999
|
-
for (const e of ordered) {
|
|
2000
|
-
if (e.height >= V29_HEIGHT) {
|
|
2001
|
-
const k = eventId(e);
|
|
2002
|
-
if (seenIds.has(k)) continue;
|
|
2003
|
-
seenIds.add(k);
|
|
2004
|
-
}
|
|
2005
|
-
applied.push(e);
|
|
2006
|
-
}
|
|
2007
2033
|
const store = createStore(opts);
|
|
2008
2034
|
const c = createContext(store);
|
|
2009
|
-
const {
|
|
2035
|
+
const { refused, sweepExpired } = c;
|
|
2010
2036
|
let pendingBlock = -1;
|
|
2011
2037
|
const applyPendingCancels = () => {
|
|
2012
2038
|
for (const f of c.pendingCancels) f();
|
|
2013
2039
|
c.pendingCancels = [];
|
|
2014
2040
|
};
|
|
2015
|
-
|
|
2016
|
-
if (
|
|
2041
|
+
const inDomain = (height) => {
|
|
2042
|
+
if (!Number.isSafeInteger(height)) store.endSplit();
|
|
2043
|
+
};
|
|
2044
|
+
const apply = (ev) => {
|
|
2045
|
+
inDomain(ev.height);
|
|
2046
|
+
if (ev.height >= V29_HEIGHT) {
|
|
2047
|
+
const k = eventId(ev);
|
|
2048
|
+
if (seenIds.has(k)) return;
|
|
2049
|
+
seenIds.add(k);
|
|
2050
|
+
}
|
|
2051
|
+
if (beforeActivation(ev.height)) return;
|
|
2017
2052
|
if (ev.height !== pendingBlock) {
|
|
2018
2053
|
applyPendingCancels();
|
|
2019
2054
|
pendingBlock = ev.height;
|
|
@@ -2025,7 +2060,7 @@ function replay(events, tipHeight, opts = {}) {
|
|
|
2025
2060
|
const parsed = explainRecord(ev.uri, ev.payloadHash);
|
|
2026
2061
|
if (!parsed.ok) {
|
|
2027
2062
|
refused(ev, ev.id, "invalid", parsed.code, "unparseable/non-canonical record");
|
|
2028
|
-
|
|
2063
|
+
return;
|
|
2029
2064
|
}
|
|
2030
2065
|
const rec = parsed.record;
|
|
2031
2066
|
const who = ev.proposer.toLowerCase();
|
|
@@ -2079,10 +2114,18 @@ function replay(events, tipHeight, opts = {}) {
|
|
|
2079
2114
|
} else {
|
|
2080
2115
|
applyAttest(c, ev);
|
|
2081
2116
|
}
|
|
2082
|
-
}
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2117
|
+
};
|
|
2118
|
+
const finish = (tipHeight) => {
|
|
2119
|
+
applyPendingCancels();
|
|
2120
|
+
inDomain(tipHeight);
|
|
2121
|
+
sweepExpired(tipHeight + 1);
|
|
2122
|
+
store.verify(tipHeight + 1, true);
|
|
2123
|
+
return materialize(c, tipHeight);
|
|
2124
|
+
};
|
|
2125
|
+
return { apply, finish };
|
|
2126
|
+
}
|
|
2127
|
+
function materialize(c, tipHeight) {
|
|
2128
|
+
const { tokens, balances, names, recaptures, offers, bids, fclaims, log } = c;
|
|
2086
2129
|
const tokensOut = {};
|
|
2087
2130
|
for (const [t, tok] of [...tokens.entries()].sort(([a], [b]) => ord(a, b))) tokensOut[t] = { ...tok.meta, minted: tok.minted.toString() };
|
|
2088
2131
|
const balancesOut = {};
|
|
@@ -2330,7 +2373,7 @@ function nameView(names, name) {
|
|
|
2330
2373
|
}
|
|
2331
2374
|
|
|
2332
2375
|
// src/version.ts
|
|
2333
|
-
var CAIRNX_CORE_VERSION = "0.2.
|
|
2376
|
+
var CAIRNX_CORE_VERSION = "0.2.9";
|
|
2334
2377
|
|
|
2335
2378
|
// src/gates.ts
|
|
2336
2379
|
var GATE_HEIGHTS = Object.freeze({
|
package/dist/index.d.cts
CHANGED
|
@@ -604,9 +604,9 @@ declare function eventId(e: ChainEvent): string;
|
|
|
604
604
|
* Outside that domain the result is unspecified: a NaN key compares as equal. */
|
|
605
605
|
declare function applyOrder(a: ChainEvent, b: ChainEvent): number;
|
|
606
606
|
declare function resolve(events: ChainEvent[], tipHeight: number): CairnXState;
|
|
607
|
-
/** Canonical serialization of state (FORMAT 2)
|
|
607
|
+
/** Canonical serialization of state (FORMAT 2): byte-identical across honest resolvers.
|
|
608
608
|
* The canonical surface is the DATA ONLY: {tipHeight, tokens, balances, names, offers, bids,
|
|
609
|
-
* feesPaid}. The applied-event log is deliberately EXCLUDED
|
|
609
|
+
* feesPaid}. The applied-event log is deliberately EXCLUDED: its free-text reason strings are
|
|
610
610
|
* implementation diagnostics, and making them normative would force every third-party resolver
|
|
611
611
|
* to reproduce English prose byte-for-byte. (Format 1, pre-2026-06-12, included the log and
|
|
612
612
|
* sorted with localeCompare; pinned format-1 hashes live in test/vectors/replay-hashes.json
|
|
@@ -862,7 +862,7 @@ declare function nameView(names: Record<string, NameState>, name: string): NameV
|
|
|
862
862
|
|
|
863
863
|
/** This package's version, for a host that names the core it loaded (cairnx-api's `rev`, a replica's report). Equal to
|
|
864
864
|
* package.json's version (test/version.test.ts). */
|
|
865
|
-
declare const CAIRNX_CORE_VERSION = "0.2.
|
|
865
|
+
declare const CAIRNX_CORE_VERSION = "0.2.9";
|
|
866
866
|
|
|
867
867
|
/** Gate name to height: `ACTIVATION_HEIGHT` and each `V<n>_HEIGHT`, frozen. test/gates.test.ts keeps it equal to the
|
|
868
868
|
* individual exports and complete. It leaves out the one other exported height, `LEGACY_HOLD_SUNSET_HEIGHT`, which is
|
package/dist/index.d.ts
CHANGED
|
@@ -604,9 +604,9 @@ declare function eventId(e: ChainEvent): string;
|
|
|
604
604
|
* Outside that domain the result is unspecified: a NaN key compares as equal. */
|
|
605
605
|
declare function applyOrder(a: ChainEvent, b: ChainEvent): number;
|
|
606
606
|
declare function resolve(events: ChainEvent[], tipHeight: number): CairnXState;
|
|
607
|
-
/** Canonical serialization of state (FORMAT 2)
|
|
607
|
+
/** Canonical serialization of state (FORMAT 2): byte-identical across honest resolvers.
|
|
608
608
|
* The canonical surface is the DATA ONLY: {tipHeight, tokens, balances, names, offers, bids,
|
|
609
|
-
* feesPaid}. The applied-event log is deliberately EXCLUDED
|
|
609
|
+
* feesPaid}. The applied-event log is deliberately EXCLUDED: its free-text reason strings are
|
|
610
610
|
* implementation diagnostics, and making them normative would force every third-party resolver
|
|
611
611
|
* to reproduce English prose byte-for-byte. (Format 1, pre-2026-06-12, included the log and
|
|
612
612
|
* sorted with localeCompare; pinned format-1 hashes live in test/vectors/replay-hashes.json
|
|
@@ -862,7 +862,7 @@ declare function nameView(names: Record<string, NameState>, name: string): NameV
|
|
|
862
862
|
|
|
863
863
|
/** This package's version, for a host that names the core it loaded (cairnx-api's `rev`, a replica's report). Equal to
|
|
864
864
|
* package.json's version (test/version.test.ts). */
|
|
865
|
-
declare const CAIRNX_CORE_VERSION = "0.2.
|
|
865
|
+
declare const CAIRNX_CORE_VERSION = "0.2.9";
|
|
866
866
|
|
|
867
867
|
/** Gate name to height: `ACTIVATION_HEIGHT` and each `V<n>_HEIGHT`, frozen. test/gates.test.ts keeps it equal to the
|
|
868
868
|
* individual exports and complete. It leaves out the one other exported height, `LEGACY_HOLD_SUNSET_HEIGHT`, which is
|
package/dist/index.js
CHANGED
|
@@ -774,6 +774,10 @@ var MinQueue = class {
|
|
|
774
774
|
get size() {
|
|
775
775
|
return this.ids.length;
|
|
776
776
|
}
|
|
777
|
+
/** The smallest stored key, or undefined when the queue is empty. */
|
|
778
|
+
peekKey() {
|
|
779
|
+
return this.keys[0];
|
|
780
|
+
}
|
|
777
781
|
/** Adds an entry. A NaN key is not stored: no comparison with NaN is true, so such an item is never due. */
|
|
778
782
|
push(key, id) {
|
|
779
783
|
if (key !== key) return;
|
|
@@ -859,6 +863,7 @@ function createStore(opts = {}) {
|
|
|
859
863
|
s.add(v);
|
|
860
864
|
};
|
|
861
865
|
const regimeHeight = () => maxSweep >= V21_HEIGHT ? V21_HEIGHT : V21_HEIGHT - 1;
|
|
866
|
+
let splitSweep = true;
|
|
862
867
|
const addOffer = (o) => {
|
|
863
868
|
if (!offers.has(o.id)) offerAt.set(o.id, ++stamp);
|
|
864
869
|
offers.set(o.id, o);
|
|
@@ -999,11 +1004,27 @@ function createStore(opts = {}) {
|
|
|
999
1004
|
stats.visits += popped.length;
|
|
1000
1005
|
return [...new Set(popped)].filter(isDue).sort((a, b) => at.get(a) - at.get(b));
|
|
1001
1006
|
};
|
|
1007
|
+
const nextDue = () => {
|
|
1008
|
+
let d = maxSweep >= V21_HEIGHT ? Infinity : V21_HEIGHT;
|
|
1009
|
+
const ko = offerQ.peekKey(), kb = bidQ.peekKey(), kn = nameQ.peekKey(), kr = recaptureQ.peekKey();
|
|
1010
|
+
if (ko !== void 0) d = Math.min(d, (ko + 1) * EPOCH_LEN);
|
|
1011
|
+
if (kb !== void 0) d = Math.min(d, (kb + 1) * EPOCH_LEN);
|
|
1012
|
+
if (kn !== void 0) d = Math.min(d, kn + 1);
|
|
1013
|
+
if (kr !== void 0) d = Math.min(d, kr + 1);
|
|
1014
|
+
return d;
|
|
1015
|
+
};
|
|
1002
1016
|
const sweep = (height, expireOffer) => {
|
|
1003
1017
|
if (!(height >= maxSweep)) {
|
|
1004
1018
|
walkSweep(height, expireOffer);
|
|
1005
1019
|
return;
|
|
1006
1020
|
}
|
|
1021
|
+
if (splitSweep) for (let d = nextDue(); d < height; d = nextDue()) {
|
|
1022
|
+
if (!(d > maxSweep)) break;
|
|
1023
|
+
sweepAt(d, expireOffer);
|
|
1024
|
+
}
|
|
1025
|
+
sweepAt(height, expireOffer);
|
|
1026
|
+
};
|
|
1027
|
+
const sweepAt = (height, expireOffer) => {
|
|
1007
1028
|
if (!(maxSweep >= V21_HEIGHT) && height >= V21_HEIGHT) {
|
|
1008
1029
|
stats.visits += openOffers.size + openBids.size;
|
|
1009
1030
|
for (const id of openOffers) {
|
|
@@ -1030,6 +1051,13 @@ function createStore(opts = {}) {
|
|
|
1030
1051
|
same(`expired bids at ${height}`, dueBids, want.bids);
|
|
1031
1052
|
same(`expired reservations at ${height}`, dueNames, want.names);
|
|
1032
1053
|
same(`expired recaptures at ${height}`, dueRecaptures, want.recaptures);
|
|
1054
|
+
const early = !splitSweep ? [] : [
|
|
1055
|
+
...dueOffers.filter((id) => offerDue(offers.get(id), height - 1)),
|
|
1056
|
+
...dueBids.filter((id) => bidDue(bids.get(id), height - 1)),
|
|
1057
|
+
...dueNames.filter((nm) => nameDue(names.get(nm), height - 1)),
|
|
1058
|
+
...dueRecaptures.filter((nm) => height - 1 > recaptures.get(nm).finalizeBy)
|
|
1059
|
+
];
|
|
1060
|
+
if (early.length) throw new Error(`replay index check: expired at ${height}, due before it: ${early.join(", ")}`);
|
|
1033
1061
|
}
|
|
1034
1062
|
for (const id of dueOffers) {
|
|
1035
1063
|
const o = offers.get(id);
|
|
@@ -1179,6 +1207,9 @@ function createStore(opts = {}) {
|
|
|
1179
1207
|
putRecapture,
|
|
1180
1208
|
deleteRecapture,
|
|
1181
1209
|
sweep,
|
|
1210
|
+
endSplit: () => {
|
|
1211
|
+
splitSweep = false;
|
|
1212
|
+
},
|
|
1182
1213
|
pendingCount,
|
|
1183
1214
|
recaptureCount,
|
|
1184
1215
|
liveHoldCount,
|
|
@@ -1790,27 +1821,31 @@ function resolve(events, tipHeight) {
|
|
|
1790
1821
|
return replay(events, tipHeight);
|
|
1791
1822
|
}
|
|
1792
1823
|
function replay(events, tipHeight, opts = {}) {
|
|
1793
|
-
const
|
|
1824
|
+
const fold = createFold(opts);
|
|
1825
|
+
for (const e of [...events].sort(applyOrder)) fold.apply(e);
|
|
1826
|
+
return fold.finish(tipHeight);
|
|
1827
|
+
}
|
|
1828
|
+
function createFold(opts) {
|
|
1794
1829
|
const seenIds = /* @__PURE__ */ new Set();
|
|
1795
|
-
const applied = [];
|
|
1796
|
-
for (const e of ordered) {
|
|
1797
|
-
if (e.height >= V29_HEIGHT) {
|
|
1798
|
-
const k = eventId(e);
|
|
1799
|
-
if (seenIds.has(k)) continue;
|
|
1800
|
-
seenIds.add(k);
|
|
1801
|
-
}
|
|
1802
|
-
applied.push(e);
|
|
1803
|
-
}
|
|
1804
1830
|
const store = createStore(opts);
|
|
1805
1831
|
const c = createContext(store);
|
|
1806
|
-
const {
|
|
1832
|
+
const { refused, sweepExpired } = c;
|
|
1807
1833
|
let pendingBlock = -1;
|
|
1808
1834
|
const applyPendingCancels = () => {
|
|
1809
1835
|
for (const f of c.pendingCancels) f();
|
|
1810
1836
|
c.pendingCancels = [];
|
|
1811
1837
|
};
|
|
1812
|
-
|
|
1813
|
-
if (
|
|
1838
|
+
const inDomain = (height) => {
|
|
1839
|
+
if (!Number.isSafeInteger(height)) store.endSplit();
|
|
1840
|
+
};
|
|
1841
|
+
const apply = (ev) => {
|
|
1842
|
+
inDomain(ev.height);
|
|
1843
|
+
if (ev.height >= V29_HEIGHT) {
|
|
1844
|
+
const k = eventId(ev);
|
|
1845
|
+
if (seenIds.has(k)) return;
|
|
1846
|
+
seenIds.add(k);
|
|
1847
|
+
}
|
|
1848
|
+
if (beforeActivation(ev.height)) return;
|
|
1814
1849
|
if (ev.height !== pendingBlock) {
|
|
1815
1850
|
applyPendingCancels();
|
|
1816
1851
|
pendingBlock = ev.height;
|
|
@@ -1822,7 +1857,7 @@ function replay(events, tipHeight, opts = {}) {
|
|
|
1822
1857
|
const parsed = explainRecord(ev.uri, ev.payloadHash);
|
|
1823
1858
|
if (!parsed.ok) {
|
|
1824
1859
|
refused(ev, ev.id, "invalid", parsed.code, "unparseable/non-canonical record");
|
|
1825
|
-
|
|
1860
|
+
return;
|
|
1826
1861
|
}
|
|
1827
1862
|
const rec = parsed.record;
|
|
1828
1863
|
const who = ev.proposer.toLowerCase();
|
|
@@ -1876,10 +1911,18 @@ function replay(events, tipHeight, opts = {}) {
|
|
|
1876
1911
|
} else {
|
|
1877
1912
|
applyAttest(c, ev);
|
|
1878
1913
|
}
|
|
1879
|
-
}
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1914
|
+
};
|
|
1915
|
+
const finish = (tipHeight) => {
|
|
1916
|
+
applyPendingCancels();
|
|
1917
|
+
inDomain(tipHeight);
|
|
1918
|
+
sweepExpired(tipHeight + 1);
|
|
1919
|
+
store.verify(tipHeight + 1, true);
|
|
1920
|
+
return materialize(c, tipHeight);
|
|
1921
|
+
};
|
|
1922
|
+
return { apply, finish };
|
|
1923
|
+
}
|
|
1924
|
+
function materialize(c, tipHeight) {
|
|
1925
|
+
const { tokens, balances, names, recaptures, offers, bids, fclaims, log } = c;
|
|
1883
1926
|
const tokensOut = {};
|
|
1884
1927
|
for (const [t, tok] of [...tokens.entries()].sort(([a], [b]) => ord(a, b))) tokensOut[t] = { ...tok.meta, minted: tok.minted.toString() };
|
|
1885
1928
|
const balancesOut = {};
|
|
@@ -2127,7 +2170,7 @@ function nameView(names, name) {
|
|
|
2127
2170
|
}
|
|
2128
2171
|
|
|
2129
2172
|
// src/version.ts
|
|
2130
|
-
var CAIRNX_CORE_VERSION = "0.2.
|
|
2173
|
+
var CAIRNX_CORE_VERSION = "0.2.9";
|
|
2131
2174
|
|
|
2132
2175
|
// src/gates.ts
|
|
2133
2176
|
var GATE_HEIGHTS = Object.freeze({
|