wallet: extend PublishTransaction to be a general reliable broadcaster

In this commit, we extend the PublishTransction method to be a more
general semi reliable transaction broadcast mechanism. We do this by
removing the special casing for neutrino. With this change, we’ll
_always_ write any transactions to be broadcast to disk. A side effect
of this, is that if the transaction doesn’t *directly* involve any
outputs we control, then it’ll linger around until a restart, when we
try to rebroadcast, and observe that it has bene rejected.
This commit is contained in:
Olaoluwa Osuntokun 2018-02-21 16:13:31 -08:00
parent 54b31c1a35
commit ab4ccacbb9

View file

@ -2540,26 +2540,20 @@ func (w *Wallet) PublishTransaction(tx *wire.MsgTx) error {
return err return err
} }
switch server.(type) { // As we aim for this to be general reliable transaction broadcast API,
// If our chain backend is neutrino, then we'll add this as an // we'll write this tx to disk as an unconfirmed transaction. This way,
// unconfirmed transaction into the transaction store. Otherwise, we // upon restarts, we'll always rebroadcast it, and also add it to our
// won't eve be notified of it's acceptance, meaning we won't attempt // set of records.
// to re-broadcast. rec, err := wtxmgr.NewTxRecordFromMsgTx(tx, time.Now())
case *chain.NeutrinoClient: if err != nil {
rec, err := wtxmgr.NewTxRecordFromMsgTx( return err
tx, time.Now(), }
) err = walletdb.Update(w.db, func(tx walletdb.ReadWriteTx) error {
if err != nil { txmgrNs := tx.ReadWriteBucket(wtxmgrNamespaceKey)
return err return w.TxStore.InsertTx(txmgrNs, rec, nil)
} })
err = walletdb.Update(w.db, func(tx walletdb.ReadWriteTx) error { if err != nil {
txmgrNs := tx.ReadWriteBucket(wtxmgrNamespaceKey) return err
return w.TxStore.InsertTx(txmgrNs, rec, nil)
})
if err != nil {
return err
}
} }
_, err = server.SendRawTransaction(tx, false) _, err = server.SendRawTransaction(tx, false)