@@ -2,8 +2,16 @@ import { USERS } from './gameConstants.js';
22import { createSeededRandom } from './seededRandom.js' ;
33import { getValidBlockSelections , isSelectionAffordable } from './txSelection.js' ;
44
5- const CORE_FEES = [ 8 , 7 , 6 , 4 ] ;
6- const FILLER_FEES = [ 5 , 4 , 3 , 3 , 2 , 2 , 1 , 1 , 1 ] ;
5+ const FEE_PROFILES = [ 0 , 1 ] . map ( ( offset ) => ( {
6+ core : [ 8 , 7 , 6 , 4 ] . map ( ( fee ) => fee + offset ) ,
7+ conflict : [ 10 + offset ] ,
8+ fillers : [ 9 , 8 , 5 , 5 , 4 , 3 , 3 , 2 , 2 ] . map ( ( fee ) => fee + offset ) ,
9+ invalid : 6 + offset ,
10+ } ) ) ;
11+
12+ function feeProfile ( rng ) {
13+ return FEE_PROFILES [ Math . floor ( rng ( ) * FEE_PROFILES . length ) ] ;
14+ }
715
816function txDate ( blockNum ) {
917 return `2026/05/${ String ( blockNum ) . padStart ( 2 , '0' ) } ` ;
@@ -62,7 +70,8 @@ function strategicQuality(pool, balances) {
6270 const valid = getValidBlockSelections ( pool , balances ) ;
6371 if ( valid . length < 2 ) return false ;
6472 const maximum = Math . max ( ...valid . map ( ( selection ) => selection . totalFees ) ) ;
65- if ( valid . filter ( ( selection ) => selection . totalFees === maximum ) . length !== 1 ) return false ;
73+ const optimalCount = valid . filter ( ( selection ) => selection . totalFees === maximum ) . length ;
74+ if ( optimalCount < 1 || optimalCount > 3 ) return false ;
6675 const topThree = [ ...pool ]
6776 . sort ( ( a , b ) => b . fee - a . fee || a . id - b . id )
6877 . slice ( 0 , 3 ) ;
@@ -94,38 +103,39 @@ function conflictPair({ sender, balance, fees, startId, blockNum, rng, conflicts
94103function buildInitialPool ( { balances, blockNum, roomSeed } ) {
95104 const rng = createSeededRandom ( `${ roomSeed || 'solo' } -mempool-${ blockNum } ` ) ;
96105 const startId = blockNum * 100 ;
106+ const profile = feeProfile ( rng ) ;
97107 const orderedUsers = shuffled ( USERS , rng )
98108 . sort ( ( a , b ) => ( balances [ b ] ?? 0 ) - ( balances [ a ] ?? 0 ) ) ;
99- const core = CORE_FEES . map ( ( fee , index ) => {
109+ const core = profile . core . map ( ( fee , index ) => {
100110 const sender = orderedUsers [ index % orderedUsers . length ] ;
101111 const available = Math . max ( 1 , ( balances [ sender ] ?? 0 ) - fee ) ;
102112 return {
103113 id : startId + index ,
104114 sender,
105115 receiver : receiverFor ( sender , balances , rng ) ,
106- amount : Math . min ( 8 , Math . max ( 1 , Math . floor ( available / 6 ) ) ) ,
116+ amount : Math . min ( available , 6 + Math . floor ( rng ( ) * 11 ) ) ,
107117 fee,
108118 date : txDate ( blockNum ) ,
109119 } ;
110120 } ) ;
111121 const conflict = conflictPair ( {
112122 sender : core [ 0 ] . sender ,
113123 balance : balances [ core [ 0 ] . sender ] ?? 0 ,
114- fees : [ 10 ] ,
124+ fees : profile . conflict ,
115125 startId : startId + core . length ,
116126 blockNum,
117127 rng,
118128 conflictsWithCost : core [ 0 ] . amount + core [ 0 ] . fee ,
119129 } ) ;
120- const fillers = FILLER_FEES . map ( ( fee , index ) => {
130+ const fillers = profile . fillers . map ( ( fee , index ) => {
121131 const sender = USERS [ ( index + Math . floor ( rng ( ) * USERS . length ) ) % USERS . length ] ;
122132 const receiver = receiverFor ( sender , balances , rng ) ;
123133 const maxAmount = Math . max ( 1 , ( balances [ sender ] ?? 0 ) - fee ) ;
124134 return {
125135 id : startId + core . length + conflict . length + index ,
126136 sender,
127137 receiver,
128- amount : Math . min ( 10 , Math . max ( 1 , Math . floor ( maxAmount / 5 ) ) ) ,
138+ amount : Math . min ( maxAmount , 6 + Math . floor ( rng ( ) * 15 ) ) ,
129139 fee,
130140 date : txDate ( blockNum ) ,
131141 } ;
@@ -136,18 +146,19 @@ function buildInitialPool({ balances, blockNum, roomSeed }) {
136146 sender : invalidSender ,
137147 receiver : receiverFor ( invalidSender , balances , rng ) ,
138148 amount : ( balances [ invalidSender ] ?? 0 ) + 5 ,
139- fee : 1 ,
149+ fee : profile . invalid ,
140150 date : txDate ( blockNum ) ,
141151 } ;
142152 const pool = finalizePool ( [ ...core , ...conflict , ...fillers , invalid ] , rng ) ;
143153 if ( strategicQuality ( pool , balances ) ) return pool ;
144- const fallback = allocateTransactions ( { balances, fees : [ 10 , 8 , 7 , 6 , 4 , 3 ] , rng, startId, blockNum } ) ;
154+ const fallbackFees = [ ...profile . core , ...profile . conflict , ...profile . fillers , profile . invalid ] ;
155+ const fallback = allocateTransactions ( { balances, fees : fallbackFees , rng, startId, blockNum } ) ;
145156 return finalizePool ( fallback , rng ) ;
146157}
147158
148159/**
149- * Build a deterministic, playable mempool. The two highest -fee choices share
150- * a sender and cannot be combined , so the best block requires reasoning about
160+ * Build a deterministic, playable mempool. A high -fee decoy conflicts with
161+ * another leading candidate , so the best block requires reasoning about
151162 * cumulative balances rather than simply taking the three largest fees.
152163 */
153164export function generateMempool ( { balances, blockNum = 1 , roomSeed = '' } ) {
@@ -171,21 +182,22 @@ export function replenishMempool(mempool, balances, blockNum, roomSeed) {
171182 if ( ! alternative ) return buildInitialPool ( { balances, blockNum, roomSeed } ) ;
172183
173184 const startId = Math . max ( blockNum * 100 , ...mempool . map ( ( tx ) => tx . id ) ) + 1 ;
185+ const profile = feeProfile ( rng ) ;
174186 const conflictSender = [ ...USERS ]
175187 . filter ( ( name ) => name !== alternative . sender )
176188 . sort ( ( a , b ) => ( balances [ b ] ?? 0 ) - ( balances [ a ] ?? 0 ) ) [ 0 ] ?? USERS [ 0 ] ;
177189 const pair = conflictPair ( {
178190 sender : conflictSender ,
179191 balance : balances [ conflictSender ] ?? 0 ,
180- fees : [ 10 , 9 ] ,
192+ fees : [ profile . conflict [ 0 ] , profile . core [ 0 ] ] ,
181193 startId,
182194 blockNum,
183195 rng,
184196 } ) ;
185197 const support = allocateTransactions ( {
186198 blockNum,
187199 balances,
188- fees : [ 7 ] ,
200+ fees : [ profile . core [ 2 ] ] ,
189201 rng,
190202 startId : startId + pair . length ,
191203 reserved : [ alternative , ...pair ] ,
0 commit comments