I am reading the Solidity by example voting example. I am interested in the vote
contract function:
function vote(uint proposal) {
Voter sender = voters[msg.sender];
require(!sender.voted);
sender.voted = true;
sender.vote = proposal;
// If `proposal` is out of the range of the array,
// this will throw automatically and revert all
// changes.
proposals[proposal].voteCount += sender.weight;
}
What happens if a transaction runs out of gas after the line sender.voted = true;
but before the line proposals[proposal].voteCount += sender.weight;
. In this case, it seems like the vote will be counted as made, but actually the voteCount
will not be updated. Because of the require(!sender.voted);
line, the voter cannot attempt to revote with a higher gas limit.
How are such out of gas situations handled in practice to guarantee atomicity of setting sender.voted
and incrementing proposals[proposal].voteCount
?