Tweak block audit algo to reduce false positives
This commit is contained in:
		
							parent
							
								
									88fa6bffb5
								
							
						
					
					
						commit
						29f7c89c53
					
				| @ -1,4 +1,4 @@ | |||||||
| import logger from '../logger'; | import config from '../config'; | ||||||
| import { BlockExtended, TransactionExtended, MempoolBlockWithTransactions } from '../mempool.interfaces'; | import { BlockExtended, TransactionExtended, MempoolBlockWithTransactions } from '../mempool.interfaces'; | ||||||
| 
 | 
 | ||||||
| const PROPAGATION_MARGIN = 180; // in seconds, time since a transaction is first seen after which it is assumed to have propagated to all miners
 | const PROPAGATION_MARGIN = 180; // in seconds, time since a transaction is first seen after which it is assumed to have propagated to all miners
 | ||||||
| @ -44,8 +44,6 @@ class Audit { | |||||||
| 
 | 
 | ||||||
|     displacedWeight += (4000 - transactions[0].weight); |     displacedWeight += (4000 - transactions[0].weight); | ||||||
| 
 | 
 | ||||||
|     logger.warn(`${fresh.length} fresh, ${Object.keys(isCensored).length} possibly censored, ${displacedWeight} displaced weight`); |  | ||||||
| 
 |  | ||||||
|     // we can expect an honest miner to include 'displaced' transactions in place of recent arrivals and censored txs
 |     // we can expect an honest miner to include 'displaced' transactions in place of recent arrivals and censored txs
 | ||||||
|     // these displaced transactions should occupy the first N weight units of the next projected block
 |     // these displaced transactions should occupy the first N weight units of the next projected block
 | ||||||
|     let displacedWeightRemaining = displacedWeight; |     let displacedWeightRemaining = displacedWeight; | ||||||
| @ -73,6 +71,7 @@ class Audit { | |||||||
| 
 | 
 | ||||||
|     // mark unexpected transactions in the mined block as 'added'
 |     // mark unexpected transactions in the mined block as 'added'
 | ||||||
|     let overflowWeight = 0; |     let overflowWeight = 0; | ||||||
|  |     let totalWeight = 0; | ||||||
|     for (const tx of transactions) { |     for (const tx of transactions) { | ||||||
|       if (inTemplate[tx.txid]) { |       if (inTemplate[tx.txid]) { | ||||||
|         matches.push(tx.txid); |         matches.push(tx.txid); | ||||||
| @ -82,11 +81,13 @@ class Audit { | |||||||
|         } |         } | ||||||
|         overflowWeight += tx.weight; |         overflowWeight += tx.weight; | ||||||
|       } |       } | ||||||
|  |       totalWeight += tx.weight | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     // transactions missing from near the end of our template are probably not being censored
 |     // transactions missing from near the end of our template are probably not being censored
 | ||||||
|     let overflowWeightRemaining = overflowWeight; |     let overflowWeightRemaining = overflowWeight - (config.MEMPOOL.BLOCK_WEIGHT_UNITS - totalWeight); | ||||||
|     let lastOverflowRate = 1.00; |     let maxOverflowRate = 0; | ||||||
|  |     let rateThreshold = 0; | ||||||
|     index = projectedBlocks[0].transactionIds.length - 1; |     index = projectedBlocks[0].transactionIds.length - 1; | ||||||
|     while (index >= 0) { |     while (index >= 0) { | ||||||
|       const txid = projectedBlocks[0].transactionIds[index]; |       const txid = projectedBlocks[0].transactionIds[index]; | ||||||
| @ -94,8 +95,11 @@ class Audit { | |||||||
|         if (isCensored[txid]) { |         if (isCensored[txid]) { | ||||||
|           delete isCensored[txid]; |           delete isCensored[txid]; | ||||||
|         } |         } | ||||||
|         lastOverflowRate = mempool[txid].effectiveFeePerVsize; |         if (mempool[txid].effectiveFeePerVsize > maxOverflowRate) { | ||||||
|       } else if (Math.floor(mempool[txid].effectiveFeePerVsize * 100) <= Math.ceil(lastOverflowRate * 100)) { // tolerance of 0.01 sat/vb
 |           maxOverflowRate = mempool[txid].effectiveFeePerVsize; | ||||||
|  |           rateThreshold = (Math.ceil(maxOverflowRate * 100) / 100) + 0.005 | ||||||
|  |         } | ||||||
|  |       } else if (mempool[txid].effectiveFeePerVsize <= rateThreshold) { // tolerance of 0.01 sat/vb + rounding
 | ||||||
|         if (isCensored[txid]) { |         if (isCensored[txid]) { | ||||||
|           delete isCensored[txid]; |           delete isCensored[txid]; | ||||||
|         } |         } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user