2

I'm trying to write a node that listens all the bitcoin transactions in real time. I'm considering two ways of doing this: The first one is to check mempools of other nodes periodically and the second one is to act like a relay so that other nodes can broadcast transactions to my node. I'm not keeping any blockchain data so it is out of question for me to verify the transactions. So my question is which one would be more reliable, secure and real time? I think the first one is more reliable because in the second case it's not certain that all transactions will be broadcasted to me but again it seems like there won't be any latency in the second case. What do you think? And also are there some better ways to achieve this?

ps: i don't want to use a third party api, it all should be handled from my node.

1 Answer 1

3

Without verifying the transactions themselves, there's no guarantee that the transactions you get from either method are valid. Nodes can lie about what transactions they have in their mempool, for example, and send you gibberish. On the flip side, nodes also don't have any obligation to send you transactions that they have. There are non-standard transactions, for example, that many nodes simply don't relay, so you have no way to find out about them, but they may still get mined in the next block.

In order to actually verify unconfirmed transactions, you're going to need to be a full node with the entire blockchain stored so you can validate them yourself. There are no guarantees about the behavior of any other node on unconfirmed transactions and assuming that they're valid is simply not a good thing to do from a security perspective.

That said, if you want the largest set of unconfirmed transactions possible, the easiest way is to connect to as many nodes as possible and get whatever transactions they have in their mempools. The bitcoin network protocol has a lot of very useful commands for this purpose that you can create. Of particular interest are the inv and getdata commands.

Of course, that's exactly what bitcoind already does and it verifies all the transactions to boot, so you'd really honestly be duplicating that exact same function. The big optimization opportunity here would be mostly on choosing the best peers that somehow are "most informed" about unconfirmed transactions.

2
  • What if i don't accept a transaction if it doesn't exist in at least two different nodes' mempool? I think it lowers the chance of my node to be tricked so i don't have to store entire blockchain. Feb 23, 2015 at 3:17
  • It also excludes transactions that are non-standard but might still make it into the blockchain. Eligius pool, for example, does non-standard transactions and it's in their mempool, but hardly anyone relays them.
    – Jimmy Song
    Feb 23, 2015 at 3:18

Your Answer

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

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