...by Daniel Szego
"Simplicity is the ultimate sophistication."
Leonardo da Vinci

Sunday, December 17, 2017

Solidity and Truffle Tips and Tricks - Computing contract data in a timed fashion

So, let we make a little bit brainstorming about generally data calculation and data consistency in solidity. Let we have the following contract: 

contact DataSync{
   uint public syncVar;

  function computeVarSync() public {
    syncVar = <complicated computation>;

In our example, we have a syncVar variable that is public, so we can read out the value anytime we want, for setting the value however we have a function that contains a complicated computation that might require a lot of gas to execute. In such an example, we might consider to call the setter valuable as rarely as possible, as an extreme example a timer job might be implemented somehow that calls the complex function once a week. Certainly, on the one hand, the use case must accept that the syncVar variable contains only the value computed the last week. On the other hand, the timer job concept is not really decentralized, so we must make sure that the computeVarSync method can be called by the community and that calling the function two times in a row does not cause any unexpected effects.