I'm using web3py's getBlock function to get the latest block. I am right now caching the latest 50 blocks so that I reduce the amount of workload in my geth node, and to improve overall speed in my service, since a recently created block is likely to be inspected several times in a short period of time.

In that scenario, could that block change because a different longer chain appeared and the chain my node was following gets invalidated? Or in other words, when I execute w3.eth.getBlock('latest', full_transactions=True) how certain can I be that this block is going to actually remain in the chain?


This is basically a question of how often uncle blocks happen. You can see statistics here: https://etherscan.io/chart/uncles

If we look at https://etherscan.io/chart/blocks we see there are about 6400 blocks per day. The uncle chart says about 400 uncles per day. So the chance that the latest block is an uncle is something around 400/6400 which means about 6,3%. This is not entirely the right figure as the uncle may appear only on the second or third block or so, but it's a good enough estimation.

  • So 0.06% chances the block is not on the chain... this makes caching pretty hard. Thanks a lot for your answer!
    – Molina
    Nov 15 '19 at 10:59
  • Since we are on it, say in an uncle I've cached there's a transaction T I'm interested in. If that transaction T was actually included in a different block that got mined first, will it have the exact same hash so that it doesn't really matter if I inspect it in the uncle or the mined block?
    – Molina
    Nov 15 '19 at 11:01
  • 1
    It's still the same transaction just in a different block, so yes it will have the same hash Nov 15 '19 at 11:04
  • Understood. Again, thank you very much!
    – Molina
    Nov 15 '19 at 11:12
  • 2
    An uncle is a block, not a transaction. You should be dividing by blocks per day, which is closer to 6400 - etherscan.io/chart/blocks Nov 15 '19 at 16:35

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.