Let we have an ethereum node which is for a watch purposes only (it doesn't create any transactions, just updates it's replica of the whole chain).
To get notifications about top blocks in the chain in most of the Ethereum libraries (especially web3j and EthereumJ) we should write some listener class with some method which will eventually be called. Something like this:
class EthereumListener {
public void onBlock(Block block) {
long blockNumber = block.getNumber();
//...
}
}
My question is: may I be sure that the block
which the listener is being notified is already on the main chain and will not become stale?
In other words: may the block
be Uncle? May it be that if I later ask client for the block with this number I get a block with different content because Uncle block was replaced by the valid one in the client's replica?
If the answer is 'Yes' my second question is: does library (web3j or EthereumJ) notify me through the onBlock
method about the new valid block when it replaces an Uncle one?
In other words: may blockNumber
be the same between different invocations of onBlock
method?