How to determine if transaction is going to propagate?



So I am creating a transaction using TransactionBuilder like this:

var builder = new TransactionBuilder();
Transaction tx = builder
  .Send(recipientAddress, Money.Coins(amount))
  .BuildTransaction(sign: true);

Boolean verified = builder.Verify(tx);

And then I propagate it to the network like so:

using (var node = Node.ConnectToLocal(network)) 

    node.SendMessage(new InvPayload(InventoryType.MSG_TX, tx.GetHash()));

    node.SendMessage(new TxPayload(tx));

I have two questions:

  1. What does the builder.Verify(tx) even tell us? It returns a boolean, but sometimes I can propagate transactions that returned false. What does verify mean/do?

  2. Since Verify() doesn't really tell us if a transaction will successfully propagate, how do I determine when a transaction made using TransactionBuilder will or won't propagate to the network?


Posted 2017-02-11T01:56:47.530

Reputation: 183



Verify() verifies if the transaction is properly signed.

Since Verify() doesn't really tell us if a transaction will successfully propagate

It is either untrue or you found a bug.

node.SendMessage(new TxPayload(tx)); should be perfect. However Stratis is currently building a Bitcoin .NET fullnode, with the lead of Nicolas Dorier, NBitcoin's creator, so you should be sure the method they are using is up to date. In their tests, they are doing it a little differently:

node.SendMessageAsync(new InvPayload(transaction));
node.SendMessageAsync(new TxPayload(transaction));

I cannot explain why two SendMessageAsync and PingPong is there. You might want to figure out.

To make sure you might want to ask some other nodes if they have the transaction in their mempool you are connected to, to check the propagation. Like this:

bool broadcasted = false;
foreach(var txid in node.GetMempool())
        broadcasted = true;

Alternatively you can ask your node only. I strongly suspect the transaction would not get into your (Bitcoin Core) mempool if there is something wrong, but you should not rely on that. Theory not always mimics practice.

Privacy concerns: if you broadcast a transaction without Tor, interested parties can note it and come to conclusions.


Posted 2017-02-11T01:56:47.530

Reputation: 642

I was able to propagate a transaction to the testnet that didn't properly verify. If you would like to view it, here is the hash: e98118de943d124e21d52dd6a05528eff18f199e3eea6ae149d97ce3f0158ae5 – rosstripi – 2017-02-13T16:27:44.630

I can just speculate at this point, but maybe the node you "propagated to" does not check the validity of the transaction, but when it wanted to propagate it further, other nodes rejected it? – nopara73 – 2017-02-13T22:00:46.150

It should accept the transaction: I'm sending it to myself, so mine is the only key needed.

Also, I'm seeing that the above transaction did go through: transaction here

– rosstripi – 2017-02-13T22:02:15.733

It did not get propagated to the network, block explorers doesn't find it. Sending to yourself happens to the same way as sending to everyone else. You have to propagate the transaction through the whole network and it has to be stored by every full-node. I'm not sure what's going on at you locally. – nopara73 – 2017-02-13T22:06:11.450

@rossbot Apparently when you copypaste the transactionid from your first comment some magic changes it. From the f015 it inserts 2 ?? when I paste it. (Win7, not sure that matters). This is why I did not see the transactions on the above links. – nopara73 – 2017-02-13T22:50:24.007

To sum up, yes, you propagated a transaction that NBitcoin couldn't verify. That's strange. – nopara73 – 2017-02-13T22:51:25.430