Lambda Bazaar: a capacity market for your dark fiber

A new NOC tab sells spectrum, managed 100G, 400G, 800G and 1.6T waves, and dark pair IRUs on every route you hold
fiber on. Demand per route moves every day (its own cycle, noise, and news: fiber cuts, hyperscalers, AI clusters,
rivals lighting glass, mergers) and grows about 15% a year, with buyers moving to bigger waves over the years and
carriers on your glass asking to move up a size. You choose what to keep back for your own traffic, from what demand
the broker lists, and the price it never sells below. Managed waves come out of capacity you lit; prices follow the
fiber's cost, how hot and how full the route is, and its latency (400G at 2.7x 100G on land, 3.8x subsea). A Cable
broker pays 3% instead of 10% and sees each route's forecast and routes worth building.

Rule F5 now bounds sales by the moving market; new rule F8 covers managed waves. The route fuzz skips dashboard tabs
main does not have yet.
This commit is contained in:
Frederic Jung 2026-11-07 13:15:56 +01:00
parent e6b5464352
commit 2f738dceda
No known key found for this signature in database
34 changed files with 891 additions and 56 deletions

View file

@ -0,0 +1,149 @@
// The capacity market, Lambda Bazaar (37-fiber-market.js): products from spectrum to 1.6T waves and dark pairs, demand
// that moves and grows, thresholds, managed waves carved out of your own capacity, customers moving up a size, the
// Cable broker's fee and forecast, and saves.
const test = require('node:test');
const assert = require('node:assert/strict');
const { load } = require('./harness');
const start = (ev) => ev("ACT.start({});if(UI.pendGame)ACT.pitchSkip();closeModal();S.cash=1e9;S.lvl=6;S.offers=[];S.biz=[];S.inc=[]");
const fiber = (ev, id, a, b, ch = 'tp16', n = 8) => ev(`for(const c of ['${a}','${b}'])if(!S.pops[c])ACT.buildPop({city:c});closeModal();
S.links.push({id:'${id}',a:'${a}',b:'${b}',kind:'df',own:true,sys:'cl',ch:Array(${n}).fill('${ch}'),km:Math.round(kmBetween('${a}','${b}')*1.05),ready:0,day:0,cut:0,mo:100,trench:'own:${id}',pairs:1});compute();`);
const route = (k) => `cmRoutes().get('${k}')`;
test('demand moves all the time: its own cycle, noise, and news; a forecast sees the cycle and the news already out', () => {
const { ev, errors } = load();
start(ev);
fiber(ev, 'f', 'fra', 'ams');
const hs = JSON.parse(ev(`JSON.stringify(Array.from({length:24},(_, i)=>cmHeat(${route('ams|fra')},'w400',i*15)))`));
assert.ok(Math.max(...hs) - Math.min(...hs) > 0.3, `heat over a year: ${Math.min(...hs).toFixed(2)} to ${Math.max(...hs).toFixed(2)}`);
assert.ok(hs.every((h) => h >= 0.3 && h <= 2.5));
assert.equal(ev(`cmFc(${route('ams|fra')},'w400',30)`), ev(`cmDem(${route('ams|fra')},'w400',S.day+30,true)`));
// A cut on a fiber next door is news the next morning, and carriers want routes around it.
const before = ev(`cmDem(${route('ams|fra')},'spec',S.day+10)`);
// (No other news today: the daily roll for news of its own comes out high.)
ev("S.inc.push({id:'cut1',type:'cut',ref:'own:f',until:S.day+5,msg:''});const r0=Math.random;Math.random=()=>0.99;cmShocks(S.day);Math.random=r0");
assert.equal(ev('S.cm.news[0].why'), 'cut');
assert.ok(ev(`cmDem(${route('ams|fra')},'spec',S.day+10)`) > before * 1.4, 'a cut makes the route around it hot');
ev('const r0=Math.random;Math.random=()=>0.99;cmShocks(S.day);Math.random=r0');
assert.equal(ev("S.cm.news.filter(n=>n.why==='cut').length"), 1, 'one incident is news once');
assert.deepEqual(errors, []);
});
test('demand grows every year, and buyers move from 100G to 400G, 800G and 1.6T', () => {
const { ev, errors } = load();
start(ev);
fiber(ev, 'f', 'fra', 'ams');
ev('S.cm.sh=[]');
const gbps = (d) => ev(`CM_W.reduce((a,p)=>a+cmDem(${route('ams|fra')},p,${d},true)*CM_G[p],0)`);
assert.ok(Math.abs(ev('cmGrowth(365*5)') - Math.pow(1.15, 5)) < 1e-9, 'about 15% more every year');
assert.ok(gbps(365 * 5) > gbps(0) * 1.3, `five years on, carriers want ${Math.round(gbps(365 * 5))} G against ${Math.round(gbps(0))} G`);
const sh = (p, d) => ev(`cmShare('${p}',${d})`);
assert.ok(sh('w100', 0) > sh('w100', 365 * 4), '100G fades');
assert.ok(sh('w1600', 0) < 0.05 && sh('w1600', 365 * 10) > 0.5, '1.6T is rare at first and common ten years on');
assert.ok(Math.abs(['w100', 'w400', 'w800', 'w1600'].reduce((a, p) => a + sh(p, 900), 0) - 1) < 1e-9, 'the shares add up');
assert.ok(ev('cmGrowth(365*40)') <= 8, 'growth has a ceiling');
assert.deepEqual(errors, []);
});
test('prices: a 400G wave is 2.7 times a 100G one on land and 3.8 on subsea, short straight routes earn more, and floors hold', () => {
const { ev, errors } = load();
start(ev);
fiber(ev, 'f', 'fra', 'ams');
const r = route('ams|fra');
assert.ok(Math.abs(ev(`cmList(${r},'w400')/cmList(${r},'w100')`) - 2.7) < 1e-9);
assert.ok(Math.abs(ev(`(()=>{const x={...${r},sub:true};return cmList(x,'w400')/cmList(x,'w100')})()`) - 3.8) < 1e-9);
assert.ok(ev(`cmList(${r},'w1600')/16 < cmList(${r},'w100')`), 'a bit on a 1.6T wave is cheaper than on a 100G one');
assert.ok(ev(`${r}.lp`) > ev(`({...${r},lp:0}, cmRoute('ams','fra',[{...S.links.find(l=>l.id==='f'),km:2000}]).lp)`), 'a long detour loses the latency premium');
// Each unit sold makes the next cheaper, and the broker never sells below the floor.
ev("for(const p of CM_P){S.cm.p[p].on=true;S.cm.p[p].floor=100;S.cm.p[p].min=1;}__reseed(5)");
ev('for(let d=0;d<400;d++){S.day++;cmDay(S.day);}');
const sales = JSON.parse(ev("JSON.stringify(S.biz.map(b=>({t:b.type,g:b.g||0})))"));
assert.ok(sales.length > 0, 'something sold');
assert.ok(ev(`(()=>{const rs=cmRoutes(),s=cmSold(rs).get('ams|fra');return CM_P.every(p=>!s[p]||cmIdx(rs.get('ams|fra'),p,s[p]-1,0,S.day)*100>=0)})()`));
assert.deepEqual(errors, []);
});
test('auto-listing follows the thresholds and the share kept back; managed waves come out of your own capacity', () => {
const { ev, errors } = load();
start(ev);
fiber(ev, 'f', 'fra', 'ams', 'zr4', 8);
ev("S.cm.hold=50;S.cm.p.w400.on=true;S.cm.p.w400.min=1;S.cm.p.w400.floor=60;S.cm.p.w800.on=true;S.cm.p.w800.min=1;S.cm.p.w800.floor=60;cmRelist()");
const L = () => JSON.parse(ev("JSON.stringify(S.links.find(l=>l.id==='f').list||{})"));
assert.ok(L().m4 > 0 && L().m4 <= 4, `half of 3.2T kept back leaves at most four 400G waves (${L().m4})`);
assert.equal(L().m8, undefined, 'no 800G wave on 400G optics');
ev("S.cm.p.w400.min=16;cmRelist()");
assert.equal(L().m4, undefined, 'below the minimum demand the broker takes it off');
// A sold managed wave carves its capacity out of your own; when your optics cannot carry it, its customer suffers.
ev("const l=S.links.find(x=>x.id==='f');cmSell(l,'w400',2,1000,0);compute()");
assert.equal(ev("dfLit(S.links.find(l=>l.id==='f'))-dfCap(S.links.find(l=>l.id==='f'))"), 800);
assert.equal(ev("fiberOk(S.biz.find(b=>b.type==='mwave'))"), true);
ev("S.links.find(l=>l.id==='f').ch=['zr4']");
assert.equal(ev("fiberOk(S.biz.find(b=>b.type==='mwave'))"), false, '400G lit cannot carry 800G sold');
ev("ACT.mktCfg({p:'w400',k:'on',v:0})");
assert.equal(ev("S.cm.p.w400.on"), false);
assert.deepEqual(errors, []);
});
test('a carrier on your glass moves up a size once the next one is common, if there is room', () => {
const { ev, errors } = load();
start(ev);
fiber(ev, 'f', 'fra', 'ams', 'tp16', 8);
ev("S.day=365*4;S.cm.hold=0;const l=S.links.find(x=>x.id==='f');cmSell(l,'w400',2,2000,0);compute()");
const b0 = JSON.parse(ev("JSON.stringify(S.biz.find(b=>b.type==='mwave'))"));
ev("Math.random=()=>0;cmGrow(S.day)");
const b1 = JSON.parse(ev("JSON.stringify(S.biz.find(b=>b.type==='mwave'))"));
assert.equal(b1.g, 800);
assert.ok(b1.rate > b0.rate, `pays more: ${b0.rate} to ${b1.rate}`);
assert.equal(ev("dfLit(S.links.find(l=>l.id==='f'))-dfCap(S.links.find(l=>l.id==='f'))"), 1600);
// No room: it asks, and does not ask again for half a year (1.6T is common by year 9).
ev("S.links.find(l=>l.id==='f').ch=['tp16'];S.cm.hold=50;S.day=365*9;cmGrow(S.day)");
const gw = ev('S.biz.find(b=>b.type===\'mwave\').gw');
ev('S.day+=30;cmGrow(S.day)');
const b2 = JSON.parse(ev("JSON.stringify(S.biz.find(b=>b.type==='mwave'))"));
assert.equal(b2.g, 800);
assert.equal(gw, 365 * 9);
assert.equal(b2.gw, 365 * 9, 'not again a month later');
assert.deepEqual(errors, []);
});
test('a Cable broker pays 3% instead of 10% and sees routes it could build with their forecast', () => {
const { ev, errors } = load();
start(ev);
assert.equal(ev('cmCut()'), 0.9);
ev("ACT.charter({k:'broker'});closeModal();S.cash=1e9");
assert.equal(ev('cmCut()'), 0.97);
for (const c of ['fra', 'ams', 'par', 'bru']) ev(`if(!S.pops['${c}'])ACT.buildPop({city:'${c}'});closeModal()`);
const sc = JSON.parse(ev('JSON.stringify(cmScout().map(r=>r.k))'));
assert.ok(sc.length > 0 && sc.every((k) => k.includes('|')));
ev("UI.dtab='market';$('dash').hidden=false;renderDash()");
const html = ev("$('dashCard').textContent");
assert.match(html, /Lambda Bazaar/);
assert.match(html, /Routes you could build/);
assert.deepEqual(errors, []);
});
test('the market is kept in the save, checked, and old saves get the defaults', () => {
const { ev, errors } = load();
start(ev);
fiber(ev, 'f', 'fra', 'ams');
ev("S.cm.hold=10;S.cm.p.w1600.on=true;S.cm.p.w1600.min=2;S.cm.off['ams|fra']=1;cmNews('glut',{k:'ams|fra',a:'ams',b:'fra'},S.day);cmSell(S.links[S.links.length-1],'w800',1,500,0)");
ev('const t=JSON.stringify(packSave(S));S=migrate(JSON.parse(t))');
const cm = JSON.parse(ev('JSON.stringify(S.cm)'));
assert.equal(cm.hold, 10);
assert.deepEqual(cm.p.w1600, { on: true, min: 2, floor: 80 });
assert.equal(cm.off['ams|fra'], 1);
assert.equal(cm.sh[0].why, 'glut');
assert.equal(ev("S.biz.find(b=>b.type==='mwave').g"), 800);
ev("const o=JSON.parse(JSON.stringify(packSave(S)));o.cm={hold:33,p:{w100:{on:'yes',min:999,floor:-1}},off:{'zzz|ams':1},sh:[{why:'nope'},{why:'dc',c:'atlantis'}],news:'x'};o.biz.find(b=>b.type==='mwave').g=999;o.links.find(l=>l.id==='f').list={m8:'lots',m16:3};S=migrate(o)");
const c2 = JSON.parse(ev('JSON.stringify(S.cm)'));
assert.equal(c2.hold, 25);
assert.deepEqual(c2.p.w100, { on: true, min: 4, floor: 80 });
assert.deepEqual(c2.off, {});
assert.deepEqual(c2.sh, []);
assert.deepEqual(c2.news, []);
assert.equal(ev("S.biz.find(b=>b.type==='mwave').g"), 100);
assert.deepEqual(JSON.parse(ev("JSON.stringify(S.links.find(l=>l.id==='f').list)")), { w: 0, p: 0, m16: 3 });
ev('const o=JSON.parse(JSON.stringify(packSave(S)));delete o.cm;S=migrate(o)');
assert.deepEqual(JSON.parse(ev('JSON.stringify(S.cm.p.spec)')), { on: false, min: 2, floor: 80 });
assert.deepEqual(errors, []);
});

