Add better fee error handling and monitoring

- Log clear error messages when fee buffer is too low
- Show exact shortfall amount and required action
- Add DOGE_REFUND_FEE_BUFFER environment variable for dynamic adjustment
- Log actual fee buffer used on successful refunds
- Add helpful comment in vars.sh about the fee buffer setting

Now when watching crypto-watcher logs, admins will see:
- 'INSUFFICIENT FUNDS - Fee estimate too low\!'
- Current buffer, shortfall amount, and line number to fix
- Success messages show actual vs estimated fee usage

This makes it much easier to adjust the fee buffer without diving into code.
This commit is contained in:
Russell Ballestrini 2025-10-02 16:34:16 -04:00
parent d4a239d748
commit 8836fb6333

View file

@ -294,7 +294,11 @@ class PaymentRescue:
# Account for network fee by reducing amounts proportionally
# Dogecoin sendmany adds fee on top of outputs, so we need to leave room
total_output = refund_amount_doge + shop_amount_doge
estimated_fee = 0.005 # Reasonable fee for 1-input, 2-output transaction
# Fee estimate - can be overridden via environment variable
import os
estimated_fee = float(os.environ.get('DOGE_REFUND_FEE_BUFFER', '0.005'))
logger.debug(f"Using fee buffer: {estimated_fee} DOGE")
# Check if we need to adjust for fees
if balance_result and total_output + estimated_fee > balance_result:
@ -329,13 +333,34 @@ class PaymentRescue:
try:
tx_hash = self.crypto_client.sendmany(from_account, clean_outputs, 1)
except Exception as e:
# If that fails, try with empty account (default)
if "insufficient funds" in str(e).lower():
tx_hash = self.crypto_client.sendmany("", clean_outputs, 1)
error_msg = str(e).lower()
if "insufficient funds" in error_msg:
# Log detailed fee information when we hit insufficient funds
logger.error(f"INSUFFICIENT FUNDS - Fee estimate too low!")
logger.error(f"Current fee buffer: {estimated_fee} DOGE")
logger.error(f"Total outputs: {sum(clean_outputs.values())} DOGE")
logger.error(f"Available balance: {balance_result} DOGE")
shortfall = sum(clean_outputs.values()) + estimated_fee - balance_result
logger.error(f"Shortfall: {shortfall:.8f} DOGE (may need more for actual network fee)")
logger.error(f"ACTION REQUIRED: Increase estimated_fee in crypto_payment_rescue.py line ~318")
# Try with default account as fallback
try:
tx_hash = self.crypto_client.sendmany("", clean_outputs, 1)
except Exception as e2:
if "insufficient funds" in str(e2).lower():
logger.error(f"Both accounts failed - fee definitely too low!")
raise e2
else:
raise
tx_result = {"tx_hash": tx_hash}
# Log success with fee info for monitoring
logger.info(f"Refund sent successfully! TX: {tx_hash}")
if balance_result:
buffer_used = balance_result - sum(clean_outputs.values())
logger.info(f"Fee buffer used: {buffer_used:.8f} DOGE (estimated: {estimated_fee})")
else:
raise ValueError(f"Refund not supported for coin type: {coin_type}")