Fix sweep confirmation monitoring to use coin-specific thresholds

- Query DOGE sweeps only if < 2 confirmations
- Query XMR sweeps only if < 10 confirmations
- Set model default to 0 for new sweeps
- Migration sets server_default to 10 for existing records
- This prevents monitoring already-confirmed legacy sweeps
This commit is contained in:
Russell Ballestrini 2025-10-02 19:15:09 -04:00
parent a74bf72e6a
commit d90f41c5d9
2 changed files with 19 additions and 13 deletions

View file

@ -3357,19 +3357,25 @@ def process_sweep_confirmations(request, settings):
db = request.dbsession
# Query payments that need sweep confirmation monitoring
sweep_queue = (
db.query(CryptoPayment)
.options(
sa.orm.joinedload(CryptoPayment.user),
sa.orm.joinedload(CryptoPayment.shop),
sweep_queue = []
# Query each coin type with its specific threshold
for coin_type, required_confirmations in OUTBOUND_CONFIRMATIONS_REQUIRED.items():
coin_sweeps = (
db.query(CryptoPayment)
.options(
sa.orm.joinedload(CryptoPayment.user),
sa.orm.joinedload(CryptoPayment.shop),
)
.filter(
CryptoPayment.status == CryptoPayment.STATUS_CONFIRMED,
CryptoPayment.coin_type == coin_type,
CryptoPayment.swept_tx_hash != None,
CryptoPayment.swept_confirmations < required_confirmations,
)
.all()
)
.filter(
CryptoPayment.status == CryptoPayment.STATUS_CONFIRMED,
CryptoPayment.swept_tx_hash != None,
CryptoPayment.swept_confirmations < 10, # Max threshold
)
.all()
)
sweep_queue.extend(coin_sweeps)
if not sweep_queue:
log.processing_cycle("No sweep transactions need confirmation monitoring")

View file

@ -21,7 +21,7 @@ from make_post_sell.models.meta import UUIDType
def upgrade():
# Add swept_confirmations column to mps_crypto_payment table
op.add_column('mps_crypto_payment',
sa.Column('swept_confirmations', sa.Integer(), nullable=False, server_default='0')
sa.Column('swept_confirmations', sa.Integer(), nullable=False, server_default='10')
)