I read some pages here about concurrency but I didn't give my answer, actually I am new to Bchain, consider this scenario:
There is a game contract on the blockchain for 4 Players, so far three players are registered to the game and there is only one remaining! for example two different people from two different regions want to Enter to the game. And both of them connect to two different nodes(miner). So in every single node the contract can compare the remaining players and let the guy be in. But at the end there are two players are registered while there were only one position remained.
1- are these type of scenarios possible in blockchain??
2- what is the solution?
if it was a centralized system I could block the code by lock, semaphore, etc but here the code are distributed on every single miner, I mean each request for transaction is sent to different miner. Thanks
EDITED if both of them enter to this code in two different miners and both miner just see that the count is less than 4 so they add the sender to the list and return "ok"..!!!!
function AddPlayer(string name) public returns(string)
{
if (PlayersCount < 4)
{
PlayersCount ++;
// add he address of player to a list and …..
return "ok";
}
EDITED 2
1- On how many nodes should this code be runned? I mean after sending the request from frontend application to this function it just return to me a true or false, right or wrong? So if it returns a true/false What is the broadcating? it is something like simple RPC. a function is called and the result is returned!!
2- what do you mean exactly by broadcasting transaction, does this "addPlayer" function call another "addPlayer" on the other node?? there isnt anything like this in the code,
3- I read something about validate the transaction, can you tell me how this function be validated after execution? does it need another function to validate it
Sorry for long questions , I really need the answers.