First Come First Serve

Is there a way to implement a first come first serve rule fairly in a contract? How would it be done?

Comments

  • CfBCfB Member Posts: 29
    @jrkirby, define "first come" for transactions from the same block, plz.
  • mids106mids106 Member Posts: 188 ✭✭✭
    You can set a boolean flag or increase a counter in the contract storage if a user calls the contract. First time this will be false, upon subsequent calls you can detect that it isn't the first time anymore.
  • jrkirbyjrkirby Member Posts: 3
    CfB said:

    @jrkirby, define "first come" for transactions from the same block, plz.

    That's what I mean. What happens to a first come first serve strategy when there are multiple requests in a single block?

    Do you just randomly choose one? Could the miner of that block have an influence on which one gets processed first? What's the correct strategy here?
  • CfBCfB Member Posts: 29
    One of other cryptos sorts transactions according to their hashes to get natural order inside a single block. Maybe u could do the same?
  • JasperJasper Eindhoven, the NetherlandsMember Posts: 514 ✭✭✭
    Just doing what @mids106 says should be fine for anything that isnt super-important. And if it is super-important you might want to do bidding or something anyway, not leave it on a whim.

    Note that the miner could leave out transactions, so he could strongly affect the result, regardless of whether it is sorted.

    Miners also get more power by miner gets to order the transactions with a block, depending on how the contracts work. Could try change the order of execution based on something like H(block_hash, coinbase, origin) to pre-empt this. If you assume selfish miners, eventually people will drop blocks in order to affect it, so afaik you cant totally stop it. Generating random values has the same problem, but now we're not at the contract level so we cant use RANDAO.

    The contract that you want the first-come-first-serve in could use RANDAO though, and basically, could make it 'psuedo-first-come', for instance anyone in 3 blocks after the 'first' plays, and you just use RANDAO to pick a random one. (really, first come first serve is a crapshoot anyway?)
  • jrkirbyjrkirby Member Posts: 3
    Thanks, these answers have been informative.
  • JasperJasper Eindhoven, the NetherlandsMember Posts: 514 ✭✭✭
Sign In or Register to comment.