5

I have the following contract:

contract Contract{
  address minter;
  uint gid;

  //...

  //constructor
  function Contract(){
    minter=msg.sender;
    gid=0;
  }
  function kill(){
    if (msg.sender == minter){
      suicide(minter);
    }
  }

  function createAgreement(string name){
      //blah, blah
      //...

      gid++;   //what happens here?!
  }

What happens if 100 users all call createAgreement(...) at the same time (i.e. on the same eth.blockNumber)? Do EVM nodes compete with each other?

I need gid to be unique for each of these 100 users!

Will gid be unique? Or do I need to do something different?

  • I did some testing and it appears that gid is being incremented correctly?! Can someone more knowledgeable on blockchains please explain this to me? I guess this is the wonder of blockchain, right? – Eamorr Feb 14 '16 at 14:04
7

All comptutations that end up on the block chain are done by the lucky miner that mines a block. So there are no competing nodes on the same block. And I believe transactions are being handled one at a time synchronously so you don't have to worry about any race conditions.

All 100 user will have a unique gid with this code.

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.