RANK score (score_v1)
score_v1: the time-weighted, saturating score of every RANK subject, from burns only.
score_v1 is the score of a RANK subject on every platform: a Twitter profile, a Nostr note, a local business, an entity. It complements RANK's all-time ranking (the plain net burn, which stays available) with a number that weighs recent votes more than old ones and the first sats burnt on a day more than the next ones. It uses only integers, so two nodes always return byte-identical answers, which the thin-client quorum digests require.
Status: implemented in lotusd 12.5.9 (computed by the RANK module and served by the REST API).
The vectors are src/test/data/rank_score_vectors.json, generated by contrib/rank/gen_rank_vectors.py, the executable form of this page. An implementation is correct only if it reproduces every number in that file.
1. Definition #
For a subject (below), a direction d (support = positive votes, against = negative votes) and a UTC day t, let W(d, t) be the sum of the sats of the indexed votes in that direction whose block time falls on day t. The score evaluated at a block of time T is:
f(W) = W0 · ln(1 + W / W0) saturation of one day's sum
D(a) = 2^(-a / H) decay for a day a days old
S(d) = Σ_t f(W(d, t)) · D(max(0, day(T) - t))day(x) = floor(x / 86400)of a block header time (unix seconds, UTC). A vote counts in the day of the block that confirmed it.- Only daily sums enter: splitting one burn into many records, or merging many into one, never changes the score. Record counts are shown, never weighed.
f(W) ≈ Wfor a day well belowW0, and grows like a logarithm above it: a party burning 1,000 times more than another on one day moves the score far less than 1,000 times more, and has to burn again the next day.Dhalves everyHdays. A day 32·H days old or older weighs exactly 0.- A vote whose day is after
day(T)(block times are not monotonic) is treated as age 0.
Subjects #
| Subject | Votes summed into W |
|---|---|
Profile (platform, profile_id) | every vote on that profile, with or without a post id |
Post (platform, profile_id, post_id) | the votes on that post only |
Entity (platform entity) | the votes of every member of the entity's class: (6, eid), plus (5, sirene-<siret>) for a fr-siret entity (legacy rule, see entity). The class sum is formed before f, per day and direction. |
| Entity in a collection | as the entity, restricted to votes whose post id is the collection's cid |
Answer #
| Field | Value |
|---|---|
support | S(+), integer sats |
against | S(-), integer sats |
pct_num, pct_den | S(+) and S(+) + S(-); the support share is their ratio (undefined when pct_den = 0) |
pct_bp | floor(10000 · S(+) / (S(+) + S(-))), or null when both are 0 |
strength_support_milli, strength_against_milli | floor(1000 · S(d) / U): the score in thousandths of one standard vote |
Every answer that carries a score also carries the evaluation height and the score version score_v1.
2. Integer algorithm #
All values are unsigned integers. Q = 32. Products marked "128" need 128-bit intermediates (C++ unsigned __int128, JS BigInt). Every division and shift truncates (floors).
log2_q32(num, den) #
log2(num / den) in Q32 fixed point, for 0 < den ≤ num < 2^63, by bit-by-bit squaring:
n = bitlen(num) - bitlen(den)
if (den << n) > num: n = n - 1 # den·2^n ≤ num < den·2^(n+1)
y = (num << 62) / (den << n) # 128; y in [2^62, 2^63)
frac = 0
for i = 1 .. 32:
y = (y · y) >> 62 # 128
if y ≥ 2^63:
y = y >> 1
frac = frac | (1 << (32 - i))
return (n << 32) | fracbitlen(x) is the number of significant bits (bitlen(1) = 1).
exp2_neg_q32(e) #
2^(-e / 2^32) in Q32, for e ≥ 0, by a product over the fraction bits:
k = e >> 32
r = e & (2^32 - 1)
acc = 2^62
for i = 1 .. 32:
if r & (1 << (32 - i)):
acc = (acc · C[i]) >> 62 # 128
v = acc >> 30
return k < 64 ? v >> k : 0C[i] = floor(2^(-2^-i) · 2^62) for i = 1..32. The table is part of the specification: it is listed in the vectors (constants.exp2_neg_q62) and must be compiled in, never computed at run time with floating point. The first entries are C[1] = 3260954456333195553, C[2] = 3877950241171266237, C[3] = 4228934724888366667.
f and D #
f(W) = W == 0 ? 0 : (W0 · log2_q32(W0 + W, W0) · LN2_Q32) >> 64 # 128
D(a) = a ≥ 32·H ? 0 : exp2_neg_q32((a << 32) / H) # Q32LN2_Q32 = floor(ln 2 · 2^32) = 2977044471. W is capped so that W0 + W < 2^63; the RANK index stores sats as signed 64-bit integers, so a larger daily sum cannot occur.
S(d) #
S(d) = Σ over days t with W(d,t) > 0: (f(W(d,t)) · D(max(0, day(T) - t))) >> 32 # 128Each term is an integer, so the order of summation does not matter. Days older than 32·H contribute 0 and need not be read.
3. Constants #
| Name | Value | Status |
|---|---|---|
Q | 32 | frozen |
LN2_Q32 | 2977044471 | frozen |
C[1..32] | vectors constants.exp2_neg_q62 | frozen |
SCORE_W0_SATS (W0) | 10,000,000 sats (10 XPI) | OD7 open: provisional, frozen from the Napoleon testnet and phone measurements before 12.5.9 |
SCORE_HALF_LIFE_DAYS (H) | 30 | OD7 open: architect's recommendation |
SCORE_UNIT_SATS (U) | 50,000 sats (0.05 XPI, one standard vote) | OD7 open: provisional |
SCORE_MAX_AGE_DAYS | 32·H = 960 | follows from H |
Changing a constant changes every score: it is a new score version, not an edit. The vector generator takes the constants as parameters, so the vectors are regenerated in the same commit.
4. Vectors #
src/test/data/rank_score_vectors.json sections: constants; log2_q32 (num, den, result); exp2_neg_q32 (e, result); saturate (w, f); decay_q32 (age_days, result); scores (daily inputs day, direction 1 support / 0 against, sats; eval_time; the answer). Large integers are written as decimal strings. Cases cover the empty subject, one vote, 30-day and 959/960-day ages, split invariance (one record of 2·W0 equals two records of W0 on the same day), spreading over days, a vote dated after the evaluation time, and the largest daily sum.
