@inversealtruism/cairnx-core 0.2.8 → 0.2.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/CHANGELOG.md +48 -0
- package/CONVENTION.md +27 -0
- package/README.md +18 -0
- package/dist/index.cjs +300 -155
- package/dist/index.d.cts +32 -4
- package/dist/index.d.ts +32 -4
- package/dist/index.js +293 -151
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,53 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.10
|
|
4
|
+
|
|
5
|
+
- A held replay context: `newReplayContext()` keeps `resolve()`'s fold between tips. `advance(toHeight, events)`
|
|
6
|
+
applies the whole blocks above the context's height, in apply order; `stateAt(t)`, at that height, answers in place.
|
|
7
|
+
It takes an event whose height is a safe integer (`isChainHeight`), whose position is a safe integer >= 0 and whose
|
|
8
|
+
id is a string, as CONVENTION section 33 builds them. For inputs made of plain values (what JSON carries), its answer
|
|
9
|
+
at t is what `resolve()` returns over the same events at t, and an answer handed out earlier does not change later.
|
|
10
|
+
Any other event, and a height or tip outside `isChainHeight`, is refused with a `ReplayContextRefusal` ("domain")
|
|
11
|
+
and the caller replays with `resolve()`. `advance` reads its events once and keeps a one-level copy of each, so a
|
|
12
|
+
write into an event after the call changes no later answer. The other refusals, each thrown before any write:
|
|
13
|
+
"order" (a target below the height, an event at or below it or above the target; a new context stands at -1, so it
|
|
14
|
+
refuses a negative height, which `resolve()` skips below activation), "tip" (an answer off the height), "broken"
|
|
15
|
+
(any call after the replay threw inside `advance` or `stateAt`, where `resolve()` throws too), "sloppy" (a build
|
|
16
|
+
that runs the module in sloppy mode, where a write to a frozen shared part would be dropped instead of throwing). The
|
|
17
|
+
context keeps no earlier state: a reorg that removes an applied block costs one full replay.
|
|
18
|
+
`isChainHeight`, the one domain rule (`Number.isSafeInteger`), is exported and read by `resolve()`'s fold and by the
|
|
19
|
+
context. `resolve()` is unchanged: the seal against 0.2.9 finds its whole result identical over each input of
|
|
20
|
+
0.2.9's proof, and walks a held context through 26,303 of them, 1,270,287 answers each equal to `resolve()`
|
|
21
|
+
(`CONSENSUS_CHANGES.md`). `test/replay-context.test.ts` compares the context with `resolve()` at every height of the
|
|
22
|
+
sweep streams (D, over 284,000 blocks, at its dense tips; the malformed ones until refused), every event height of
|
|
23
|
+
the replay corpus and the growth streams at 500, with answers re-read after later advances and written over. On the
|
|
24
|
+
replay corpus (1,133 events in 774 blocks), advancing one block and answering at it, 774 times, took 2.81 percent of
|
|
25
|
+
the time of a `resolve()` per block (medians of five interleaved runs on a host at load 30 to 40; the build without
|
|
26
|
+
the copy and the position and id checks measured 4.41 percent in the same runs, and the runs' ranges overlap, so the
|
|
27
|
+
two figures do not rank the builds); those checks and the copy alone take 0.108 ms over the whole corpus.
|
|
28
|
+
|
|
29
|
+
## 0.2.9
|
|
30
|
+
|
|
31
|
+
- The replay runs as a fold (one step per event, an end at the tip that alone reads the tip) and its expiry sweep
|
|
32
|
+
applies each expiry at the first height it is due, one batch per such height in ascending order, where 0.2.8 applied
|
|
33
|
+
every due expiry in one batch before each event; it does so only while each event height and the tip it has read is
|
|
34
|
+
a safe integer, and from the first value outside that domain (an input no chain produces) it runs one batch per
|
|
35
|
+
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
|
|
36
|
+
returns, and throws where 0.2.8 throws: derived in CONVENTION.md section 5 and checked by
|
|
37
|
+
`scripts/seal-differential.mjs`, which finds the whole result, codes and moves included, identical to npm's 0.2.8 on
|
|
38
|
+
each input of its differential, among them 3,000 sequences built so that offers, bids, reservations and recapture
|
|
39
|
+
reservations end between events, 3,000 whose heights, expiries and tips no chain produces (numbers that are not safe
|
|
40
|
+
integers, strings, null, booleans, arrays, objects, and also undefined and BigInts) and a dense walk of 1,699,031
|
|
41
|
+
tips. Outside plain values two inputs are known to differ: an event whose `height` is a getter that answers
|
|
42
|
+
differently on later reads (0.2.8 applies the event, 0.2.9 skips it, since the fold reads the height once more), and
|
|
43
|
+
an events array with an `undefined` entry after an event whose handler throws (both throw a TypeError, with another
|
|
44
|
+
text; `test/fold.test.ts`). Heights and the tip are consensus only as a chain produces them, non-negative integers
|
|
45
|
+
below 2^53: outside that, released cores answer differently (0.2.4 and 0.2.7 on a string height), so a caller checks
|
|
46
|
+
them before the call. No export changed. `conformance/fuzz-resolve.mjs` checks the property of section 5 in the
|
|
47
|
+
Python reference by adding events that write nothing, and gains `--expiry` and `--malformed` with a floor per kind
|
|
48
|
+
and per type; `test/sweep.test.ts` pins twelve constructed streams; check mode asserts that each expiry lands at the
|
|
49
|
+
first height it is due.
|
|
50
|
+
|
|
3
51
|
## 0.2.8
|
|
4
52
|
|
|
5
53
|
- 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,33 @@ 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
|
+
|
|
255
|
+
A resolver may also hold its replay between tips and answer in place at the last height it applied, as cairnx-core's
|
|
256
|
+
held context does from 0.2.10: inside the domain its answer at t equals a full replay to t, because the answer's sweep
|
|
257
|
+
at `t + 1` is one more sweep height, and the next block's flush and sweep follow it as they would follow the block
|
|
258
|
+
before; outside the domain the heights at which sweeps run matter, so such a resolver replays in full.
|
|
259
|
+
|
|
233
260
|
**Canonical state (format 2, normative):** the canonical surface is
|
|
234
261
|
`{tipHeight, tokens, balances, names, offers, bids, feesPaid}`: the event log is excluded.
|
|
235
262
|
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,24 @@ 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
|
+
|
|
325
|
+
A replica or a server that answers at each new block can hold the replay instead of rebuilding it: `const ctx =
|
|
326
|
+
newReplayContext()`, then at each new height `h`, `ctx.advance(h, events)` with the events of the blocks above
|
|
327
|
+
`ctx.height` up to `h` (only those: an event at or below `ctx.height` is refused), and `ctx.stateAt(h)`. In the scope
|
|
328
|
+
above, its answer at a height is what `resolve()` returns over the same events there, for every event it takes: one
|
|
329
|
+
whose height is a safe integer (`isChainHeight`), whose position is a safe integer >= 0 and whose id is a string, as
|
|
330
|
+
the rule of `CONVENTION.md` section 33 builds them. It refuses any other event, and a height or tip that
|
|
331
|
+
`isChainHeight` rejects, with a `ReplayContextRefusal` before anything is written, and the caller replays with
|
|
332
|
+
`resolve()`. It keeps a copy of each event's own fields, so a later write into an event already given changes no
|
|
333
|
+
answer. A reorg that removes an applied block means a new context. A new context stands at height -1, below the
|
|
334
|
+
chain's first block, so it refuses a negative height ("order"), which `resolve()` skips below activation. It refuses
|
|
335
|
+
to start in a build that runs it in sloppy mode: it shares frozen parts with the answers it returns and relies on a
|
|
336
|
+
write to a frozen part throwing, so that a write the replay makes there breaks the context instead of being dropped
|
|
337
|
+
silently.
|
|
338
|
+
|
|
321
339
|
### What a resolver result proves
|
|
322
340
|
|
|
323
341
|
- Display: an answer read from someone's API. It is worth the trust you place in that API.
|