Update TS side
This commit is contained in:
parent
2d4963c2df
commit
152d2c364b
@ -1,3 +1,4 @@
|
|||||||
|
import * as napiAddon from '../../rust-gbt';
|
||||||
import logger from '../logger';
|
import logger from '../logger';
|
||||||
import { MempoolBlock, MempoolTransactionExtended, TransactionStripped, MempoolBlockWithTransactions, MempoolBlockDelta, Ancestor, CompactThreadTransaction, EffectiveFeeStats, AuditTransaction } from '../mempool.interfaces';
|
import { MempoolBlock, MempoolTransactionExtended, TransactionStripped, MempoolBlockWithTransactions, MempoolBlockDelta, Ancestor, CompactThreadTransaction, EffectiveFeeStats, AuditTransaction } from '../mempool.interfaces';
|
||||||
import { Common, OnlineFeeStatsCalculator } from './common';
|
import { Common, OnlineFeeStatsCalculator } from './common';
|
||||||
@ -5,8 +6,6 @@ import config from '../config';
|
|||||||
import { Worker } from 'worker_threads';
|
import { Worker } from 'worker_threads';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
const neonAddon = require('../../rust-gbt');
|
|
||||||
|
|
||||||
class MempoolBlocks {
|
class MempoolBlocks {
|
||||||
private mempoolBlocks: MempoolBlockWithTransactions[] = [];
|
private mempoolBlocks: MempoolBlockWithTransactions[] = [];
|
||||||
private mempoolBlockDeltas: MempoolBlockDelta[] = [];
|
private mempoolBlockDeltas: MempoolBlockDelta[] = [];
|
||||||
@ -342,7 +341,14 @@ class MempoolBlocks {
|
|||||||
|
|
||||||
// run the block construction algorithm in a separate thread, and wait for a result
|
// run the block construction algorithm in a separate thread, and wait for a result
|
||||||
try {
|
try {
|
||||||
const { blocks, rates, clusters } = this.convertNeonResultTxids(await new Promise((resolve) => { neonAddon.make(mempoolBuffer, resolve); }));
|
const { blocks, rates, clusters } = this.convertNapiResultTxids(
|
||||||
|
await new Promise((resolve) => {
|
||||||
|
napiAddon.make(
|
||||||
|
new Uint8Array(mempoolBuffer),
|
||||||
|
resolve,
|
||||||
|
);
|
||||||
|
})
|
||||||
|
);
|
||||||
this.rustInitialized = true;
|
this.rustInitialized = true;
|
||||||
const processed = this.processBlockTemplates(newMempool, blocks, rates, clusters, saveResults);
|
const processed = this.processBlockTemplates(newMempool, blocks, rates, clusters, saveResults);
|
||||||
logger.debug(`RUST makeBlockTemplates completed in ${(Date.now() - start)/1000} seconds`);
|
logger.debug(`RUST makeBlockTemplates completed in ${(Date.now() - start)/1000} seconds`);
|
||||||
@ -374,7 +380,15 @@ class MempoolBlocks {
|
|||||||
|
|
||||||
// run the block construction algorithm in a separate thread, and wait for a result
|
// run the block construction algorithm in a separate thread, and wait for a result
|
||||||
try {
|
try {
|
||||||
const { blocks, rates, clusters } = this.convertNeonResultTxids(await new Promise((resolve) => { neonAddon.update(addedBuffer, removedBuffer, resolve); }));
|
const { blocks, rates, clusters } = this.convertNapiResultTxids(
|
||||||
|
await new Promise((resolve) => {
|
||||||
|
napiAddon.update(
|
||||||
|
new Uint8Array(addedBuffer),
|
||||||
|
new Uint8Array(removedBuffer),
|
||||||
|
resolve,
|
||||||
|
);
|
||||||
|
})
|
||||||
|
);
|
||||||
this.processBlockTemplates(newMempool, blocks, rates, clusters, saveResults);
|
this.processBlockTemplates(newMempool, blocks, rates, clusters, saveResults);
|
||||||
logger.debug(`RUST updateBlockTemplates completed in ${(Date.now() - start)/1000} seconds`);
|
logger.debug(`RUST updateBlockTemplates completed in ${(Date.now() - start)/1000} seconds`);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -563,7 +577,7 @@ class MempoolBlocks {
|
|||||||
return { blocks: convertedBlocks, rates: convertedRates, clusters: convertedClusters } as { blocks: string[][], rates: { [root: string]: number }, clusters: { [root: string]: string[] }};
|
return { blocks: convertedBlocks, rates: convertedRates, clusters: convertedClusters } as { blocks: string[][], rates: { [root: string]: number }, clusters: { [root: string]: string[] }};
|
||||||
}
|
}
|
||||||
|
|
||||||
private convertNeonResultTxids({ blocks, rates, clusters }: { blocks: number[][], rates: number[][], clusters: number[][]})
|
private convertNapiResultTxids({ blocks, rates, clusters }: { blocks: number[][], rates: number[][], clusters: number[][]})
|
||||||
: { blocks: string[][], rates: { [root: string]: number }, clusters: { [root: string]: string[] }} {
|
: { blocks: string[][], rates: { [root: string]: number }, clusters: { [root: string]: string[] }} {
|
||||||
const rateMap = new Map<number, number>();
|
const rateMap = new Map<number, number>();
|
||||||
const clusterMap = new Map<number, number[]>();
|
const clusterMap = new Map<number, number[]>();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user