0

Suppose in blockchain network we have 5 nodes and we have new transaction done by first node of network, so now rest of 4 node will mine the transaction to commit it in blockchain network, will the nonce be same for all node mining the same transaction?

0

A miner (honest) more or less,in high level, runs the following algorithm:

  1. Listens the network for transactions and blocks.
  2. Constructs a block that includes: a) all valid transactions b) a reference to the previous block (parent hash) c) new state.
  3. Search for a proof of work based on the constructed block in step 2.
  4. If she finds a block she broadcast it to the network.
  5. If another miner found a block she drops her previous work and continue the mining in the most recent block.

Proof-of-Work (high level):

H(state || txs || nonce || parent-blockid) < T

where T is the target.

To find a proof of work each miner runs the following algorithm (high level / pseudocode):

do {
    nonce = rand();
} while (H(state || txs || nonce || parent-blockid) >= T);

return nonce;

So the nonce is totally random and that's what miners try to find: a nonce that satisfies a condition.

The first miner to find a block wins and all other honest miners drop their work and start mining on the new block (miners adopt the "heaviest" chain).


Previous answer (account nonce)

The nonce is part of the state of the account. The global state of Ethereum consists of all accounts. A change in the state of an account is a change in the global state. All nodes of the network have to agree on that state. The agreement to the new global state is being made with the use of a consensus algorithm such as Proof-of-Work (PoW). At the end all nodes will agree on the same nonce.

  • So how the nonce is decided? That this nonce will be same across network, mean all nodes are mining and calculating their own nonce and matching the hash(block data + nonce) with targetHash value whether it is less than or equal to targetHash value so there are chances that many nodes find such type of nonce that satisfy the condition – Rishabh Singh May 22 at 10:50
  • Oh sorry my mistake. I thought you meant the account nonce. I will update my answer accordingly. – Laxmana May 22 at 10:59
  • thank you so much. – Rishabh Singh May 22 at 11:48
  • In this code do { nonce = rand(); } while (H(state || txs || nonce || parent-blockid) >= T); return nonce; your hash of H((state || txs || nonce || parent-blockid))) is grater than Target Hash but I read that is should be less than or equal to. Correct me if I am wrong – Rishabh Singh May 22 at 11:54
  • The do-while loop should run until a valid nonce is found. So the condition in the do-loop says if the H(...) is bigger than T continiue looping. If not stop and return the valid nonce. – Laxmana May 22 at 11:59

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.