chainntnfs/interface: stricter conf dispatch for txindex

This commit is contained in:
Conner Fromknecht 2019-06-27 19:11:25 -07:00
parent 50f7f7f1b7
commit d5da18827e
No known key found for this signature in database
GPG Key ID: E7D737B67FA592C7
2 changed files with 39 additions and 15 deletions

View File

@ -628,6 +628,28 @@ func ConfDetailsFromTxIndex(chainConn TxIndexConn, r ConfRequest,
r.TxID, err)
}
// Deserialize the hex-encoded transaction to include it in the
// confirmation details.
rawTx, err := hex.DecodeString(rawTxRes.Hex)
if err != nil {
return nil, TxNotFoundIndex,
fmt.Errorf("unable to deserialize tx %v: %v",
r.TxID, err)
}
var tx wire.MsgTx
if err := tx.Deserialize(bytes.NewReader(rawTx)); err != nil {
return nil, TxNotFoundIndex,
fmt.Errorf("unable to deserialize tx %v: %v",
r.TxID, err)
}
// Ensure the transaction matches our confirmation request in terms of
// txid and pkscript.
if !r.MatchesTx(&tx) {
return nil, TxNotFoundIndex,
fmt.Errorf("unable to locate tx %v", r.TxID)
}
// Make sure we actually retrieved a transaction that is included in a
// block. If not, the transaction must be unconfirmed (in the mempool),
// and we'll return TxFoundMempool together with a nil TxConfirmation.
@ -659,21 +681,6 @@ func ConfDetailsFromTxIndex(chainConn TxIndexConn, r ConfRequest,
continue
}
// Deserialize the hex-encoded transaction to include it in the
// confirmation details.
rawTx, err := hex.DecodeString(rawTxRes.Hex)
if err != nil {
return nil, TxNotFoundIndex,
fmt.Errorf("unable to deserialize tx %v: %v",
txHash, err)
}
var tx wire.MsgTx
if err := tx.Deserialize(bytes.NewReader(rawTx)); err != nil {
return nil, TxNotFoundIndex,
fmt.Errorf("unable to deserialize tx %v: %v",
txHash, err)
}
return &TxConfirmation{
Tx: &tx,
BlockHash: blockHash,

View File

@ -660,12 +660,29 @@ func testTxConfirmedBeforeNtfnRegistration(miner *rpctest.Harness,
t.Fatalf("unable to register ntfn: %v", err)
}
// We'll also register for a confirmation notification with the pkscript
// of a different transaction. This notification shouldn't fire since we
// match on both txid and pkscript.
var ntfn4 *chainntnfs.ConfirmationEvent
ntfn4, err = notifier.RegisterConfirmationsNtfn(
txid3, pkScript2, 1, uint32(currentHeight-1),
)
if err != nil {
t.Fatalf("unable to register ntfn: %v", err)
}
select {
case <-ntfn3.Confirmed:
case <-time.After(10 * time.Second):
t.Fatalf("confirmation notification never received")
}
select {
case <-ntfn4.Confirmed:
t.Fatalf("confirmation notification received")
case <-time.After(5 * time.Second):
}
time.Sleep(1 * time.Second)
select {