Sponsor follow + one network holding tank + Sponsor check (Marty, 2026-10-22, approved 1-3)
Deliberate sponsor changes (tank adoption, dormant-lead rescue, release, adoption window ending, admin edit) are now recorded (sponsorfollow.json: when, how, the sponsor before, origin) and travel on the LinkSpin sync rows as sponsorSetAt/By/PrevEmail/Origin. A deliberate change from LinkSpin is applied here (a clear back to the tank included) only when the member is not bound on the InstantAdPay contract (memberId or wallet on chain), it is newer than our own deliberate change, and both sides agreed before it (or we have no sponsor). Bound, diverged and race cases change nothing and are logged. Race within 15 min: the earlier change wins on both. Ordinary bindings keep the first-platform rule. Accounts with no record behave as before; rows without the new facts hash exactly as before (no resend on deploy). Network tank: rows carry this site's own adoptions of a person; the waiting list hides someone adopted on LinkSpin, the two-adoptions limit counts both sites, the 3-day hold applies to a LinkSpin adoption too, follows close local open adoptions quietly (no chat, mail or feed post). Admin > Members > Sponsor check: shared members whose sponsor differs or is one-sided, each side's when/how, chain binding, and Use InstantAdPay's / Use LinkSpin's sponsor (applied on the other site, refused when bound there). Partner endpoints /api/partner/sponsor-facts and /api/partner/sponsor-apply (same HMAC as the registry rows). Tests: qa/sponsorfollow.test.cjs 27/27, qa/sponsorfollow-e2e.mjs 20/20 (local IAP + local LinkSpin, throwaway data), QA member walk 0 bugs. No sponsor was changed on production. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -5,8 +5,15 @@
|
||||
// hash in DATA_DIR/lssync.json and only changed rows go, 100 per request. Catches anything touch() missed.
|
||||
// LinkSpin upserts the rows and creates shell accounts with their sponsor line, so a new InstantAdPay member is already
|
||||
// "waiting" on LinkSpin before they ever sign in there. Nothing here moves money; the registry is identity + line only.
|
||||
//
|
||||
// Sponsor follow (2026-10-22, sponsorfollow.js): a row also carries sponsorSetAt / sponsorSetBy / sponsorPrevEmail /
|
||||
// sponsorSetOrigin while the account's sponsor is the result of a deliberate change (tank adoption, rescue, release,
|
||||
// window expiry, admin edit), and `tank` (this site's own adoptions of the person: count + the open one, or null).
|
||||
// Rows without those facts hash exactly as before, so nothing is resent on deploy. Until LinkSpin answers proto 2 the
|
||||
// hash of a row carrying the new facts is not recorded, so it is sent again once LinkSpin runs the new code.
|
||||
'use strict';
|
||||
const crypto = require('crypto');
|
||||
const SF = require('./sponsorfollow');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
@@ -20,11 +27,16 @@ function load() { if (state) return state; try { state = JSON.parse(fs.readFileS
|
||||
function save() { try { fs.writeFileSync(FILE(), JSON.stringify(load())); } catch (e) {} }
|
||||
|
||||
function init(deps) { R = deps; load(); }
|
||||
async function rowFor(acct, byRef) {
|
||||
async function rowFor(acct, byRef, tankMap) {
|
||||
const ref = String(acct.sponsorRef || '').toLowerCase(); let sponsorEmail = null;
|
||||
if (ref) { const sp = byRef ? byRef.get(ref) : (await R.accounts.byUsername(ref) || await R.accounts.byCode(ref)); if (sp && sp.email !== acct.email) sponsorEmail = sp.email; }
|
||||
return { email: acct.email, username: acct.username || null, wallet: acct.address || null, sponsorEmail, joinedAt: Number(acct.created) || null, memberId: acct.memberId || null, profile: profileOf(acct) };
|
||||
const row = { email: acct.email, username: acct.username || null, wallet: acct.address || null, sponsorEmail, joinedAt: Number(acct.created) || null, memberId: acct.memberId || null, profile: profileOf(acct) };
|
||||
if (R.follow) Object.assign(row, SF.rowFields(R.follow.get(acct.email), sponsorEmail) || {});
|
||||
const T = R.tank && R.tank();
|
||||
if (T) { try { row.tank = (tankMap ? tankMap.get(String(acct.email).toLowerCase()) : await T.summaryFor(acct.email)) || null; } catch (e) {} }
|
||||
return row;
|
||||
}
|
||||
const carriesNew = r => !!(r.sponsorSetBy || r.tank);
|
||||
// the member's profile travels too (Marty 2026-10-11: no re-typing on LinkSpin; they can change it there later). Avatar as an
|
||||
// absolute https URL so the other property can show it; socials as the parsed {platform: url} object.
|
||||
const PUBLIC = () => String(process.env.PUBLIC_URL || 'https://instantadpay.com').replace(/\/+$/, '');
|
||||
@@ -36,7 +48,7 @@ function profileOf(a) {
|
||||
if (!avatarUrl && !bio && !(socials && Object.keys(socials).length)) return null;
|
||||
return { avatarUrl, bio, socials: socials && Object.keys(socials).length ? socials : null };
|
||||
}
|
||||
const hashOf = r => crypto.createHash('sha1').update([r.username || '', r.wallet || '', r.sponsorEmail || '', r.joinedAt || '', r.memberId || '', r.profile ? JSON.stringify(r.profile) : ''].join('|')).digest('hex').slice(0, 16);
|
||||
const hashOf = r => crypto.createHash('sha1').update([r.username || '', r.wallet || '', r.sponsorEmail || '', r.joinedAt || '', r.memberId || '', r.profile ? JSON.stringify(r.profile) : ''].join('|') + SF.hashExtra(r)).digest('hex').slice(0, 16);
|
||||
|
||||
async function post(rows) {
|
||||
const raw = JSON.stringify({ rows }); const ts = String(Date.now());
|
||||
@@ -48,8 +60,9 @@ async function post(rows) {
|
||||
async function push(rows) {
|
||||
const st = load(); let sent = 0;
|
||||
for (let i = 0; i < rows.length; i += 100) {
|
||||
const chunk = rows.slice(i, i + 100); await post(chunk); sent += chunk.length;
|
||||
for (const r of chunk) st.hashes[r.email] = hashOf(r);
|
||||
const chunk = rows.slice(i, i + 100); const res = await post(chunk); sent += chunk.length;
|
||||
const peerNew = Number(res && res.proto) >= SF.PROTO; if (R.follow) R.follow.setPeer(peerNew ? SF.PROTO : 1);
|
||||
for (const r of chunk) { if (peerNew || !carriesNew(r)) st.hashes[r.email] = hashOf(r); } // an old LinkSpin ignored the new facts: send again later
|
||||
}
|
||||
st.pushed += sent; st.last = { at: Date.now(), rows: sent }; save(); return sent;
|
||||
}
|
||||
@@ -65,7 +78,8 @@ async function tick(force) {
|
||||
try {
|
||||
const all = await R.accounts.listAll(50000, { shells: true }); const st = load();
|
||||
const byRef = new Map(); for (const a of all) { if (a.username) byRef.set(String(a.username).toLowerCase(), a); if (a.code) byRef.set(String(a.code).toLowerCase(), a); }
|
||||
const rows = []; for (const a of all) { if (!a.email || muted.has(a.email)) continue; const r = await rowFor(a, byRef); if (force || st.hashes[r.email] !== hashOf(r)) rows.push(r); }
|
||||
const T = R.tank && R.tank(); let tankMap = null; if (T) { try { tankMap = await T.summaryMap(); } catch (e) { tankMap = null; } }
|
||||
const rows = []; for (const a of all) { if (!a.email || muted.has(a.email)) continue; const r = await rowFor(a, byRef, tankMap || (T ? new Map() : null)); if (force || st.hashes[r.email] !== hashOf(r)) rows.push(r); }
|
||||
const sent = rows.length ? await push(rows) : 0;
|
||||
return { accounts: all.length, changed: rows.length, sent };
|
||||
} catch (e) { load().errors++; save(); console.error('lssync tick', e.message); return { error: e.message }; }
|
||||
@@ -82,7 +96,9 @@ async function release(email, sent) {
|
||||
const a = await R.accounts.byEmail(e);
|
||||
if (a && sent) {
|
||||
const r = await rowFor(a); const n = v => String(v || '').toLowerCase();
|
||||
if (n(r.username) === n(sent.username) && n(r.wallet) === n(sent.wallet) && n(r.sponsorEmail) === n(sent.sponsorEmail)) { load().hashes[e] = hashOf(r); save(); same = true; }
|
||||
// a deliberate change from LinkSpin counts as the same only when we now carry that same record (applied, not refused)
|
||||
const sameFollow = !sent.sponsorSetBy || (Number(r.sponsorSetAt) === Number(sent.sponsorSetAt) && String(r.sponsorSetBy) === String(sent.sponsorSetBy));
|
||||
if (n(r.username) === n(sent.username) && n(r.wallet) === n(sent.wallet) && n(r.sponsorEmail) === n(sent.sponsorEmail) && sameFollow) { load().hashes[e] = hashOf(r); save(); same = true; }
|
||||
}
|
||||
} catch (err) {}
|
||||
if (pending.has(e) && !timer) { pending.delete(e); touch(e); } // a touch that queued while muted goes now (the hash check drops it when same)
|
||||
|
||||
Reference in New Issue
Block a user