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:
parent
54b31c1a35
commit
ab4ccacbb9
1 changed files with 14 additions and 20 deletions
|
@ -2540,26 +2540,20 @@ func (w *Wallet) PublishTransaction(tx *wire.MsgTx) error {
|
|||
return err
|
||||
}
|
||||
|
||||
switch server.(type) {
|
||||
// If our chain backend is neutrino, then we'll add this as an
|
||||
// unconfirmed transaction into the transaction store. Otherwise, we
|
||||
// won't eve be notified of it's acceptance, meaning we won't attempt
|
||||
// to re-broadcast.
|
||||
case *chain.NeutrinoClient:
|
||||
rec, err := wtxmgr.NewTxRecordFromMsgTx(
|
||||
tx, time.Now(),
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = walletdb.Update(w.db, func(tx walletdb.ReadWriteTx) error {
|
||||
txmgrNs := tx.ReadWriteBucket(wtxmgrNamespaceKey)
|
||||
|
||||
return w.TxStore.InsertTx(txmgrNs, rec, nil)
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// As we aim for this to be general reliable transaction broadcast API,
|
||||
// we'll write this tx to disk as an unconfirmed transaction. This way,
|
||||
// upon restarts, we'll always rebroadcast it, and also add it to our
|
||||
// set of records.
|
||||
rec, err := wtxmgr.NewTxRecordFromMsgTx(tx, time.Now())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = walletdb.Update(w.db, func(tx walletdb.ReadWriteTx) error {
|
||||
txmgrNs := tx.ReadWriteBucket(wtxmgrNamespaceKey)
|
||||
return w.TxStore.InsertTx(txmgrNs, rec, nil)
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = server.SendRawTransaction(tx, false)
|
||||
|
|
Loading…
Reference in a new issue