The missing query number in a TON Highload Wallet v3 queue
A payout queue works for its first thousand requests and then a sequential identifier reaches 1023. Highload Wallet v3 stores replay protection in a bitmap whose bit number has a restricted range.
Separate the queue sequence from the encoded query ID
The low ten bits encode the bit position, but valid positions run from 0 to 1022. After the pair (0, 1022), the next ordinary pair is (1, 0). Their packed values are 1022 and 1024. Incrementing the packed integer directly would select bit 1023, outside the valid range.
const pack = (shift, bit) => (shift << 10) | bit;
console.log(pack(0, 1022), pack(1, 0));
console.log(1023 & 1023);
Test the boundary during queue recovery
Persist the association between business request and assigned query ID so that two workers do not issue the same slot for different payouts. Include a restart between those two boundary values in a queue test. At the upper end, use the wallet’s reference allocator and its reserved emergency slot rules. A local counter alone also cannot determine when an old identifier is eligible for reuse under the wallet timeout.