implement HD sweep
This commit is contained in:
parent
0140e01c9f
commit
8f081ebf00
4 changed files with 67 additions and 1 deletions
|
|
@ -8,6 +8,7 @@ const backoff = require('u-promised').backoff
|
|||
const logger = require('./logger')
|
||||
|
||||
const CACHED_SESSION_TTL = 60 * 60 * 1000
|
||||
const LIVE_SWEEP_TTL = 48 * 60 * 60 * 1000
|
||||
|
||||
let db
|
||||
|
||||
|
|
@ -441,3 +442,39 @@ exports.nextCashOutSerialHD = function nextCashOutSerialHD (sessionId, cryptoCod
|
|||
|
||||
return backoff(100, 0, 5, attempt)
|
||||
}
|
||||
|
||||
exports.fetchLiveHD = function fetchLiveHD () {
|
||||
const sql = `select * from cash_out_txs, cash_out_hds
|
||||
where cash_out_txs.session_id=cash_out_hds.session_id
|
||||
and status=$1 and swept=$2 and
|
||||
((extract(epoch from (now() - cash_out_txs.created))) * 1000)<$3`
|
||||
|
||||
const values = ['confirmed', false, LIVE_SWEEP_TTL]
|
||||
|
||||
return db.manyOrNone(sql, values)
|
||||
}
|
||||
|
||||
exports.fetchOldHD = function fetchLiveHD () {
|
||||
db.one(`select reltuples as approximate_row_count from pg_class where relname = 'cash_out_txs'`)
|
||||
.then(row => {
|
||||
const rowCount = row.approximate_row_count
|
||||
|
||||
const factor = rowCount < 1000
|
||||
? 10
|
||||
: rowCount < 10000 ? 1 : 0.1
|
||||
|
||||
const sql = `select * from cash_out_txs tablesample system $1,
|
||||
cash_out_hds
|
||||
where cash_out_txs.session_id=cash_out_hds.session_id
|
||||
and status=$2`
|
||||
|
||||
const values = [factor, 'confirmed']
|
||||
|
||||
return db.manyOrNone(sql, values)
|
||||
})
|
||||
}
|
||||
|
||||
exports.markSwept = function markSwept (sessionId) {
|
||||
const sql = `update cash_out_hds set swept=$1 where session_id=$2`
|
||||
return db.none(sql, [true, sessionId])
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue