When a contract is triggered, all nodes execute the code; where exactly does consensus come in? Are they agreeing upon the OUTPUT or just the code itself?


2 Answers 2


What I expect should be happening from my reading of the docs (I have not personally traced through the code or the consensus process yet):

  • Each mining node selects a list of pending transactions from the transaction pool and executes these transaction (including the insertion and execution of smart contract code).
  • The results from the above executions will change the balances of accounts and the data stored with smart contract code (including the insertion of new contract code into the blockchain).
  • The transactions and updated data are packaged into a block and the transaction hash + block hash + nonce is iteratively solved to calculate a hash. If this computed hash is less than a target number (determined by the current difficulty level), the mining node has solved the block and broadcasts this winning block results across the P2P network.
  • Each node receiving this broadcasted block executes the transactions and smart contract code in the order specified by the winning block, and records the resulting changes to account balances and data stored with smart contract code.
  • Each node then computes the transaction hash + block hash + nonce and verifies that the computed hash us less than the target number (determined by the current difficulty level).
  • If the computed hash is less than the target, each node accepts the winning block as valid and adds this to it's copy of the blockchain.

In summary, I expect that all nodes execute the code (and transactions) and verify the block "numbers" are valid before accepting the block as valid in the consensus process.

EDIT 12/05/2016 - As stated by @Nick Johnson, the state tree is compared as this provides a checksum of the data in the current and all previous blocks.

Q: Are they agreeing upon the OUTPUT or just the code itself?

A: They are agreeing on the output based on the execution of each transaction (including running the code).

  • 1
    A good summary, but you missed the critical point for this question: Each node also computes the root of the state tree after executing the block, and verifies it matches the one in the block. That's what they're agreeing on with regards to the contract's execution. Apr 27, 2016 at 9:26

The consensus is on the contract's values for certain block after each node executed the contract independently.

You are welcome to browse various contract and check the in consensus state:


  • Thanks--can you explain what you mean by contract values?
    – Mark J.
    Apr 26, 2016 at 19:43
  • the values that are in consensus for all nodes Apr 26, 2016 at 19:44

Your Answer

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

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