Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversion of withdraw and txprepare to new UTXO primitives (as plugins!) #3867

Merged

Commits on Aug 28, 2020

  1. wallet: fix reference to potentially-undefined variable.

    If all is set, diff may not be:
    
        ==1230518== Use of uninitialised value of size 8
        ==1230518==    at 0x4C5781B: _itoa_word (_itoa.c:179)
        ==1230518==    by 0x4C736F4: __vfprintf_internal (vfprintf-internal.c:1687)
        ==1230518==    by 0x4C88119: __vsnprintf_internal (vsnprintf.c:114)
        ==1230518==    by 0x1D44B6: do_vfmt (str.c:66)
        ==1230518==    by 0x1D45A0: tal_vfmt_ (str.c:92)
        ==1230518==    by 0x1D4401: tal_fmt_ (str.c:44)
        ==1230518==    by 0x15D30F: fmt_amount_sat (amount.c:60)
        ==1230518==    by 0x15D338: fmt_amount_sat_ (amount.c:62)
        ==1230518==    by 0x178C45: type_to_string_ (type_to_string.c:35)
        ==1230518==    by 0x1B8F75: json_fundpsbt (reservation.c:394)
        ==1230518==    by 0x12D0EC: command_exec (jsonrpc.c:602)
        ==1230518==    by 0x12D598: rpc_command_hook_callback (jsonrpc.c:712)
    
    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Aug 28, 2020
    Configuration menu
    Copy the full SHA
    69d87f8 View commit details
    Browse the repository at this point in the history
  2. txprepare: a plugin to replace txprepare (not yet active).

    This uses `fundpsbt` and similar to simulate the txprepare command.
    It has one difference (when complete), in that it those reservations
    are now timed and don't get reset on restart.
    
    It also doesn't have the restriction that `all` can only be used with
    no other output, as I didn't realize that when I implemented it!
    
    Note that change is now inserted in a random position, not sorted
    into BIP69 order.
    
    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Aug 28, 2020
    Configuration menu
    Copy the full SHA
    3476ba1 View commit details
    Browse the repository at this point in the history
  3. plugins/txprepare: use utxopsbt to handle utxos arg.

    Very similar to fundpsbt, but takes 'utxos' instead of 'minconf'.
    
    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Aug 28, 2020
    Configuration menu
    Copy the full SHA
    143abd6 View commit details
    Browse the repository at this point in the history
  4. reservation: return FUNDING_STILL_SYNCING_BITCOIN if we might be miss…

    …ing funds.
    
    This is useful, and also makes us pass the testsuite.
    
    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Aug 28, 2020
    Configuration menu
    Copy the full SHA
    f52c311 View commit details
    Browse the repository at this point in the history
  5. txprepare: add txdiscard functionality.

    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Aug 28, 2020
    Configuration menu
    Copy the full SHA
    cb02964 View commit details
    Browse the repository at this point in the history
  6. txprepare: add txsend functionality.

    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Aug 28, 2020
    Configuration menu
    Copy the full SHA
    2f99fbc View commit details
    Browse the repository at this point in the history
  7. pytest: remove test_txprepare_restart

    This tested that we unreserved everything on restart, which we no
    longer do.
    
    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Aug 28, 2020
    Configuration menu
    Copy the full SHA
    6955217 View commit details
    Browse the repository at this point in the history
  8. txprepare: remove old code, switch to plugin.

    Some minor phrasing differences cause test changes.
    
    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    Changelog-Changed: txprepare reservations stay across restarts: use fundpsbt/reservepsbt/unreservepsbt
    Changelog-Removed: txprepare `destination` `satoshi` argument form removed (deprecated v0.7.3)
    rustyrussell committed Aug 28, 2020
    Configuration menu
    Copy the full SHA
    91b15ab View commit details
    Browse the repository at this point in the history
  9. walletrpc: remove now-unused txprepare parsing code.

    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Aug 28, 2020
    Configuration menu
    Copy the full SHA
    64f4502 View commit details
    Browse the repository at this point in the history
  10. wallet: wean fundpsbt off tx_spending_utxos.

    We only need a subset of its functionality, so reproduce that here.
    
    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Aug 28, 2020
    Configuration menu
    Copy the full SHA
    c4c0270 View commit details
    Browse the repository at this point in the history
  11. sendpsbt: just reserve (maybe bump) inputs on send, don't mark spent.

    Marking spent means if the transaction doesn't confirm for some
    reason, the user will need to force a rescan to find the funds.  Now
    we have timed reservations, reserving for (an additional) 12 hours
    should be sufficient.
    
    We also take this opportunity (now we have our own callback path)
    to record the tx in the wallet only on success.
    
    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Aug 28, 2020
    Configuration menu
    Copy the full SHA
    de79281 View commit details
    Browse the repository at this point in the history
  12. plugins/txprepare: move functions higher.

    Simple moveonly change for next patch.
    
    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Aug 28, 2020
    Configuration menu
    Copy the full SHA
    00f455f View commit details
    Browse the repository at this point in the history
  13. plugins/txprepare: create simple variant for "withdraw".

    This is a little lazy, but simpler than extracting the common parts
    or making withdraw a plugin which calls txprepare (which should be
    deprecated soon in favor of fundpsbt etc).
    
    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Aug 28, 2020
    Configuration menu
    Copy the full SHA
    b613d58 View commit details
    Browse the repository at this point in the history
  14. pytest: allow variable-order coin_moves, and give more information on…

    … failure.
    
    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Aug 28, 2020
    Configuration menu
    Copy the full SHA
    e0123d1 View commit details
    Browse the repository at this point in the history
  15. pytest: fix assumptions in test_withdraw_misc

    First, simplify: amount is set to 1000000, but then we deposit 1000000 + 0.01btc
    (i.e. 2000000), and we always use 2 * amount.  Just use a single constant to
    make it clear.
    
    Secondly, we assume that the wallet considers outputs spent as soon as
    we created the tx: this will not be true once withdraw uses sendpsbt.
    So, we generate blocks, but now sometimes withdraw will pick up change
    txs, so we need to reserve them to avoid that messing our coinmovements.
    
    Finally, we assumed the withdrawl order was BIP69, which becomes
    variable.
    
    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Aug 28, 2020
    Configuration menu
    Copy the full SHA
    7f7d7d9 View commit details
    Browse the repository at this point in the history
  16. pytest: remove duplicate tests.

    These tests appear in both test_misc.py and test_wallet.py.
    
    I checked, and they're the only duplcates; they were moved in
    0543149 then re-added (merge error?)
    in 67fc8ff.
    
    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Aug 28, 2020
    Configuration menu
    Copy the full SHA
    d3bfe91 View commit details
    Browse the repository at this point in the history
  17. wallet: switch over to withdraw in module, remove lots of unused code.

    This removes the reservation cleanup at startup, too, now they're all
    using 'reserved_til'.
    
    This changes test_withdraw, since it asserted that outputs were marked
    spent as soon as we broadcast a transaction: now they're reserved until
    it's mined.  Similarly, test_addfunds_from_block assumed we'd see funds
    as soon as we broadcast the tx.
    
    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    Changelog-Changed: JSON-RPC: `withdraw` now randomizes input and output order, not BIP69.
    rustyrussell committed Aug 28, 2020
    Configuration menu
    Copy the full SHA
    ea08087 View commit details
    Browse the repository at this point in the history
  18. common: remove funding_tx.

    It's now only needed by devtools/mkfunding, so include a reduced one
    there, and this also means we remove tx_spending_utxos().
    
    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Aug 28, 2020
    Configuration menu
    Copy the full SHA
    dd0a4cc View commit details
    Browse the repository at this point in the history
  19. utxo: make reserved_til a u32 not a ptr, now it's compsulory.

    It's 0 for old dbs, which is the same as "available".
    
    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Aug 28, 2020
    Configuration menu
    Copy the full SHA
    321ea8a View commit details
    Browse the repository at this point in the history
  20. utxo: expose is_reserved, make enum constants upper case.

    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Aug 28, 2020
    Configuration menu
    Copy the full SHA
    532ce8c View commit details
    Browse the repository at this point in the history
  21. wellet: use create_psbt and psbt_append_input instead of constructing…

    … via bitcoin_tx.
    
    Suggested-by: @niftynei
    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Aug 28, 2020
    Configuration menu
    Copy the full SHA
    75bbaa1 View commit details
    Browse the repository at this point in the history