fix up sweeping
This commit is contained in:
parent
751067bace
commit
19ebf9d2a2
4 changed files with 37 additions and 22 deletions
|
|
@ -24,7 +24,7 @@ var MAX_NOTIFY_AGE = 48 * 60 * 60 * 1000
|
|||
var MIN_NOTIFY_AGE = 5 * 60 * 1000
|
||||
var TRANSACTION_EXPIRATION = 48 * 60 * 60 * 1000
|
||||
var SWEEP_LIVE_HD_INTERVAL = 60 * 1000
|
||||
var SWEEP_OLD_HD_INTERVAL = 60 * 60 * 1000
|
||||
var SWEEP_OLD_HD_INTERVAL = 2 * 60 * 1000
|
||||
var TRADE_INTERVAL = 60 * 1000
|
||||
|
||||
var cryptoCodes = null
|
||||
|
|
@ -468,6 +468,7 @@ exports.startPolling = function startPolling () {
|
|||
monitorIncoming()
|
||||
monitorUnnotified()
|
||||
sweepLiveHD()
|
||||
sweepOldHD()
|
||||
}
|
||||
|
||||
function startTrader (cryptoCode) {
|
||||
|
|
@ -791,9 +792,11 @@ function sweepHD (row) {
|
|||
function sweepLiveHD () {
|
||||
return db.fetchLiveHD()
|
||||
.then(rows => Promise.all(rows.map(sweepHD)))
|
||||
.catch(err => logger.error(err))
|
||||
}
|
||||
|
||||
function sweepOldHD () {
|
||||
return db.fetchOldHD()
|
||||
.then(rows => Promise.all(rows.map(sweepHD)))
|
||||
.catch(err => logger.error(err))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -332,10 +332,7 @@ exports.updateTxStatus = function updateTxStatus (tx, status) {
|
|||
const values2 = [newStatus, tx.sessionId]
|
||||
|
||||
return t.none(sql2, values2)
|
||||
.then(() => {
|
||||
const sql3 = 'insert into cash_out_actions (session_id, action) values ($1, $2)'
|
||||
return t.none(sql3, [tx.sessionId, newStatus])
|
||||
})
|
||||
.then(() => ({status: newStatus}))
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -344,6 +341,18 @@ exports.updateTxStatus = function updateTxStatus (tx, status) {
|
|||
// Note: don't worry about retrying failed transaction here
|
||||
// It will be tried again on the next status check
|
||||
return db.tx(transaction)
|
||||
.then(r => {
|
||||
if (!r) return
|
||||
|
||||
const sql3 = 'insert into cash_out_actions (session_id, action) values ($1, $2)'
|
||||
return db.none(sql3, [tx.sessionId, r.status])
|
||||
.then(() => {
|
||||
if (r.status === 'confirmed') {
|
||||
const sql4 = `update cash_out_hds set confirmed=true where session_id=$1`
|
||||
return db.none(sql4, [tx.sessionId])
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
exports.updateRedeem = function updateRedeem (session) {
|
||||
|
|
@ -449,23 +458,12 @@ exports.fetchLiveHD = function fetchLiveHD () {
|
|||
}
|
||||
|
||||
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 sql = `select * from cash_out_hds
|
||||
where confirmed
|
||||
order by last_checked
|
||||
limit 10`
|
||||
|
||||
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)
|
||||
})
|
||||
return db.manyOrNone(sql)
|
||||
}
|
||||
|
||||
exports.markSwept = function markSwept (sessionId) {
|
||||
|
|
|
|||
14
migrations/013-add-last-checked.js
Normal file
14
migrations/013-add-last-checked.js
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
var db = require('./db')
|
||||
|
||||
exports.up = function (next) {
|
||||
var sql = [
|
||||
'alter table cash_out_hds add last_checked timestamptz not null default now()',
|
||||
'alter table cash_out_hds add confirmed boolean not null default false',
|
||||
'create index on cash_out_hds (confirmed, last_checked)'
|
||||
]
|
||||
db.multi(sql, next)
|
||||
}
|
||||
|
||||
exports.down = function (next) {
|
||||
next()
|
||||
}
|
||||
2
todo.txt
2
todo.txt
|
|
@ -1,4 +1,4 @@
|
|||
- l-m shouldn't keep polling l-s when not on pending screen (low priority)
|
||||
|
||||
- scrutinize hkdf, maybe use own simplified version
|
||||
- test geth cash-out
|
||||
- test eth cash-out confirmation record in cash_out_hds
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue