0

Recently I learned about 'chain reorganization'.

What is the change in smart contract when the 'chain reorganizations'?

for example,

contract Contract{
    event LOG_Increase();
    uint sum = 0;

    function Increase() public {
        sum++;
        emit LOG_Increase();
    }    
}

When call the solidity function Increase that increments sum from 0, If the block containing the transaction is discarded due to 'chain reorganization' Does sum become 1 and then become 0 again? Or is there no change in 0? And What about LOG_Increase events?

I can't speak English well and I got help from translator. Thank you for your understanding.

0

Just to be clear: Chain reorganization is a term used in Geth. It means the event when a different (fork of the) chain is accepted as the canonical chain - so the blockchain reaches a consensus and some already-mined blocks get discarded.

So if the chain reorganizes, all transactions in the "lost" blocks are effectively lost. It's like the transaction never happened. So, in your case, the sum becomes 0 and the event is never fired.

However, this does not mean that the same transaction might not be included and executed in a different block - perhaps in a block which is part of the new canonical chain. So your transaction may be already executed in a block which is considered "valid".

You can read more about chain reorganizations for example here (and its link): https://ethereum.stackexchange.com/a/19393/31933

  • Thank you for your answer! You mean that the smart contact variable changes and the event fires after a consensus? – Errcode Nov 20 '18 at 8:22
  • They change in the current chain whenever the transaction is executed in a block - it's just a matter of which chain becomes the "right" chain and then transactions in that chain are considered "valid" transactions. – Lauri Peltonen Nov 20 '18 at 8:23
  • I think I understand. What I see is affected by the chain's information that is synchronized to my node. In other words, that mean that even though transaction was valid before my node synchronized, it could be an invalid transaction if the chain information was synchronized on my node? Is it correct? – Errcode Nov 20 '18 at 9:32
  • It could become an invalid transactio due to chain reorganizations. Your node may be looking at the "wrong" chain. You should read a bit more about how Ethereum reaches consensus (white paper for example) - it's not about "synchronizing" your node as such - your node has all the right data until some other chain becomes dominant and then your node's chain becomes obsolete. – Lauri Peltonen Nov 20 '18 at 9:39

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.