Omit possible high-sigop txs from block health score
This commit is contained in:
@@ -6,14 +6,15 @@ const PROPAGATION_MARGIN = 180; // in seconds, time since a transaction is first
|
||||
|
||||
class Audit {
|
||||
auditBlock(transactions: TransactionExtended[], projectedBlocks: MempoolBlockWithTransactions[], mempool: { [txId: string]: TransactionExtended })
|
||||
: { censored: string[], added: string[], fresh: string[], score: number, similarity: number } {
|
||||
: { censored: string[], added: string[], fresh: string[], sigop: string[], score: number, similarity: number } {
|
||||
if (!projectedBlocks?.[0]?.transactionIds || !mempool) {
|
||||
return { censored: [], added: [], fresh: [], score: 0, similarity: 1 };
|
||||
return { censored: [], added: [], fresh: [], sigop: [], score: 0, similarity: 1 };
|
||||
}
|
||||
|
||||
const matches: string[] = []; // present in both mined block and template
|
||||
const added: string[] = []; // present in mined block, not in template
|
||||
const fresh: string[] = []; // missing, but firstSeen within PROPAGATION_MARGIN
|
||||
const sigop: string[] = []; // missing, but possibly has an adjusted vsize due to high sigop count
|
||||
const isCensored = {}; // missing, without excuse
|
||||
const isDisplaced = {};
|
||||
let displacedWeight = 0;
|
||||
@@ -37,6 +38,8 @@ class Audit {
|
||||
// tx is recent, may have reached the miner too late for inclusion
|
||||
if (mempool[txid]?.firstSeen != null && (now - (mempool[txid]?.firstSeen || 0)) <= PROPAGATION_MARGIN) {
|
||||
fresh.push(txid);
|
||||
} else if (this.isPossibleHighSigop(mempool[txid])) {
|
||||
sigop.push(txid);
|
||||
} else {
|
||||
isCensored[txid] = true;
|
||||
}
|
||||
@@ -137,10 +140,19 @@ class Audit {
|
||||
censored: Object.keys(isCensored),
|
||||
added,
|
||||
fresh,
|
||||
sigop,
|
||||
score,
|
||||
similarity,
|
||||
};
|
||||
}
|
||||
|
||||
// Detect transactions with a possibly adjusted vsize due to high sigop count
|
||||
// very rough heuristic based on number of OP_CHECKMULTISIG outputs
|
||||
// will miss cases with other sources of sigops
|
||||
isPossibleHighSigop(tx: TransactionExtended): boolean {
|
||||
const numBareMultisig = tx.vout.reduce((count, vout) => count + (vout.scriptpubkey_asm.includes('OP_CHECKMULTISIG') ? 1 : 0), 0);
|
||||
return (numBareMultisig * 400) > tx.vsize;
|
||||
}
|
||||
}
|
||||
|
||||
export default new Audit();
|
||||
Reference in New Issue
Block a user