0

If we take blockchain.info; how do they know when a new block has arrived?

I understand that there is a full node running on the background, how would they have setup their infrastructure, so that their db which serves the users, is in sync with the full node db? I cannot think of a way to be alerted of when a new block arrives. It's not like the full node will tell you that we have a new block right? So do they watch the leveldb for changes?

Also, is it possible that they have full nodes that only respond to requests from blockchain.info?

2 Answers 2

1

I cannot think of a way to be alerted of when a new block arrives. It's not like the full node will tell you that we have a new block right?

I believe that it will. Check the events you can subscribe to via the websocket interface.

But you could instead just poll every 500ms (or whatever). There are only new blocks every 10-15 seconds. Being a few hundred milliseconds behind won't hurt you.

7
  • What if I don’t want to open up rpc for the rest of the world, just me? May 26, 2018 at 10:49
  • I'm not sure what you're asking. I didn't suggest opening up RPC to anyone else.
    – user19510
    May 26, 2018 at 14:45
  • Wrong post, person below suggested RPC May 26, 2018 at 14:47
  • The other answer also didn't suggest opening up RPC to anyone else.
    – user19510
    May 26, 2018 at 14:50
  • I’m not sure how I would use the rpc interface, if I do not call it using the ip:port setup. Would I do localhost:port? If I am on the machine without rpc enabled and I have my code editor open, what steps would I take to call the rpc interface from code? May 26, 2018 at 14:54
1

You can easily poll on the RPC interface for getBlockByNumber (“latest”) which will return the latest block. That’s not difficult at all because as the other answer says, you only get a block every 15 seconds or so.

The difficult part is that more often than you might think, the chain re-orgs, which means a block changes. So you have to revisit blocks to make sure there aren’t reorgs.

A lot of explorers even go a step further and scrape pending transactions which aren’t even in a block yet, but in the pending transaction queue. There’s an RPC interface for this too.

Some explorers even dig into to guts and read the database directly, as you mention.

2
  • I would want to only run the rpc interface locally and query it from my code. Based upon your answer, I have created another question, to not go off-topic: ethereum.stackexchange.com/questions/49587/… May 26, 2018 at 15:13
  • Thanks. I saw your other questions. Unfortunately, I'm not very well versed in running a node remotely. I run my node locally on my own machines, and I run the code that does the RPC queries on the same machines, so the queries are to localhost. I'm not sure how to set things up so you can query remotely and still be secure. May 27, 2018 at 1:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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