Browse Source

Consistent dust threshold in client and obwatch

Fixes #899.
Before this commit, the dust threshold used to filter
orders in `jmdaemon.OrderbookWatch` was different than
that used in `jmclient`. This is corrected by setting
the threshold in client config and passing this as a
parameter in the `JMInit` command (since the daemon
does not know the client config).
master
Adam Gibson 4 years ago
parent
commit
24f3aabf9e
No known key found for this signature in database
GPG Key ID: 141001A1AF77F20B
  1. 3
      jmbase/jmbase/commands.py
  2. 3
      jmbase/jmbase/support.py
  3. 3
      jmbitcoin/jmbitcoin/__init__.py
  4. 6
      jmclient/jmclient/client_protocol.py
  5. 2
      jmclient/jmclient/configure.py
  6. 4
      jmclient/test/test_client_protocol.py
  7. 4
      jmdaemon/jmdaemon/daemon_protocol.py
  8. 6
      jmdaemon/jmdaemon/orderbookwatch.py
  9. 6
      jmdaemon/test/test_daemon_protocol.py
  10. 3
      jmdaemon/test/test_orderbookwatch.py
  11. 6
      scripts/joinmarket-qt.py
  12. 6
      scripts/sendpayment.py

3
jmbase/jmbase/commands.py

@ -31,7 +31,8 @@ class JMInit(JMCommand):
(b'network', Unicode()),
(b'irc_configs', Unicode()),
(b'minmakers', Integer()),
(b'maker_timeout_sec', Integer())]
(b'maker_timeout_sec', Integer()),
(b'dust_threshold', Integer())]
errors = {DaemonNotReady: b'daemon is not ready'}
class JMStartMC(JMCommand):

3
jmbase/jmbase/support.py

@ -71,9 +71,6 @@ joinmarket_alert = ['']
core_alert = ['']
debug_silence = [False]
#TODO pass this through from client, bitcoin paramater:
DUST_THRESHOLD = 2730
class JoinMarketStreamHandler(ColorizingStreamHandler):
def __init__(self):

3
jmbitcoin/jmbitcoin/__init__.py

@ -14,6 +14,9 @@ if os.path.exists(expected_secp_location):
import bitcointx
bitcointx.set_custom_secp256k1_path(expected_secp_location)
# Bitcoin network level utxo amount limit:
DUST_THRESHOLD = 2730
from jmbitcoin.secp256k1_main import *
from jmbitcoin.secp256k1_transaction import *
from jmbitcoin.secp256k1_deterministic import *

6
jmclient/jmclient/client_protocol.py

@ -425,7 +425,8 @@ class JMMakerClientProtocol(JMClientProtocol):
network=network,
irc_configs=json.dumps(irc_configs),
minmakers=minmakers,
maker_timeout_sec=maker_timeout_sec)
maker_timeout_sec=maker_timeout_sec,
dust_threshold=jm_single().DUST_THRESHOLD)
self.defaultCallbacks(d)
@commands.JMFidelityBondProofRequest.responder
@ -602,7 +603,8 @@ class JMTakerClientProtocol(JMClientProtocol):
network=network,
irc_configs=json.dumps(irc_configs),
minmakers=minmakers,
maker_timeout_sec=maker_timeout_sec)
maker_timeout_sec=maker_timeout_sec,
dust_threshold=jm_single().DUST_THRESHOLD)
self.defaultCallbacks(d)
def stallMonitor(self, schedule_index):

2
jmclient/jmclient/configure.py

@ -63,7 +63,7 @@ global_singleton.JM_VERSION = 5
global_singleton.APPNAME = JM_APP_NAME
global_singleton.datadir = None
global_singleton.nickname = None
global_singleton.BITCOIN_DUST_THRESHOLD = 2730
global_singleton.BITCOIN_DUST_THRESHOLD = btc.DUST_THRESHOLD
global_singleton.DUST_THRESHOLD = 10 * global_singleton.BITCOIN_DUST_THRESHOLD
global_singleton.bc_interface = None
global_singleton.maker_timeout_sec = 60

4
jmclient/test/test_client_protocol.py

@ -166,9 +166,9 @@ class JMTestServerProtocol(JMBaseProtocol):
@JMInit.responder
def on_JM_INIT(self, bcsource, network, irc_configs, minmakers,
maker_timeout_sec):
maker_timeout_sec, dust_threshold):
show_receipt("JMINIT", bcsource, network, irc_configs, minmakers,
maker_timeout_sec)
maker_timeout_sec, dust_threshold)
d = self.callRemote(JMInitProto,
nick_hash_length=1,
nick_max_encoded=2,

4
jmdaemon/jmdaemon/daemon_protocol.py

@ -495,7 +495,7 @@ class JMDaemonServerProtocol(amp.AMP, OrderbookWatch):
@JMInit.responder
def on_JM_INIT(self, bcsource, network, irc_configs, minmakers,
maker_timeout_sec):
maker_timeout_sec, dust_threshold):
"""Reads in required configuration from client for a new
session; feeds back joinmarket messaging protocol constants
(required for nick creation).
@ -503,6 +503,8 @@ class JMDaemonServerProtocol(amp.AMP, OrderbookWatch):
one is shutdown in preparation.
"""
self.maker_timeout_sec = int(maker_timeout_sec)
# used in OrderbookWatch:
self.dust_threshold = int(dust_threshold)
self.minmakers = int(minmakers)
irc_configs = json.loads(irc_configs)
#(bitcoin) network only referenced in channel name construction

6
jmdaemon/jmdaemon/orderbookwatch.py

@ -8,7 +8,7 @@ from numbers import Integral
from jmdaemon.protocol import JM_VERSION
from jmdaemon import fidelity_bond_sanity_check
from jmbase.support import get_log, joinmarket_alert, DUST_THRESHOLD
from jmbase.support import get_log, joinmarket_alert
log = get_log()
@ -88,8 +88,8 @@ class OrderbookWatch(object):
log.debug("Got invalid minsize: {} from {}".format(
minsize, counterparty))
return
if int(minsize) < DUST_THRESHOLD:
minsize = DUST_THRESHOLD
if int(minsize) < self.dust_threshold:
minsize = self.dust_threshold
log.debug("{} has dusty minsize, capping at {}".format(
counterparty, minsize))
# do not pass return, go not drop this otherwise fine offer

6
jmdaemon/test/test_daemon_protocol.py

@ -66,7 +66,8 @@ class JMTestClientProtocol(JMBaseProtocol):
network="dummynetwork",
irc_configs=json.dumps(irc),
minmakers=2,
maker_timeout_sec=3)
maker_timeout_sec=3,
dust_threshold=27300)
self.defaultCallbacks(d)
@JMInitProto.responder
@ -213,8 +214,9 @@ class JMDaemonTestServerProtocol(JMDaemonServerProtocol):
@JMInit.responder
def on_JM_INIT(self, bcsource, network, irc_configs, minmakers,
maker_timeout_sec):
maker_timeout_sec, dust_threshold):
self.maker_timeout_sec = int(maker_timeout_sec)
self.dust_threshold = int(dust_threshold)
self.minmakers = int(minmakers)
mcs = [DummyMC(None)]
self.mcc = MessageChannelCollection(mcs)

3
jmdaemon/test/test_orderbookwatch.py

@ -30,6 +30,9 @@ def get_ob():
ob = OrderbookWatch()
ob.on_welcome = on_welcome
ob.set_msgchan(mc)
# would usually be set in JMInit; we use
# a fake small value to allow small orders:
ob.dust_threshold = 2
return ob
@pytest.mark.parametrize(

6
scripts/joinmarket-qt.py

@ -56,7 +56,7 @@ donation_address_url = "https://bitcoinprivacy.me/joinmarket-donations"
JM_GUI_VERSION = '22dev'
from jmbase import get_log, stop_reactor
from jmbase.support import DUST_THRESHOLD, EXIT_FAILURE, utxo_to_utxostr,\
from jmbase.support import EXIT_FAILURE, utxo_to_utxostr,\
hextobin, JM_CORE_VERSION
import jmbitcoin as btc
from jmclient import load_program_config, get_network, update_persist_config,\
@ -370,11 +370,11 @@ class SpendTab(QWidget):
except ValueError as e:
JMQtMessageBox(self, e.args[0], title="Error", mbtype="warn")
return False
if amount_sat < DUST_THRESHOLD:
if amount_sat < jm_single().DUST_THRESHOLD:
JMQtMessageBox(self,
"Amount " + btc.amount_to_str(amount_sat) +
" is below dust threshold " +
btc.amount_to_str(DUST_THRESHOLD) + ".",
btc.amount_to_str(jm_single().DUST_THRESHOLD) + ".",
mbtype='warn',
title="Error")
return False

6
scripts/sendpayment.py

@ -21,7 +21,7 @@ from jmclient import Taker, load_program_config, get_schedule,\
detect_script_type, EngineError
from twisted.python.log import startLogging
from jmbase.support import get_log, jmprint, \
EXIT_FAILURE, EXIT_ARGERROR, DUST_THRESHOLD
EXIT_FAILURE, EXIT_ARGERROR
import jmbitcoin as btc
@ -102,10 +102,10 @@ def main():
jmprint("The required options for burning coins are zero makers"
+ " (-N 0), sweeping (amount = 0) and not using BIP78 Payjoin", "info")
sys.exit(EXIT_ARGERROR)
if sweeping == False and amount < DUST_THRESHOLD:
if sweeping == False and amount < jm_single().DUST_THRESHOLD:
jmprint('ERROR: Amount ' + btc.amount_to_str(amount) +
' is below dust threshold ' +
btc.amount_to_str(DUST_THRESHOLD) + '.', "error")
btc.amount_to_str(jm_single().DUST_THRESHOLD) + '.', "error")
sys.exit(EXIT_ARGERROR)
if (options.makercount != 0 and
options.makercount < jm_single().config.getint(

Loading…
Cancel
Save