From ab87db2477f0a423dd36b4a2fcbfc1691c54d6ec Mon Sep 17 00:00:00 2001 From: Jules Comte Date: Mon, 3 Aug 2020 20:30:54 -0400 Subject: [PATCH] Create native segwit v0 order type Note: The defaults for the fake offer and yg-privacyenhanced remain on nested segwit --- docs/YIELDGENERATOR.md | 8 ++++---- jmclient/jmclient/configure.py | 9 +++++---- jmclient/jmclient/support.py | 12 ++++++------ jmclient/jmclient/taker.py | 16 ++++++++++++---- jmclient/jmclient/wallet_utils.py | 8 ++++---- jmclient/jmclient/yieldgenerator.py | 13 +++++++------ jmclient/test/commontest.py | 4 ++-- jmclient/test/taker_test_data.py | 18 +++++++++--------- jmclient/test/test_client_protocol.py | 2 +- jmclient/test/test_maker.py | 2 +- jmclient/test/test_snicker.py | 7 +++++-- jmclient/test/test_support.py | 6 ++++-- jmclient/test/test_tx_creation.py | 2 +- jmclient/test/test_yieldgenerator.py | 4 ++-- jmdaemon/jmdaemon/protocol.py | 4 ++++ scripts/joinmarket-qt.py | 4 ++-- scripts/obwatch/ob-watcher.py | 7 ++++--- scripts/sendpayment.py | 13 ++++++------- scripts/tumbler.py | 2 +- scripts/yg-privacyenhanced.py | 8 ++++---- scripts/yield-generator-basic.py | 2 +- test/common.py | 4 ++-- test/ygrunner.py | 2 +- 23 files changed, 88 insertions(+), 69 deletions(-) diff --git a/docs/YIELDGENERATOR.md b/docs/YIELDGENERATOR.md index f4981af..d9209a7 100644 --- a/docs/YIELDGENERATOR.md +++ b/docs/YIELDGENERATOR.md @@ -24,14 +24,14 @@ Open one of the two built-in yield generators: `yield-generator-basic.py` or `yg txfee = 1000 cjfee_a = 2000 cjfee_r = '0.0002' # 0.02% fee - ordertype = 'swreloffer' + ordertype = 'sw0reloffer' minsize = int(1.2 * txfee / float(cjfee)) #minimum size is such that you always net profit at least 20% of the miner fee Meaning of fields: + txfee. The yield generators contribution to the miner fee. -+ ordertype. One of 'swreloffer' or 'swabsoffer'. -+ cjfee_r. Your offered coinjoin fee as a fraction of the coinjoin amount (for 'swreloffer'). Takers pay this to you. -+ cjfee_a. Your offered coinjoin fee as an absolute number of satoshis (for 'swabsoffer') ++ ordertype. One of 'swreloffer', 'swabsoffer', 'sw0reloffer', 'sw0absoffer'. ++ cjfee_r. Your offered coinjoin fee as a fraction of the coinjoin amount (for 'swreloffer', 'sw0reloffer'). Takers pay this to you. ++ cjfee_a. Your offered coinjoin fee as an absolute number of satoshis (for 'swabsoffer', 'sw0absoffer') ## Keeping Track of Returns diff --git a/jmclient/jmclient/configure.py b/jmclient/jmclient/configure.py index bb1bf96..1dc9dee 100644 --- a/jmclient/jmclient/configure.py +++ b/jmclient/jmclient/configure.py @@ -185,10 +185,11 @@ confirm_timeout_hours = 6 # Only set to false for old wallets, Joinmarket is now segwit only. segwit = true -# Use native segwit (bech32) wallet. This is NOT -# currently supported in Joinmarket coinjoins. Only set to "true" -# if specifically advised to do so. -native = false +# Use native segwit (bech32) wallet. If set to false, p2sh-p2wkh +# will be used when generating the addresses for this wallet. +# Notes: 1. The default joinmarket pit is native segwit. +# 2. You cannot change the type of a pre-existing wallet. +native = true # for dust sweeping, try merge_algorithm = gradual # for more rapid dust sweeping, try merge_algorithm = greedy diff --git a/jmclient/jmclient/support.py b/jmclient/jmclient/support.py index f2d8cef..3f1b971 100644 --- a/jmclient/jmclient/support.py +++ b/jmclient/jmclient/support.py @@ -174,9 +174,9 @@ def select_one_utxo(unspent, value): def calc_cj_fee(ordertype, cjfee, cj_amount): - if ordertype in ['swabsoffer', 'absoffer']: + if ordertype in ['sw0absoffer', 'swabsoffer', 'absoffer']: real_cjfee = int(cjfee) - elif ordertype in ['swreloffer', 'reloffer']: + elif ordertype in ['sw0reloffer', 'swreloffer', 'reloffer']: real_cjfee = int((Decimal(cjfee) * Decimal(cj_amount)).quantize(Decimal( 1))) else: @@ -235,7 +235,7 @@ def _get_is_within_max_limits(max_fee_rel, max_fee_abs, cjvalue): def choose_orders(offers, cj_amount, n, chooseOrdersBy, ignored_makers=None, - pick=False, allowed_types=["swreloffer", "swabsoffer"], + pick=False, allowed_types=["sw0reloffer", "sw0absoffer"], max_cj_fee=(1, float('inf'))): is_within_max_limits = _get_is_within_max_limits( max_cj_fee[0], max_cj_fee[1], cj_amount) @@ -301,7 +301,7 @@ def choose_sweep_orders(offers, n, chooseOrdersBy, ignored_makers=None, - allowed_types=['swreloffer', 'swabsoffer'], + allowed_types=['sw0reloffer', 'sw0absoffer'], max_cj_fee=(1, float('inf'))): """ choose an order given that we want to be left with no change @@ -325,9 +325,9 @@ def choose_sweep_orders(offers, sumtxfee_contribution = 0 for order in ordercombo: sumtxfee_contribution += order['txfee'] - if order['ordertype'] in ['swabsoffer', 'absoffer']: + if order['ordertype'] in ['sw0absoffer', 'swabsoffer', 'absoffer']: sumabsfee += int(order['cjfee']) - elif order['ordertype'] in ['swreloffer', 'reloffer']: + elif order['ordertype'] in ['sw0reloffer', 'swreloffer', 'reloffer']: sumrelfee += Decimal(order['cjfee']) #this is unreachable since calc_cj_fee must already have been called else: #pragma: no cover diff --git a/jmclient/jmclient/taker.py b/jmclient/jmclient/taker.py index 5a60d04..bdd8e6e 100644 --- a/jmclient/jmclient/taker.py +++ b/jmclient/jmclient/taker.py @@ -250,8 +250,12 @@ class Taker(object): if sweep: self.orderbook = orderbook #offers choosing deferred to next step else: - allowed_types = ["reloffer", "absoffer"] if jm_single().config.get( - "POLICY", "segwit") == "false" else ["swreloffer", "swabsoffer"] + if jm_single().config.get("POLICY", "segwit") == "false": + allowed_types = ["reloffer", "absoffer"] + elif jm_single().config.get("POLICY", "native") == "false": + allowed_types = ["swreloffer", "swabsoffer"] + else: + allowed_types = ["sw0reloffer", "sw0absoffer"] self.orderbook, self.total_cj_fee = choose_orders( orderbook, self.cjamount, self.n_counterparties, self.order_chooser, self.ignored_makers, allowed_types=allowed_types, @@ -320,8 +324,12 @@ class Taker(object): txtype=self.wallet_service.get_txtype()) jlog.debug("We have a fee estimate: "+str(self.total_txfee)) total_value = sum([va['value'] for va in self.input_utxos.values()]) - allowed_types = ["reloffer", "absoffer"] if jm_single().config.get( - "POLICY", "segwit") == "false" else ["swreloffer", "swabsoffer"] + if jm_single().config.get("POLICY", "segwit") == "false": + allowed_types = ["reloffer", "absoffer"] + elif jm_single().config.get("POLICY", "native") == "false": + allowed_types = ["swreloffer", "swabsoffer"] + else: + allowed_types = ["sw0reloffer", "sw0absoffer"] self.orderbook, self.cjamount, self.total_cj_fee = choose_sweep_orders( self.orderbook, total_value, self.total_txfee, self.n_counterparties, self.order_chooser, diff --git a/jmclient/jmclient/wallet_utils.py b/jmclient/jmclient/wallet_utils.py index 07d00c7..0c77d1f 100644 --- a/jmclient/jmclient/wallet_utils.py +++ b/jmclient/jmclient/wallet_utils.py @@ -1001,7 +1001,7 @@ def wallet_importprivkey(wallet, mixdepth, key_type): "word mnemonic phrase. Make sure you have backups.", "warning") jmprint("WARNING: Make sure that the type of the public address previously " "derived from this private key matches the wallet type you are " - "currently using.") + "currently using.", "warning") jmprint("WARNING: Handling of raw ECDSA bitcoin private keys can lead to " "non-intuitive behaviour and loss of funds.\n Recommended instead " "is to use the \'sweep\' feature of sendpayment.py.", "warning") @@ -1263,7 +1263,7 @@ def create_wallet(path, password, max_mixdepth, wallet_cls, **kwargs): def open_test_wallet_maybe(path, seed, max_mixdepth, - test_wallet_cls=SegwitLegacyWallet, wallet_password_stdin=False, **kwargs): + test_wallet_cls=SegwitWallet, wallet_password_stdin=False, **kwargs): """ Create a volatile test wallet if path is a hex-encoded string of length 64, otherwise run open_wallet(). @@ -1279,8 +1279,8 @@ def open_test_wallet_maybe(path, seed, max_mixdepth, """ # If the native flag is set in the config, it overrides the argument # test_wallet_cls - if jm_single().config.get("POLICY", "native") == "true": - test_wallet_cls = SegwitWallet + if jm_single().config.get("POLICY", "native") == "false": + test_wallet_cls = SegwitLegacyWallet if len(seed) == test_wallet_cls.ENTROPY_BYTES * 2: try: seed = binascii.unhexlify(seed) diff --git a/jmclient/jmclient/yieldgenerator.py b/jmclient/jmclient/yieldgenerator.py index b816a6b..2383210 100644 --- a/jmclient/jmclient/yieldgenerator.py +++ b/jmclient/jmclient/yieldgenerator.py @@ -83,13 +83,13 @@ class YieldGeneratorBasic(YieldGenerator): max_mix = max(mix_balance, key=mix_balance.get) f = '0' - if self.ordertype in ('reloffer', 'swreloffer'): + if self.ordertype in ('reloffer', 'swreloffer', 'sw0reloffer'): f = self.cjfee_r #minimum size bumped if necessary such that you always profit #least 50% of the miner fee self.minsize = max(int(1.5 * self.txfee / float(self.cjfee_r)), self.minsize) - elif self.ordertype in ('absoffer', 'swabsoffer'): + elif self.ordertype in ('absoffer', 'swabsoffer', 'sw0absoffer'): f = str(self.txfee + self.cjfee_a) order = {'oid': 0, 'ordertype': self.ordertype, @@ -188,7 +188,7 @@ class YieldGeneratorBasic(YieldGenerator): return self.wallet_service.get_internal_addr(cjoutmix) -def ygmain(ygclass, txfee=1000, cjfee_a=200, cjfee_r=0.002, ordertype='swreloffer', +def ygmain(ygclass, txfee=1000, cjfee_a=200, cjfee_r=0.002, ordertype='sw0reloffer', nickserv_password='', minsize=100000, gaplimit=6): import sys @@ -222,19 +222,20 @@ def ygmain(ygclass, txfee=1000, cjfee_a=200, cjfee_r=0.002, ordertype='swreloffe wallet_name = args[0] ordertype = options.ordertype txfee = options.txfee - if ordertype in ('reloffer', 'swreloffer'): + if ordertype in ('reloffer', 'swreloffer', 'sw0reloffer'): if options.cjfee != '': cjfee_r = options.cjfee # minimum size is such that you always net profit at least 20% #of the miner fee minsize = max(int(1.2 * txfee / float(cjfee_r)), options.minsize) - elif ordertype in ('absoffer', 'swabsoffer'): + elif ordertype in ('absoffer', 'swabsoffer', 'sw0absoffer'): if options.cjfee != '': cjfee_a = int(options.cjfee) minsize = options.minsize else: parser.error('You specified an incorrect offer type which ' +\ - 'can be either swreloffer or swabsoffer') + 'can be either swreloffer, sw0reloffer, ' +\ + 'swabsoffer, or sw0absoffer') sys.exit(EXIT_ARGERROR) nickserv_password = options.password diff --git a/jmclient/test/commontest.py b/jmclient/test/commontest.py index f4c849c..ed63872 100644 --- a/jmclient/test/commontest.py +++ b/jmclient/test/commontest.py @@ -11,7 +11,7 @@ from jmbase import (get_log, hextobin, bintohex, dictchanger) from jmclient import ( jm_single, open_test_wallet_maybe, estimate_tx_fee, BlockchainInterface, BIP32Wallet, - SegwitLegacyWallet, WalletService, BTC_P2SH_P2WPKH) + SegwitWallet, WalletService, BTC_P2SH_P2WPKH) from jmbase.support import chunks import jmbitcoin as btc @@ -177,7 +177,7 @@ def make_wallets(n, sdev_amt=0, start_index=0, fixed_seeds=None, - wallet_cls=SegwitLegacyWallet, + wallet_cls=SegwitWallet, mixdepths=5, populate_internal=False): '''n: number of wallets to be created diff --git a/jmclient/test/taker_test_data.py b/jmclient/test/taker_test_data.py index 0ee3c09..ec65a77 100644 --- a/jmclient/test/taker_test_data.py +++ b/jmclient/test/taker_test_data.py @@ -1,15 +1,15 @@ #orderbook -t_orderbook = [{u'counterparty': u'J6FA1Gj7Ln4vSGne', u'ordertype': u'swreloffer', u'oid': 0, +t_orderbook = [{u'counterparty': u'J6FA1Gj7Ln4vSGne', u'ordertype': u'sw0reloffer', u'oid': 0, u'minsize': 7500000, u'txfee': 1000, u'maxsize': 599972700, u'cjfee': u'0.0002'}, - {u'counterparty': u'J6CFffuuewjG44UJ', u'ordertype': u'swreloffer', u'oid': 0, + {u'counterparty': u'J6CFffuuewjG44UJ', u'ordertype': u'sw0reloffer', u'oid': 0, u'minsize': 7500000, u'txfee': 1000, u'maxsize': 599972700, u'cjfee': u'0.0002'}, - {u'counterparty': u'J65z23xdjxJjC7er', u'ordertype': u'swreloffer', u'oid': 0, + {u'counterparty': u'J65z23xdjxJjC7er', u'ordertype': u'sw0reloffer', u'oid': 0, u'minsize': 7500000, u'txfee': 1000, u'maxsize': 599972700, u'cjfee': u'0.0002'}, - {u'counterparty': u'J64Ghp5PXCdY9H3t', u'ordertype': u'swreloffer', u'oid': 0, + {u'counterparty': u'J64Ghp5PXCdY9H3t', u'ordertype': u'sw0reloffer', u'oid': 0, u'minsize': 7500000, u'txfee': 1000, u'maxsize': 599972700, u'cjfee': u'0.0002'}, - {u'counterparty': u'J659UPUSLLjHJpaB', u'ordertype': u'swreloffer', u'oid': 0, + {u'counterparty': u'J659UPUSLLjHJpaB', u'ordertype': u'sw0reloffer', u'oid': 0, u'minsize': 7500000, u'txfee': 1000, u'maxsize': 599972700, u'cjfee': u'0.0002'}, - {u'counterparty': u'J6cBx1FwUVh9zzoO', u'ordertype': u'swreloffer', u'oid': 0, + {u'counterparty': u'J6cBx1FwUVh9zzoO', u'ordertype': u'sw0reloffer', u'oid': 0, u'minsize': 7500000, u'txfee': 1000, u'maxsize': 599972700, u'cjfee': u'0.0002'}] t_dest_addr = "mvw1NazKDRbeNufFANqpYNAANafsMC2zVU" @@ -19,21 +19,21 @@ t_chosen_orders = {u'J659UPUSLLjHJpaB': {u'cjfee': u'0.0002', u'maxsize': 599972700, u'minsize': 7500000, u'oid': 0, - u'ordertype': u'swreloffer', + u'ordertype': u'sw0reloffer', u'txfee': 1000}, u'J65z23xdjxJjC7er': {u'cjfee': u'0.0002', u'counterparty': u'J65z23xdjxJjC7er', u'maxsize': 599972700, u'minsize': 7500000, u'oid': 0, - u'ordertype': u'swreloffer', + u'ordertype': u'sw0reloffer', u'txfee': 1000}, u'J6CFffuuewjG44UJ': {u'cjfee': u'0.0002', u'counterparty': u'J6CFffuuewjG44UJ', u'maxsize': 599972700, u'minsize': 7500000, u'oid': 0, - u'ordertype': u'swreloffer', + u'ordertype': u'sw0reloffer', u'txfee': 1000}} """ diff --git a/jmclient/test/test_client_protocol.py b/jmclient/test/test_client_protocol.py index 96ae0c3..d16f8df 100644 --- a/jmclient/test/test_client_protocol.py +++ b/jmclient/test/test_client_protocol.py @@ -118,7 +118,7 @@ class DummyMaker(Maker): 'maxsize': 100000000, 'minsize': 75000, 'oid': 0, - 'ordertype': 'swreloffer', + 'ordertype': 'sw0reloffer', 'txfee': 0 }] diff --git a/jmclient/test/test_maker.py b/jmclient/test/test_maker.py index 28750ec..031779a 100644 --- a/jmclient/test/test_maker.py +++ b/jmclient/test/test_maker.py @@ -77,7 +77,7 @@ def get_address_generator(script_pre, script_post, p2sh=False): def create_tx_and_offerlist(cj_addr, cj_change_addr, other_output_addrs, - offertype='swreloffer'): + offertype='sw0reloffer'): assert len(other_output_addrs) % 2 == 0, "bug in test" cj_value = 100000000 diff --git a/jmclient/test/test_snicker.py b/jmclient/test/test_snicker.py index 7eeca55..cafe11e 100644 --- a/jmclient/test/test_snicker.py +++ b/jmclient/test/test_snicker.py @@ -9,7 +9,7 @@ from commontest import make_wallets, dummy_accept_callback, dummy_info_callback import jmbitcoin as btc from jmbase import get_log, bintohex from jmclient import (load_test_config, estimate_tx_fee, SNICKERReceiver, - direct_send) + direct_send, SegwitLegacyWallet) TEST_PROPOSALS_FILE = "test_proposals.txt" log = get_log() @@ -31,7 +31,10 @@ def test_snicker_e2e(setup_snicker, nw, wallet_structures, LoopingCall) and processes them. 5. Check for valid final transaction with broadcast. """ - wallets = make_wallets(nw, wallet_structures, mean_amt, sdev_amt) + + # TODO: Make this test work with native segwit wallets + wallets = make_wallets(nw, wallet_structures, mean_amt, sdev_amt, + wallet_cls=SegwitLegacyWallet) for w in wallets.values(): w['wallet'].sync_wallet(fast=True) print(wallets) diff --git a/jmclient/test/test_support.py b/jmclient/test/test_support.py index cbd93b6..01322f3 100644 --- a/jmclient/test/test_support.py +++ b/jmclient/test/test_support.py @@ -55,6 +55,8 @@ def test_random_funcs(): def test_calc_cjfee(): assert calc_cj_fee("swabsoffer", 3000, 200000000) == 3000 assert calc_cj_fee("swreloffer", "0.01", 100000000) == 1000000 + assert calc_cj_fee("sw0absoffer", 3000, 200000000) == 3000 + assert calc_cj_fee("sw0reloffer", "0.01", 100000000) == 1000000 with pytest.raises(RuntimeError) as e_info: calc_cj_fee("dummyoffer", 2, 3) @@ -100,7 +102,7 @@ def test_choose_orders(): #(b) add an unrecognized ordertype (does not raise, ignores) #(c) put an order with wrong minsize orderbook.append({u'counterparty': u'fake', - u'ordertype': u'swabsoffer', u'oid': 0, + u'ordertype': u'sw0absoffer', u'oid': 0, u'minsize': 7500000, u'txfee': 1000, u'maxsize': 599972700, u'cjfee': 9000}) result, cjamount, total_fee = choose_sweep_orders(orderbook, 50000000, @@ -132,4 +134,4 @@ def test_choose_orders(): None) assert result == None assert cjamount == 0 - assert total_fee == 0 \ No newline at end of file + assert total_fee == 0 diff --git a/jmclient/test/test_tx_creation.py b/jmclient/test/test_tx_creation.py index de13f18..af5bcfe 100644 --- a/jmclient/test/test_tx_creation.py +++ b/jmclient/test/test_tx_creation.py @@ -68,7 +68,7 @@ def test_verify_tx_input(setup_tx_creation): scriptSig = tx.vin[0].scriptSig tx2 = bitcoin.mktx(ins, outs) res = bitcoin.verify_tx_input(tx2, 0, scriptSig, - bitcoin.pubkey_to_p2sh_p2wpkh_script(pub), + bitcoin.pubkey_to_p2wpkh_script(pub), amount = bitcoin.coins_to_satoshi(1), witness = bitcoin.CScriptWitness([sig, pub])) assert res diff --git a/jmclient/test/test_yieldgenerator.py b/jmclient/test/test_yieldgenerator.py index 1622baf..c3acc83 100644 --- a/jmclient/test/test_yieldgenerator.py +++ b/jmclient/test/test_yieldgenerator.py @@ -85,10 +85,10 @@ class CreateMyOrdersTests(unittest.TestCase): def test_rel_fee(self): jm_single().DUST_THRESHOLD = 10 yg = create_yg_basic([0, 2000000, 1000000], txfee=1000, cjfee_r=0.1, - ordertype='swreloffer', minsize=10) + ordertype='sw0reloffer', minsize=10) self.assertEqual(yg.create_my_orders(), [ {'oid': 0, - 'ordertype': 'swreloffer', + 'ordertype': 'sw0reloffer', 'minsize': 15000, 'maxsize': 1999000, 'txfee': 1000, diff --git a/jmdaemon/jmdaemon/protocol.py b/jmdaemon/jmdaemon/protocol.py index 9920e2c..7d531aa 100644 --- a/jmdaemon/jmdaemon/protocol.py +++ b/jmdaemon/jmdaemon/protocol.py @@ -12,6 +12,10 @@ offertypes = {"reloffer": [(int, "oid"), (int, "minsize"), (int, "maxsize"), "swreloffer": [(int, "oid"), (int, "minsize"), (int, "maxsize"), (int, "txfee"), (float, "cjfee")], "swabsoffer": [(int, "oid"), (int, "minsize"), (int, "maxsize"), + (int, "txfee"), (int, "cjfee")], + "sw0reloffer": [(int, "oid"), (int, "minsize"), (int, "maxsize"), + (int, "txfee"), (float, "cjfee")], + "sw0absoffer": [(int, "oid"), (int, "minsize"), (int, "maxsize"), (int, "txfee"), (int, "cjfee")]} offername_list = list(offertypes.keys()) diff --git a/scripts/joinmarket-qt.py b/scripts/joinmarket-qt.py index a05a7a9..3e1269e 100755 --- a/scripts/joinmarket-qt.py +++ b/scripts/joinmarket-qt.py @@ -892,10 +892,10 @@ class SpendTab(QWidget): mbinfo.append("Counterparties chosen:") mbinfo.append('Name, Order id, Coinjoin fee (sat.)') for k, o in iteritems(offers): - if o['ordertype'] in ['swreloffer', 'reloffer']: + if o['ordertype'] in ['sw0reloffer', 'swreloffer', 'reloffer']: display_fee = int(self.taker.cjamount * float(o['cjfee'])) - int(o['txfee']) - elif o['ordertype'] in ['swabsoffer', 'absoffer']: + elif o['ordertype'] in ['sw0absoffer', 'swabsoffer', 'absoffer']: display_fee = int(o['cjfee']) - int(o['txfee']) else: log.debug("Unsupported order type: " + str(o['ordertype']) + diff --git a/scripts/obwatch/ob-watcher.py b/scripts/obwatch/ob-watcher.py index 6bb8b32..c24f0d3 100755 --- a/scripts/obwatch/ob-watcher.py +++ b/scripts/obwatch/ob-watcher.py @@ -70,15 +70,16 @@ def do_nothing(arg, order, btc_unit, rel_unit): def ordertype_display(ordertype, order, btc_unit, rel_unit): - ordertypes = {'swabsoffer': 'SW Absolute Fee', 'swreloffer': 'SW Relative Fee', + ordertypes = {'sw0absoffer': 'Native SW Absolute Fee', 'sw0reloffer': 'Native SW Relative Fee', + 'swabsoffer': 'SW Absolute Fee', 'swreloffer': 'SW Relative Fee', 'absoffer': 'Absolute Fee', 'reloffer': 'Relative Fee'} return ordertypes[ordertype] def cjfee_display(cjfee, order, btc_unit, rel_unit): - if order['ordertype'] in ['absoffer', 'swabsoffer']: + if order['ordertype'] in ['absoffer', 'swabsoffer', 'sw0absoffer']: return satoshi_to_unit(cjfee, order, btc_unit, rel_unit) - elif order['ordertype'] in ['reloffer', 'swreloffer']: + elif order['ordertype'] in ['reloffer', 'swreloffer', 'sw0reloffer']: return str(Decimal(cjfee) * rel_unit_to_factor[rel_unit]) + rel_unit diff --git a/scripts/sendpayment.py b/scripts/sendpayment.py index 8901ed3..8d8912d 100755 --- a/scripts/sendpayment.py +++ b/scripts/sendpayment.py @@ -147,13 +147,6 @@ def main(): if int(options.txfee) > 0: jm_single().config.set("POLICY", "tx_fees", str(options.txfee)) - # Dynamically estimate a realistic fee. - # At this point we do not know even the number of our own inputs, so - # we guess conservatively with 2 inputs and 2 outputs each. - fee_per_cp_guess = estimate_tx_fee(2, 2, txtype="p2sh-p2wpkh") - log.debug("Estimated miner/tx fee for each cj participant: " + str( - fee_per_cp_guess)) - maxcjfee = (1, float('inf')) if not options.pickorders and options.makercount != 0: maxcjfee = get_max_cj_fee_values(jm_single().config, options) @@ -179,6 +172,12 @@ def main(): # the sync call here will now be a no-op: wallet_service.startService() + # Dynamically estimate a realistic fee. + # At this point we do not know even the number of our own inputs, so + # we guess conservatively with 2 inputs and 2 outputs each. + fee_per_cp_guess = estimate_tx_fee(2, 2, txtype=wallet_service.get_txtype()) + log.debug("Estimated miner/tx fee for each cj participant: " + str( + fee_per_cp_guess)) # From the estimated tx fees, check if the expected amount is a # significant value compared the the cj amount; currently enabled diff --git a/scripts/tumbler.py b/scripts/tumbler.py index 5a918bb..c6239e4 100755 --- a/scripts/tumbler.py +++ b/scripts/tumbler.py @@ -125,7 +125,7 @@ def main(): # Dynamically estimate an expected tx fee for the whole tumbling run. # This is very rough: we guess with 2 inputs and 2 outputs each. - fee_per_cp_guess = estimate_tx_fee(2, 2, txtype="p2sh-p2wpkh") + fee_per_cp_guess = estimate_tx_fee(2, 2, txtype=wallet_service.get_txtype()) log.debug("Estimated miner/tx fee for each cj participant: " + str( fee_per_cp_guess)) diff --git a/scripts/yg-privacyenhanced.py b/scripts/yg-privacyenhanced.py index 54a623c..7a94758 100755 --- a/scripts/yg-privacyenhanced.py +++ b/scripts/yg-privacyenhanced.py @@ -15,7 +15,7 @@ from jmclient import YieldGeneratorBasic, ygmain, jm_single """THESE SETTINGS CAN SIMPLY BE EDITED BY HAND IN THIS FILE: """ -ordertype = 'swreloffer' # [string, 'swreloffer' or 'swabsoffer'] / which fee type to actually use +ordertype = 'swreloffer' # [string, 'swreloffer', 'swabsoffer', 'sw0reloffer', 'sw0absoffer'] / which fee type to actually use cjfee_a = 500 # [satoshis, any integer] / absolute offer fee you wish to receive for coinjoins (cj) cjfee_r = '0.00002' # [percent, any str between 0-1] / relative offer fee you wish to receive based on a cj's amount cjfee_factor = 0.1 # [percent, 0-1] / variance around the average fee. Ex: 200 fee, 0.2 var = fee is btw 160-240 @@ -39,9 +39,9 @@ class YieldGeneratorPrivacyEnhanced(YieldGeneratorBasic): # We publish ONLY the maximum amount and use minsize for lower bound; # leave it to oid_to_order to figure out the right depth to use. f = '0' - if ordertype == 'swreloffer': + if ordertype in ['swreloffer', 'sw0reloffer']: f = self.cjfee_r - elif ordertype == 'swabsoffer': + elif ordertype in ['swabsoffer', 'sw0absoffer']: f = str(self.txfee + self.cjfee_a) mix_balance = dict([(m, b) for m, b in iteritems(mix_balance) if b > self.minsize]) @@ -80,7 +80,7 @@ class YieldGeneratorPrivacyEnhanced(YieldGeneratorBasic): assert order['minsize'] >= 0 assert order['maxsize'] > 0 assert order['minsize'] <= order['maxsize'] - if order['ordertype'] == 'swreloffer': + if order['ordertype'] in ['swreloffer', 'sw0reloffer']: while order['txfee'] >= (float(order['cjfee']) * order['minsize']): order['txfee'] = int(order['txfee'] / 2) jlog.info('Warning: too high txfee to be profitable, halfing it to: ' + str(order['txfee'])) diff --git a/scripts/yield-generator-basic.py b/scripts/yield-generator-basic.py index 406b0d0..23ff3c1 100755 --- a/scripts/yield-generator-basic.py +++ b/scripts/yield-generator-basic.py @@ -8,7 +8,7 @@ from jmclient import YieldGeneratorBasic, ygmain txfee = 100 cjfee_a = 500 cjfee_r = '0.00002' -ordertype = 'swreloffer' #'swreloffer' or 'swabsoffer' +ordertype = 'sw0reloffer' # [string, 'swreloffer', 'sw0reloffer', 'swabsoffer', 'sw0absoffer'] nickserv_password = '' max_minsize = 100000 gaplimit = 6 diff --git a/test/common.py b/test/common.py index 971eb79..34f3ea1 100644 --- a/test/common.py +++ b/test/common.py @@ -11,7 +11,7 @@ data_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) sys.path.insert(0, os.path.join(data_dir)) from jmbase import get_log -from jmclient import open_test_wallet_maybe, BIP32Wallet, SegwitLegacyWallet, \ +from jmclient import open_test_wallet_maybe, BIP32Wallet, SegwitWallet, \ estimate_tx_fee, jm_single, WalletService import jmbitcoin as btc from jmbase import chunks @@ -64,7 +64,7 @@ def make_wallets(n, fixed_seeds=None, test_wallet=False, passwords=None, - walletclass=SegwitLegacyWallet, + walletclass=SegwitWallet, mixdepths=5): '''n: number of wallets to be created wallet_structure: array of n arrays , each subarray diff --git a/test/ygrunner.py b/test/ygrunner.py index 544a7a5..08210d9 100644 --- a/test/ygrunner.py +++ b/test/ygrunner.py @@ -120,7 +120,7 @@ def test_start_ygs(setup_ygrunner, num_ygs, wallet_structures, mean_amt, txfee = 1000 cjfee_a = 4200 cjfee_r = '0.001' - ordertype = 'swreloffer' + ordertype = 'sw0reloffer' minsize = 100000 ygclass = YieldGeneratorBasic if malicious: