bisq-network / bisq-pricenode

GNU General Public License v3.0
5 stars 12 forks source link

Fix fee rate calculation bug when a provider is offline. #45

Closed ghost closed 8 months ago

ghost commented 9 months ago

When a provider is offline the default fee rate of 10 sats/vB was being used. In a high fee environment. this pulls down the average calculated from all providers. e.g. at the moment fees are 89 sats/vB and when a provider is offline, the resultant average fee shown on Bisq is 69 sats/vB:

bisq.price.mining.providers.MempoolFeeRateProvider$First@7015ebef feeRate: 89 
bisq.price.mining.providers.MempoolFeeRateProvider$Second@2a87ba34 feeRate: 89 
bisq.price.mining.providers.MempoolFeeRateProvider$Third@44592c39 feeRate: 89 
bisq.price.mining.providers.MempoolFeeRateProvider$Fourth@5e180aaf feeRate: 10 

To address this, the offline provider should not pull down the average:

bisq.price.mining.providers.MempoolFeeRateProvider$First@7015ebef feeRate: 88 
bisq.price.mining.providers.MempoolFeeRateProvider$Second@2a87ba34 feeRate: 88 
bisq.price.mining.providers.MempoolFeeRateProvider$Third@44592c39 feeRate: 88 
feeRate is null, provider=bisq.price.mining.providers.MempoolFeeRateProvider$Fourth@5e180aaf 

The default fee rate should be chosen only when all providers are offline:

feeRate is null, provider=bisq.price.mining.providers.MempoolFeeRateProvider$First@7015ebef  
feeRate is null, provider=bisq.price.mining.providers.MempoolFeeRateProvider$Second@2a87ba34  
feeRate is null, provider=bisq.price.mining.providers.MempoolFeeRateProvider$Third@44592c39  
feeRate is null, provider=bisq.price.mining.providers.MempoolFeeRateProvider$Fourth@5e180aaf  

See: https://github.com/bisq-network/bisq-pricenode/blob/6073a3948e7567359adf9f167c27d65a7e352d9a/src/main/java/bisq/price/mining/FeeRateService.java#L78-L81

Emzy commented 9 months ago

I will test this on my pricenode.

Emzy commented 9 months ago

Tested ACK After restart with this pr 492b04d: For about 20 sec it showed btcTxFee: 10. (far to low) But then it showed btcTxFee: 107 while another price node shows btcTxFee: 58

ghost commented 9 months ago

The default tx fee (10) is shown until there is some data from providers.

https://github.com/bisq-network/bisq-pricenode/blob/6073a3948e7567359adf9f167c27d65a7e352d9a/src/main/java/bisq/price/mining/FeeRateProvider.java#L30