Skip to content

Commit

Permalink
Merge pull request btcsuite#775 from ennmichael/unconfirmed-txn-notif…
Browse files Browse the repository at this point in the history
…ication-label

Fixed a bug where unconfirmed txn notifications were missing a label
  • Loading branch information
Roasbeef authored and buck54321 committed Apr 21, 2024
1 parent 35b9664 commit 8b1ad3b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 138 deletions.
129 changes: 2 additions & 127 deletions waddrmgr/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -990,8 +990,8 @@ func testImportScript(tc *testContext) bool {
"3b033a2fd64fe14a9b955e5355f0c6ac",
),
expected: expectedAddr{
address: "ltc1pc57jdm7kcnufnc339fvy2caflj6lkfeqasdfghftl7dd77dfpresrcsury",
addressHash: hexToBytes("c53d26efd6c4f899e2312a584563a9fcb5fb2720ec1a945d2bff9adf79a908f3"),
address: "ltc1pu92qt24cl4spyp4rsj9sa3y4ma6a3fszgewcmway9f6f80vgnduqhmaa4e",
addressHash: hexToBytes("e15405aab8fd601206a3848b0ec495df75d8a602465d8dbba42a7493bd889b78"),
internal: false,
imported: true,
compressed: true,
Expand Down Expand Up @@ -3304,128 +3304,3 @@ func TestManagedAddressValidation(t *testing.T) {
}

}

// TestTaprootPubKeyDerivation tests that p2tr addresses can be derived from the
// scoped manager when using the BIP0086 key scope.
func TestTaprootPubKeyDerivation(t *testing.T) {
t.Parallel()

teardown, db := emptyDB(t)
defer teardown()

// From: https://github.com/bitcoin/bips/blob/master/bip-0086.mediawiki
rootKey, _ := hdkeychain.NewKeyFromString(
"xprv9s21ZrQH143K3GJpoapnV8SFfukcVBSfeCficPSGfubmSFDxo1kuHnLi" +
"sriDvSnRRuL2Qrg5ggqHKNVpxR86QEC8w35uxmGoggxtQTPvfUu",
)

// We'll start the test by creating a new root manager that will be
// used for the duration of the test.
var mgr *Manager
err := walletdb.Update(db, func(tx walletdb.ReadWriteTx) error {
ns, err := tx.CreateTopLevelBucket(waddrmgrNamespaceKey)
if err != nil {
return err
}
err = Create(
ns, rootKey, pubPassphrase, privPassphrase,
&chaincfg.MainNetParams, fastScrypt, time.Time{},
)
if err != nil {
return err
}
mgr, err = Open(ns, pubPassphrase, &chaincfg.MainNetParams)
if err != nil {
return err
}

return mgr.Unlock(ns, privPassphrase)
})
require.NoError(t, err, "create/open: unexpected error: %v", err)

defer mgr.Close()

// Now that we have the manager created, we'll fetch one of the default
// scopes for usage within this test.
scopedMgr, err := mgr.FetchScopedKeyManager(KeyScopeBIP0086)
require.NoError(
t, err, "unable to fetch scope %v: %v", KeyScopeBIP0086, err,
)

externalPath := DerivationPath{
InternalAccount: 0,
Account: hdkeychain.HardenedKeyStart,
Branch: 0,
Index: 0,
}
internalPath := DerivationPath{
InternalAccount: 0,
Account: hdkeychain.HardenedKeyStart,
Branch: 1,
Index: 0,
}

assertAddressDerivation(
t, db, func(ns walletdb.ReadWriteBucket) (ManagedAddress, error) {
return scopedMgr.DeriveFromKeyPath(ns, externalPath)
},
"bc1p5cyxnuxmeuwuvkwfem96lqzszd02n6xdcjrs20cac6yqjjwudpxqkedrcr",
)
assertAddressDerivation(
t, db, func(ns walletdb.ReadWriteBucket) (ManagedAddress, error) {
addrs, err := scopedMgr.NextExternalAddresses(ns, 0, 1)
if err != nil {
return nil, err
}
return addrs[0], nil
},
"bc1p5cyxnuxmeuwuvkwfem96lqzszd02n6xdcjrs20cac6yqjjwudpxqkedrcr",
)
assertAddressDerivation(
t, db, func(ns walletdb.ReadWriteBucket) (ManagedAddress, error) {
return scopedMgr.LastExternalAddress(ns, 0)
},
"bc1p5cyxnuxmeuwuvkwfem96lqzszd02n6xdcjrs20cac6yqjjwudpxqkedrcr",
)
assertAddressDerivation(
t, db, func(ns walletdb.ReadWriteBucket) (ManagedAddress, error) {
return scopedMgr.DeriveFromKeyPath(ns, internalPath)
},
"bc1p3qkhfews2uk44qtvauqyr2ttdsw7svhkl9nkm9s9c3x4ax5h60wqwruhk7",
)
assertAddressDerivation(
t, db, func(ns walletdb.ReadWriteBucket) (ManagedAddress, error) {
addrs, err := scopedMgr.NextInternalAddresses(ns, 0, 1)
if err != nil {
return nil, err
}
return addrs[0], nil
},
"bc1p3qkhfews2uk44qtvauqyr2ttdsw7svhkl9nkm9s9c3x4ax5h60wqwruhk7",
)
assertAddressDerivation(
t, db, func(ns walletdb.ReadWriteBucket) (ManagedAddress, error) {
return scopedMgr.LastInternalAddress(ns, 0)
},
"bc1p3qkhfews2uk44qtvauqyr2ttdsw7svhkl9nkm9s9c3x4ax5h60wqwruhk7",
)
}

// assertAddressDerivation makes sure the address derived in the given callback
// is the one that is expected.
func assertAddressDerivation(t *testing.T, db walletdb.DB,
fn func(walletdb.ReadWriteBucket) (ManagedAddress, error),
expectedAddr string) {

var address ManagedAddress
err := walletdb.Update(db, func(tx walletdb.ReadWriteTx) error {
ns := tx.ReadWriteBucket(waddrmgrNamespaceKey)

var err error
address, err = fn(ns)
return err
})
require.NoError(t, err, "unable to derive addr: %v", err)

require.Equal(t, expectedAddr, address.Address().String())
}
19 changes: 8 additions & 11 deletions wallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -3725,19 +3725,16 @@ func (w *Wallet) reliablyPublishTransaction(tx *wire.MsgTx,
}
}

if err := w.addRelevantTx(dbTx, txRec, nil); err != nil {
return err
}

// If the tx label is empty, we can return early.
if len(label) == 0 {
return nil
}

// If there is a label we should write, get the namespace key
// and record it in the tx store.
txmgrNs := dbTx.ReadWriteBucket(wtxmgrNamespaceKey)
return w.TxStore.PutTxLabel(txmgrNs, tx.TxHash(), label)
if len(label) != 0 {
txmgrNs := dbTx.ReadWriteBucket(wtxmgrNamespaceKey)
if err = w.TxStore.PutTxLabel(txmgrNs, tx.TxHash(), label); err != nil {
return err
}
}

return w.addRelevantTx(dbTx, txRec, nil)
})
if err != nil {
return nil, err
Expand Down

0 comments on commit 8b1ad3b

Please sign in to comment.