From 7043a3c40880533b2fdc1c08676d860f033f2379 Mon Sep 17 00:00:00 2001 From: Rafael Taranto Date: Sun, 30 Dec 2018 10:47:09 -0300 Subject: [PATCH 1/6] Retry downloading OFAC lists (#236) * Retry downloading OFAC lists * Update ofac sources on lamassu-update --- bin/lamassu-ofac-update-sources | 23 +++++++++++++++++++++++ bin/lamassu-update | 3 +++ lib/ofac/index.js | 6 +++++- lib/ofac/update.js | 4 ++++ lib/poller.js | 13 +++++++++++++ 5 files changed, 48 insertions(+), 1 deletion(-) create mode 100755 bin/lamassu-ofac-update-sources diff --git a/bin/lamassu-ofac-update-sources b/bin/lamassu-ofac-update-sources new file mode 100755 index 00000000..83f6c011 --- /dev/null +++ b/bin/lamassu-ofac-update-sources @@ -0,0 +1,23 @@ +#!/usr/bin/env node + +'use strict' + +const fs = require('fs') + +const ofacSources = [ + { + name: 'sdn_advanced', + url: 'https://www.treasury.gov/ofac/downloads/sanctions/1.0/sdn_advanced.xml' + }, + { + name: 'cons_advanced', + url: 'https://www.treasury.gov/ofac/downloads/sanctions/1.0/cons_advanced.xml' + } +] + +const options = require('../lib/options-loader')() + +if (!options.opts.ofacSources) { + options.opts.ofacSources = ofacSources + fs.writeFileSync(options.path, JSON.stringify(options.opts, null, ' '), 'utf8') +} diff --git a/bin/lamassu-update b/bin/lamassu-update index 9b770460..90b6131c 100755 --- a/bin/lamassu-update +++ b/bin/lamassu-update @@ -55,6 +55,9 @@ decho "running migration" lamassu-migrate >> ${LOG_FILE} 2>&1 lamassu-migrate-config >> ${LOG_FILE} 2>&1 +decho "update ofac sources" +$SCRIPTPATH/bin/lamassu-ofac-update-sources + decho "updating supervisor conf" perl -i -pe 's/command=.*/command=$ENV{NPM_BIN}\/lamassu-server/g' /etc/supervisor/conf.d/lamassu-server.conf >> ${LOG_FILE} 2>&1 perl -i -pe 's/command=.*/command=$ENV{NPM_BIN}\/lamassu-admin-server/g' /etc/supervisor/conf.d/lamassu-admin-server.conf >> ${LOG_FILE} 2>&1 diff --git a/lib/ofac/index.js b/lib/ofac/index.js index 0669f2d5..4d352263 100644 --- a/lib/ofac/index.js +++ b/lib/ofac/index.js @@ -75,4 +75,8 @@ function match (nameParts, birthDateString, options) { return result } -module.exports = {load, match} +function getStructs () { + return structs +} + +module.exports = {load, match, getStructs} diff --git a/lib/ofac/update.js b/lib/ofac/update.js index 35271370..5cf7a351 100644 --- a/lib/ofac/update.js +++ b/lib/ofac/update.js @@ -103,6 +103,10 @@ function update () { throw new Error('ofacDataDir must be defined in lamassu.json') } + if (!options.ofacSources) { + logger.error('ofacSources must be defined in lamassu.json') + } + const OFAC_SOURCES_DIR = path.join(OFAC_DATA_DIR, 'sources') const OFAC_ETAGS_FILE = path.join(OFAC_DATA_DIR, 'etags.json') diff --git a/lib/poller.js b/lib/poller.js index 64681bdb..2e539f6a 100644 --- a/lib/poller.js +++ b/lib/poller.js @@ -1,3 +1,5 @@ +const _ = require('lodash/fp') + const plugins = require('./plugins') const notifier = require('./notifier') const T = require('./time') @@ -16,6 +18,7 @@ const SWEEP_HD_INTERVAL = T.minute const TRADE_INTERVAL = 60 * T.seconds const PONG_INTERVAL = 10 * T.seconds const PONG_CLEAR_INTERVAL = 1 * T.day +const SANCTIONS_INITIAL_DOWNLOAD_INTERVAL = 5 * T.minutes const SANCTIONS_UPDATE_INTERVAL = 1 * T.week const RADAR_UPDATE_INTERVAL = 5 * T.minutes @@ -35,6 +38,15 @@ function reload (__settings) { function pi () { return _pi } function settings () { return _settings } +function initialSanctionsDownload () { + const structs = sanctions.getStructs() + const isEmptyStructs = _.isNil(structs) || _.flow(_.values, _.all(_.isEmpty))(structs) + + if (!isEmptyStructs) return Promise.resolve() + + return updateAndLoadSanctions() +} + function updateAndLoadSanctions () { const config = configManager.unscoped(settings().config) @@ -75,6 +87,7 @@ function start (__settings) { setInterval(() => pi().pong(), PONG_INTERVAL) setInterval(() => pi().pongClear(), PONG_CLEAR_INTERVAL) setInterval(() => notifier.checkNotification(pi()), CHECK_NOTIFICATION_INTERVAL) + setInterval(initialSanctionsDownload, SANCTIONS_INITIAL_DOWNLOAD_INTERVAL) setInterval(updateAndLoadSanctions, SANCTIONS_UPDATE_INTERVAL) setInterval(updateCoinAtmRadar, RADAR_UPDATE_INTERVAL) } From 07626cf5056df978cd81c59ca7d80455218ea7d5 Mon Sep 17 00:00:00 2001 From: Neal Conner Date: Sun, 30 Dec 2018 17:07:47 -0500 Subject: [PATCH 2/6] Add lamassu-ofac-update-sources --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 348045f5..083f8f62 100644 --- a/package.json +++ b/package.json @@ -80,7 +80,8 @@ "lamassu-coins": "./bin/lamassu-coins", "lamassu-update": "./bin/lamassu-update", "lamassu-ofac-update": "./bin/lamassu-ofac-update", - "lamassu-send-coins": "./bin/lamassu-send-coins" + "lamassu-send-coins": "./bin/lamassu-send-coins", + "lamassu-ofac-update-sources": "./bin/lamassu-ofac-update-sources" }, "scripts": { "start": "node bin/lamassu-server", From df13f2ed908ae849f11af2bbecb5e994fa4edd75 Mon Sep 17 00:00:00 2001 From: Neal Conner Date: Fri, 18 Jan 2019 17:37:20 -0500 Subject: [PATCH 3/6] Fix lamassu-ofac-update-sources during update Otherwise: ``` bash: line 59: /bin/lamassu-ofac-update-sources: No such file or directory ``` --- bin/lamassu-update | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/lamassu-update b/bin/lamassu-update index 90b6131c..1f579ab8 100755 --- a/bin/lamassu-update +++ b/bin/lamassu-update @@ -56,7 +56,7 @@ lamassu-migrate >> ${LOG_FILE} 2>&1 lamassu-migrate-config >> ${LOG_FILE} 2>&1 decho "update ofac sources" -$SCRIPTPATH/bin/lamassu-ofac-update-sources +lamassu-ofac-update-sources >> ${LOG_FILE} 2>&1 decho "updating supervisor conf" perl -i -pe 's/command=.*/command=$ENV{NPM_BIN}\/lamassu-server/g' /etc/supervisor/conf.d/lamassu-server.conf >> ${LOG_FILE} 2>&1 From 9364eb5132bb651c37e7e13de82a4260189c7afe Mon Sep 17 00:00:00 2001 From: Rafael Taranto Date: Thu, 7 Feb 2019 16:43:57 -0300 Subject: [PATCH 4/6] Fix cash-out exchange behavior for 'rejected' tx A TX on the 'rejected' state should still be watched for authorization. This fixes the bug where delayed cash-out confirmations would not trigger a exchange sell command. --- lib/cash-out/cash-out-atomic.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/cash-out/cash-out-atomic.js b/lib/cash-out/cash-out-atomic.js index 369ef42c..382ec519 100644 --- a/lib/cash-out/cash-out-atomic.js +++ b/lib/cash-out/cash-out-atomic.js @@ -119,10 +119,10 @@ function updateCassettes (t, tx) { } function wasJustAuthorized (oldTx, newTx, isZeroConf) { - const isAuthorized = () => _.includes(oldTx.status, ['notSeen', 'published']) && + const isAuthorized = () => _.includes(oldTx.status, ['notSeen', 'published', 'rejected']) && _.includes(newTx.status, ['authorized', 'instant', 'confirmed']) - const isConfirmed = () => _.includes(oldTx.status, ['notSeen', 'published', 'authorized']) && + const isConfirmed = () => _.includes(oldTx.status, ['notSeen', 'published', 'authorized', 'rejected']) && _.includes(newTx.status, ['instant', 'confirmed']) return isZeroConf ? isAuthorized() : isConfirmed() From f02e34ca9ce28ca8ad0526f1f42ee83b44ba8532 Mon Sep 17 00:00:00 2001 From: Neal Conner Date: Fri, 15 Feb 2019 14:18:33 -0500 Subject: [PATCH 5/6] Update ZEC, BCH, ETH node versions --- lib/blockchain/common.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/blockchain/common.js b/lib/blockchain/common.js index fce05ef7..24bf8035 100644 --- a/lib/blockchain/common.js +++ b/lib/blockchain/common.js @@ -25,12 +25,12 @@ const BINARIES = { dir: 'bitcoin-0.16.3/bin' }, ETH: { - url: 'https://gethstore.blob.core.windows.net/builds/geth-linux-amd64-1.8.19-dae82f09.tar.gz', - dir: 'geth-linux-amd64-1.8.19-dae82f09' + url: 'https://gethstore.blob.core.windows.net/builds/geth-linux-amd64-1.8.22-7fa3509e.tar.gz', + dir: 'geth-linux-amd64-1.8.22-7fa3509e' }, ZEC: { - url: 'https://z.cash/downloads/zcash-2.0.2-linux64.tar.gz', - dir: 'zcash-2.0.2/bin' + url: 'https://z.cash/downloads/zcash-2.0.3-linux64.tar.gz', + dir: 'zcash-2.0.3/bin' }, DASH: { url: 'https://github.com/dashpay/dash/releases/download/v0.12.3.3/dashcore-0.12.3.3-x86_64-linux-gnu.tar.gz', @@ -41,8 +41,8 @@ const BINARIES = { dir: 'litecoin-0.16.3/bin' }, BCH: { - url: 'https://download.bitcoinabc.org/0.18.5/linux/bitcoin-abc-0.18.5-x86_64-linux-gnu.tar.gz', - dir: 'bitcoin-abc-0.18.5/bin', + url: 'https://download.bitcoinabc.org/0.18.8/linux/bitcoin-abc-0.18.8-x86_64-linux-gnu.tar.gz', + dir: 'bitcoin-abc-0.18.8/bin', files: [['bitcoind', 'bitcoincashd'], ['bitcoin-cli', 'bitcoincash-cli']] } } From 4a95c7f91b39cbdb455872c99ff8819234a3d801 Mon Sep 17 00:00:00 2001 From: Neal Conner Date: Fri, 22 Feb 2019 11:56:22 -0500 Subject: [PATCH 6/6] Update BCH for May 2019 upgrade --- lib/blockchain/common.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/blockchain/common.js b/lib/blockchain/common.js index 24bf8035..90beaaf2 100644 --- a/lib/blockchain/common.js +++ b/lib/blockchain/common.js @@ -41,8 +41,8 @@ const BINARIES = { dir: 'litecoin-0.16.3/bin' }, BCH: { - url: 'https://download.bitcoinabc.org/0.18.8/linux/bitcoin-abc-0.18.8-x86_64-linux-gnu.tar.gz', - dir: 'bitcoin-abc-0.18.8/bin', + url: 'https://download.bitcoinabc.org/0.19.0/linux/bitcoin-abc-0.19.0-x86_64-linux-gnu.tar.gz', + dir: 'bitcoin-abc-0.19.0/bin', files: [['bitcoind', 'bitcoincashd'], ['bitcoin-cli', 'bitcoincash-cli']] } }