View file

@ -16,6 +16,8 @@ test('a route\'s market follows the eyeballs at both ends, and a landing town co
assert.ok(ev("brMarket('nyc','bde')") > ev("brMarket('nyc','gdx')"));
});
// The market moves (37-fiber-market.js): demand has its own cycle and grows, so days pass here; at its hottest a route
// wants CM_HMAX times its usual spectrum.
test('a listing sells over time, never past the market, and rent from a road to nowhere stays small', () => {
const { ev, errors } = load();
start(ev);
@ -23,11 +25,11 @@ test('a listing sells over time, never past the market, and rent from a road to
fiber(ev, 'far', 'jed', 'gdx', 9089);
ev("__reseed(7);ACT.listFiber({id:'big',w:60});ACT.listFiber({id:'far',w:60})");
assert.equal(ev("S.biz.length"), 0, 'nothing sells the moment it is listed');
ev('for(let d=0;d<720;d++)brTick()');
ev('for(let d=0;d<720;d++){S.day++;brTick();}');
const sold = (id) => ev(`S.biz.filter(b=>b.link==='${id}').reduce((a,b)=>a+(b.slots||0),0)`);
assert.ok(sold('big') >= 3, `Frankfurt–Amsterdam sold ${sold('big')}`);
assert.ok(sold('big') <= ev("brMarket('fra','ams')"), 'never more than the route wants');
assert.equal(sold('far'), 1, 'Jeddah–Magadan: one wave, then the market is full');
assert.ok(sold('big') <= ev("brMarket('fra','ams')*0.5*CM_HMAX*Math.pow(cmGrowth(S.day),0.7)"), 'never more than the route wants at its hottest');
assert.ok(sold('far') >= 1 && sold('far') <= 2, `Jeddah–Magadan: a wave or two, then the market is full (${sold('far')})`);
assert.equal(ev("brFree(S.links.find(l=>l.id==='far'))"), 0);
// random alien-wave offers respect the market too
ev("S.offers=[];for(let i=0;i<400;i++)spawnOffer()");

View file

@ -432,8 +432,11 @@ test('F5: rented capacity never outgrows the route\'s market (#203)', () => {
const g = load();
g.ev("ACT.start({});if(UI.pendGame)ACT.pitchSkip();S.cash=1e9;S.lvl=4;S.biz=[];S.offers=[];for(const c of ['jed','gdx'])ACT.buildPop({city:c})");
g.ev("S.links.push({id:'f',a:'jed',b:'gdx',kind:'df',own:true,sys:'roadm',ch:[],km:9089,ready:0,day:0,cut:0,mo:1,trench:'own:f',pairs:1});compute();__reseed(5);ACT.listFiber({id:'f',w:120,p:1})");
g.ev('for(let d=0;d<1500;d++){brTick();if(d%7===0)spawnOffer();}for(const o of S.offers.filter(o=>o.link===\'f\'))ACT.accept({id:o.id})');
assert.ok(g.ev("brSold('jed','gdx')") <= g.ev("brMarket('jed','gdx')"), 'F5: no more than the route wants');
g.ev('for(let d=0;d<1500;d++){S.day++;brTick();if(d%7===0)spawnOffer();}for(const o of S.offers.filter(o=>o.link===\'f\'))ACT.accept({id:o.id})');
// The market moves and grows (37-fiber-market.js): never more than the route wants at its hottest, today.
const most = g.ev("Math.max(brMarket('jed','gdx'),Math.round(brMarket('jed','gdx')*0.5*CM_HMAX*Math.pow(cmGrowth(S.day),0.7)))");
assert.ok(g.ev("brSold('jed','gdx')") <= most, `F5: no more than the route wants (${g.ev("brSold('jed','gdx')")} of ${most})`);
assert.ok(g.ev("brSold('jed','gdx')") <= 3, 'a road to nowhere still sells only a little');
assert.deepEqual(g.errors, []);
});
@ -462,6 +465,26 @@ test('F7: extra crews cut a build on land to half its planned time at most (#203
assert.deepEqual(g.errors, []);
});
test('F8: a managed wave costs your own capacity, rides one optic, and is priced against its fiber', () => {
const g = load();
g.ev("ACT.start({});if(UI.pendGame)ACT.pitchSkip();S.cash=1e9;S.lvl=6;S.biz=[];S.offers=[];for(const c of ['fra','ams'])if(!S.pops[c])ACT.buildPop({city:c})");
g.ev("S.links.push({id:'f',a:'fra',b:'ams',kind:'df',own:true,sys:'cl',ch:['zr4','zr4'],km:400,ready:0,day:0,cut:0,mo:1,trench:'own:f',pairs:1});compute()");
const r = "cmRoutes().get('ams|fra')";
for (const [p, land, sea] of [['w400', 2.7, 3.8], ['w800', 4.6, 6.6], ['w1600', 7.8, 11]]) {
assert.ok(Math.abs(g.ev(`cmList(${r},'${p}')/cmList(${r},'w100')`) - land) < 1e-9, `F8: ${p} on land`);
assert.ok(Math.abs(g.ev(`(()=>{const x={...${r},sub:true};return cmList(x,'${p}')/cmList(x,'w100')})()`) - sea) < 1e-9, `F8: ${p} on subsea`);
}
for (let i = 1; i < 4; i++) assert.ok(g.ev(`cmList(${r},CM_W[${i}])/CM_G[CM_W[${i}]]<cmList(${r},CM_W[${i - 1}])/CM_G[CM_W[${i - 1}]]`), 'F8: cheaper per bit');
assert.ok(Math.abs(g.ev(`cmList(${r},'spec')/(dfLeaseMo(400)+ampCount(400)*AMP_MO)`) - 0.3) < 1e-9, 'F8: spectrum lists at 30%');
for (let d = 0; d < 720; d += 9) { const x = g.ev(`cmIdx(${r},'spec',0,0,${d})`); assert.ok(x >= 0.7 - 1e-9 && x <= 1.35 + 1e-9, `F8: heat moves a price by ${x}`); }
assert.equal(g.ev("cmSpare(S.links[S.links.length-1],'w800',0)"), 0, 'F8: no 800G wave on 400G optics');
g.ev("cmSell(S.links[S.links.length-1],'w400',1,100,0);compute()");
assert.equal(g.ev("dfLit(S.links[S.links.length-1])-dfCap(S.links[S.links.length-1])"), 400, 'F8: it comes out of your own capacity');
g.ev("S.links[S.links.length-1].ch=[]");
assert.equal(g.ev("fiberOk(S.biz.find(b=>b.type==='mwave'))"), false, 'F8: unlit, its customer is down');
assert.deepEqual(g.errors, []);
});
// D1–D4: DDoS as networks see it (#242). tests/ddos-model.test.js plays each one in detail.
const ddFra = (ev) => ev("ACT.start({});if(UI.pendGame)ACT.pitchSkip();S.cash=1e9;S.lvl=4;S.nextFail=1e9;S.nextEvent=1e9;ACT.launchBB({city:'fra'});S.pops.fra.bb.d=40;ACT.buyTransit({city:'fra',net:'cog',tier:1});S.pops.fra.rgen=RG.findIndex(r=>r.fsN===8);S.biz.push({id:'g',type:'game',name:'G',city:'fra',bw:10,rate:1,mood:80,since:0,reqs:[]},{id:'d',type:'dia',name:'D',city:'fra',bw:5,rate:1,mood:80,since:0,reqs:[]});compute()");
const ddHit = (ev, g) => ev(`S.ev.ddos={id:'x',city:'fra',tgt:'g',vec:'dns',gbps:${g},start:S.day,until:S.day+2,bh:false};compute()`);

View file

@ -1270,7 +1270,10 @@ test('#51 a dark fiber shows what is rented out, and spare capacity can be liste
ev("for(let i=0;i<120&&!S.biz.some(b=>b.link==='df1');i++)brTick();renderPanel()");
const b = JSON.parse(ev("JSON.stringify(S.biz.find(x=>x.link==='df1'))"));
assert.equal(b.type, 'wwave');
assert.equal(b.rate, ev(`(()=>{const F=dfLeaseMo(450)+ampCount(450)*AMP_MO,M=brMarket('fra','ams');let r=0;for(let i=0;i<${b.slots};i++)r+=F*WW_SHARE*(1-WW_FALL*Math.min(1,i/M));return Math.round(r*0.9)})()`), 'the alien-wave price, priced against the fiber, minus the broker');
// The capacity market prices it (37-fiber-market.js): 30% of the fiber's cost a month, moved by how hot the route is
// and how full, minus the broker.
assert.equal(b.rate, ev(`(()=>{const r=cmRoutes().get('ams|fra');let x=0;for(let i=0;i<${b.slots};i++)x+=cmList(r,'spec')*cmIdx(r,'spec',0,i,S.day);return Math.round(x*0.9*mkt())})()`), 'the alien-wave price, priced against the fiber, minus the broker');
assert.ok(Math.abs(ev("cmList(cmRoutes().get('ams|fra'),'spec')/(dfLeaseMo(450)+ampCount(450)*AMP_MO)") - 0.3) < 1e-9);
assert.ok(txt().includes(b.name), 'the customer is listed on the fiber');
assert.match(txt(), new RegExp(`Free channels\\s*${62 - b.slots} / 64`));
assert.equal(ev("S.links[0].list?S.links[0].list.w:0"), 4 - b.slots, 'the listing shrinks by what sold');