3

So I am creating a transaction using TransactionBuilder like this:

var builder = new TransactionBuilder();
Transaction tx = builder
  .AddCoins(coins)
  .AddKeys(privateKeys)
  .Send(recipientAddress, Money.Coins(amount))
  .SetChange(changeAddress)
  .SendFees(Money.Coins(fee))
  .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.VersionHandshake(); 

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

    node.SendMessage(new TxPayload(tx));
    Thread.Sleep(500); 
}

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?

1 Answer 1

2

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.VersionHandshake();
node.SendMessageAsync(new InvPayload(transaction));
node.SendMessageAsync(new TxPayload(transaction));
node.PingPong();

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())
{
    if(txid.Equals(tx.GetHash()))
    {
        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.

7
  • 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
    Commented Feb 13, 2017 at 16:27
  • I cannot find it: testnet.smartbit.com.au/tx/… tbtc.blockr.io/tx/info/…‌​8ae5
    – nopara73
    Commented Feb 13, 2017 at 21:57
  • 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
    Commented Feb 13, 2017 at 22:00
  • 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
    Commented Feb 13, 2017 at 22:02
  • 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
    Commented Feb 13, 2017 at 22:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.