From 20460432d543338568f96f08f8a7e53b18307181 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Wed, 12 Sep 2018 20:49:14 -0700 Subject: [PATCH 1/6] build: update dep to latest version of btcwallet --- Gopkg.lock | 5 ++--- Gopkg.toml | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index 3c7f5874e..335188126 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -106,7 +106,7 @@ revision = "ab6388e0c60ae4834a1f57511e20c17b5f78be4b" [[projects]] - digest = "1:012039cbb6694894aa9e9890645e6ade8a5aff5a02c279714779eff3eae53bc2" + digest = "1:e6575f3ee773e72a38319dbd8f4cb7f1b574eccfed7cb103c3a25c254d5c250f" name = "github.com/btcsuite/btcwallet" packages = [ "chain", @@ -126,7 +126,7 @@ "wtxmgr", ] pruneopts = "UT" - revision = "f4ae41ce5f5834eb67ab64cdeed74c74fc95638c" + revision = "421298df22601db0fe4adb8f4be71b7014324ba9" [[projects]] branch = "master" @@ -417,7 +417,6 @@ version = "v0.3.0" [[projects]] - branch = "master" digest = "1:c9e7a4b4d47c0ed205d257648b0e5b0440880cb728506e318f8ac7cd36270bc4" name = "golang.org/x/time" packages = ["rate"] diff --git a/Gopkg.toml b/Gopkg.toml index f07ad1f64..44a34ba95 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -72,7 +72,7 @@ [[constraint]] name = "github.com/btcsuite/btcwallet" - revision = "f4ae41ce5f5834eb67ab64cdeed74c74fc95638c" + revision = "421298df22601db0fe4adb8f4be71b7014324ba9" [[constraint]] name = "github.com/tv42/zbase32" From 24f9504e274e5de7d94402c76369ad5afeb4d6c5 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Wed, 12 Sep 2018 20:51:27 -0700 Subject: [PATCH 2/6] lnwallet: add test to ensure that all backends show unconf txns in ListTransactionDetails In this commit, we add a new test to the set of lnwallet integration tests. In this new test, we aim to ensure that all backends are able to display unconfirmed transactions in ListChainTransactions. As of this commit, this test fails as no backends will return unconfirmed transactions properly. --- lnwallet/interface_test.go | 39 +++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/lnwallet/interface_test.go b/lnwallet/interface_test.go index eb2be23e3..cd1125831 100644 --- a/lnwallet/interface_test.go +++ b/lnwallet/interface_test.go @@ -1055,7 +1055,9 @@ func testListTransactionDetails(miner *rpctest.Harness, delete(txids, txDetail.Hash) } if len(txids) != 0 { - t.Fatalf("all transactions not found in details!") + t.Fatalf("all transactions not found in details: left=%v, "+ + "returned_set=%v", spew.Sdump(txids), + spew.Sdump(txDetails)) } // Next create a transaction paying to an output which isn't under the @@ -1075,6 +1077,41 @@ func testListTransactionDetails(miner *rpctest.Harness, if err != nil { t.Fatalf("tx not relayed to miner: %v", err) } + + // Before we mine the next block, we'll ensure that the above + // transaction shows up in the set of unconfirmed transactions returned + // by ListTransactionDetails. + err = waitForWalletSync(miner, alice) + if err != nil { + t.Fatalf("Couldn't sync Alice's wallet: %v", err) + } + + // We should be able to find the transaction above in the set of + // returned transactions, and it should have a confirmation of -1, + // indicating that it's not yet mined. + txDetails, err = alice.ListTransactionDetails() + if err != nil { + t.Fatalf("unable to fetch tx details: %v", err) + } + var mempoolTxFound bool + for _, txDetail := range txDetails { + if !bytes.Equal(txDetail.Hash[:], burnTXID[:]) { + continue + } + + // Now that we've found the transaction, ensure that it has a + // negative number of confirmations to indicate that it's + // unconfirmed. + mempoolTxFound = true + if txDetail.NumConfirmations != 0 { + t.Fatalf("num confs incorrect, got %v expected %v", + txDetail.NumConfirmations, 0) + } + } + if !mempoolTxFound { + t.Fatalf("unable to find mempool tx in tx details!") + } + burnBlock, err := miner.Node.Generate(1) if err != nil { t.Fatalf("unable to mine block: %v", err) From 2509ecd8d8c69785c0832001bc4307684005fbfe Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Wed, 12 Sep 2018 20:53:52 -0700 Subject: [PATCH 3/6] lnwallet: fix ListTransactionDetails to ensure unconfirmed transactions are installed In this commit, we fix a bug in the arguments to GetTransactions for the btcwallet implementation of the WalletController interface. Before this commit, we wouldn't properly return unconfirmed transactions. The issue was that we didn't specify the special mempool height of "-1", as the ending height. The mempool height is actually internally converted to the highest possible height that can fit into a int32. In this commit, we set the start to zero, and end to -1 (actually 2^32-1) to properly scan for unconfirmed transactions. Fixes #1422. --- lnwallet/btcwallet/btcwallet.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lnwallet/btcwallet/btcwallet.go b/lnwallet/btcwallet/btcwallet.go index 92bcbfa25..3fb7665c6 100644 --- a/lnwallet/btcwallet/btcwallet.go +++ b/lnwallet/btcwallet/btcwallet.go @@ -559,9 +559,11 @@ func (b *BtcWallet) ListTransactionDetails() ([]*lnwallet.TransactionDetail, err bestBlock := b.wallet.Manager.SyncedTo() currentHeight := bestBlock.Height - // TODO(roasbeef): can replace with start "wallet birthday" + // We'll attempt to find all unconfirmed transactions (height of -1), + // as well as all transactions that are known to have confirmed at this + // height. start := base.NewBlockIdentifierFromHeight(0) - stop := base.NewBlockIdentifierFromHeight(bestBlock.Height) + stop := base.NewBlockIdentifierFromHeight(-1) txns, err := b.wallet.GetTransactions(start, stop, nil) if err != nil { return nil, err From 27abad92f608d0d851974cd9a48d1ca834f9625d Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Wed, 12 Sep 2018 20:55:51 -0700 Subject: [PATCH 4/6] lnwallet: update for new API change in NewBitcoindClient --- lnwallet/interface_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lnwallet/interface_test.go b/lnwallet/interface_test.go index cd1125831..b19e74faa 100644 --- a/lnwallet/interface_test.go +++ b/lnwallet/interface_test.go @@ -2315,8 +2315,8 @@ func runTests(t *testing.T, walletDriver *lnwallet.WalletDriver, // Create a btcwallet bitcoind client for both Alice and // Bob. - aliceClient = chainConn.NewBitcoindClient(time.Unix(0, 0)) - bobClient = chainConn.NewBitcoindClient(time.Unix(0, 0)) + aliceClient = chainConn.NewBitcoindClient() + bobClient = chainConn.NewBitcoindClient() default: t.Fatalf("unknown chain driver: %v", backEnd) } From 64681214f42d9c89f765256a6fb22d9669b23ae1 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Wed, 12 Sep 2018 20:59:20 -0700 Subject: [PATCH 5/6] lnwallet: add test to execrise unconfirmed transcations notified by SubscribeTransactions In this commit, we add a new test to ensure that all backends will properly send out notifications when an unconfirmed transcation that we send is inserted into the tx store. Before we updated the btcwallet build commit in dep, this would fail for neutrino but now passes. --- lnwallet/interface_test.go | 39 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/lnwallet/interface_test.go b/lnwallet/interface_test.go index b19e74faa..e69fba9c9 100644 --- a/lnwallet/interface_test.go +++ b/lnwallet/interface_test.go @@ -1270,6 +1270,45 @@ func testTransactionSubscriptions(miner *rpctest.Harness, t.Fatalf("transactions not received after 5 seconds") case <-confirmedNtfns: // Fall through on success } + + // We'll also ensure that the client is able to send our new + // notifications when we _create_ transactions ourselves that spend our + // own outputs. + b := txscript.NewScriptBuilder() + b.AddOp(txscript.OP_0) + outputScript, err := b.Script() + if err != nil { + t.Fatalf("unable to make output script: %v", err) + } + burnOutput := wire.NewTxOut(outputAmt, outputScript) + txid, err := alice.SendOutputs([]*wire.TxOut{burnOutput}, 2500) + if err != nil { + t.Fatalf("unable to create burn tx: %v", err) + } + err = waitForMempoolTx(miner, txid) + if err != nil { + t.Fatalf("tx not relayed to miner: %v", err) + } + + // Before we mine the next block, we'll ensure that the above + // transaction shows up in the set of unconfirmed transactions returned + // by ListTransactionDetails. + err = waitForWalletSync(miner, alice) + if err != nil { + t.Fatalf("Couldn't sync Alice's wallet: %v", err) + } + + // As we just sent the transaction and it was landed in the mempool, we + // should get a notification for a new unconfirmed transactions + select { + case <-time.After(time.Second * 10): + t.Fatalf("transactions not received after 10 seconds") + case unConfTx := <-txClient.UnconfirmedTransactions(): + if unConfTx.Hash != *txid { + t.Fatalf("wrong txn notified: expected %v got %v", + txid, unConfTx.Hash) + } + } } // testPublishTransaction checks that PublishTransaction returns the From 2fa64dd6ff25cf6e791b2208011224f0b26d5585 Mon Sep 17 00:00:00 2001 From: Wilmer Paulino Date: Wed, 12 Sep 2018 15:57:05 -0700 Subject: [PATCH 6/6] multi: update to new BitcoindClient API --- chainntnfs/bitcoindnotify/bitcoind.go | 3 +-- chainregistry.go | 2 +- routing/chainview/bitcoind.go | 3 +-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/chainntnfs/bitcoindnotify/bitcoind.go b/chainntnfs/bitcoindnotify/bitcoind.go index 82abfd984..9ce2c5288 100644 --- a/chainntnfs/bitcoindnotify/bitcoind.go +++ b/chainntnfs/bitcoindnotify/bitcoind.go @@ -6,7 +6,6 @@ import ( "strings" "sync" "sync/atomic" - "time" "github.com/btcsuite/btcd/btcjson" "github.com/btcsuite/btcd/chaincfg/chainhash" @@ -115,7 +114,7 @@ func New(chainConn *chain.BitcoindConn, spendHintCache chainntnfs.SpendHintCache quit: make(chan struct{}), } - notifier.chainConn = chainConn.NewBitcoindClient(time.Unix(0, 0)) + notifier.chainConn = chainConn.NewBitcoindClient() return notifier } diff --git a/chainregistry.go b/chainregistry.go index fcebfbc84..c4d915d6c 100644 --- a/chainregistry.go +++ b/chainregistry.go @@ -335,7 +335,7 @@ func newChainControlFromConfig(cfg *config, chanDB *channeldb.DB, bitcoindConn, hintCache, hintCache, ) cc.chainView = chainview.NewBitcoindFilteredChainView(bitcoindConn) - walletConfig.ChainSource = bitcoindConn.NewBitcoindClient(birthday) + walletConfig.ChainSource = bitcoindConn.NewBitcoindClient() // If we're not in regtest mode, then we'll attempt to use a // proper fee estimator for testnet. diff --git a/routing/chainview/bitcoind.go b/routing/chainview/bitcoind.go index bcdc3bcaf..5e03e63f4 100644 --- a/routing/chainview/bitcoind.go +++ b/routing/chainview/bitcoind.go @@ -6,7 +6,6 @@ import ( "fmt" "sync" "sync/atomic" - "time" "github.com/btcsuite/btcd/btcjson" "github.com/btcsuite/btcd/chaincfg/chainhash" @@ -71,7 +70,7 @@ func NewBitcoindFilteredChainView( quit: make(chan struct{}), } - chainView.chainClient = chainConn.NewBitcoindClient(time.Unix(0, 0)) + chainView.chainClient = chainConn.NewBitcoindClient() chainView.blockQueue = newBlockEventQueue() return chainView