Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | 57x 57x 57x 57x 57x 57x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 10x 2x 2x 2x 2x 2x 2x 2x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 2x | import { entity, table } from '../../storage/index.client';
import { verifyTruthy } from '../../utility/index.client';
import { Monitor } from '../Monitor';
import { WalletMonitorTask } from './WalletMonitorTask';
import { attemptToPostReqsToNetwork } from '../../storage/methods/attemptToPostReqsToNetwork';
export class TaskSendWaiting extends WalletMonitorTask {
static taskName = 'SendWaiting';
constructor(monitor: Monitor, public triggerMsecs = 1000 * 60 * 5, public agedMsecs = 0) {
super(monitor, TaskSendWaiting.taskName);
}
trigger(nowMsecsSinceEpoch: number): { run: boolean; } {
return { run: nowMsecsSinceEpoch > this.lastRunMsecsSinceEpoch + this.triggerMsecs };
}
async runTask(): Promise<string> {
let log = '';
const limit = 100;
let offset = 0;
const agedLimit = new Date(Date.now() - this.agedMsecs);
for (; ;) {
const reqs = await this.storage.findProvenTxReqs({ partial: {}, status: ['unsent'], paged: { limit, offset } });
Iif (reqs.length === 0) break;
log += `${reqs.length} reqs with status 'unsent'\n`;
const agedReqs = reqs.filter(req => verifyTruthy(req.updated_at) < agedLimit);
log += ` Of those reqs, ${agedReqs.length} where last updated before ${agedLimit.toISOString()}.\n`;
log += await this.processUnsent(agedReqs, 2);
if (reqs.length < limit) break;
offset += limit;
}
return log
}
/**
* Process an array of 'unsent' status table.ProvenTxReq
*
* Send rawTx to transaction processor(s), requesting proof callbacks when possible.
*
* Set status 'invalid' if req is invalid.
*
* Set status to 'callback' on successful network submission with callback service.
*
* Set status to 'unmined' on successful network submission without callback service.
*
* Add mapi responses to database table if received.
*
* Increments attempts if sending was attempted.
*
* @param reqApis
*/
async processUnsent(reqApis: table.ProvenTxReq[], indent = 0) : Promise<string> {
let log = ''
for (let i = 0; i < reqApis.length; i++) {
const reqApi = reqApis[i]
log += ' '.repeat(indent)
log += `${i} reqId=${reqApi.provenTxReqId} attempts=${reqApi.attempts} txid=${reqApi.txid}: \n`
Iif (reqApi.status !== 'unsent') {
log += ` status now ${reqApi.status}\n`
continue
}
const req = new entity.ProvenTxReq(reqApi)
const reqs: entity.ProvenTxReq[] = []
Iif (req.batch) {
// Make sure wew process entire batch together for efficient beef generation
const batchReqApis = await this.storage.findProvenTxReqs({ partial: { batch: req.batch, status: 'unsent' } })
for (const bra of batchReqApis) {
// Remove any matching batchReqApis from reqApis
const index = reqApis.findIndex(ra => ra.provenTxReqId === bra.provenTxReqId)
Iif (index > -1) reqApis.slice(index, index + 1);
// And add to reqs being processed now:
reqs.push(new entity.ProvenTxReq(bra))
}
} else {
// Just a single non-batched req...
reqs.push(req)
}
const r = await this.storage.runAsStorageProvider(async (sp) => {
return attemptToPostReqsToNetwork(sp, reqs)
})
log += r.log
}
return log
}
}
|