I am learning solidity/ethereum and I came across this situation:
I have a mapping(address => unit) that keeps track of how much every address is paying my contract, and at some point, I have to compute how much % of the total pool has one user contributed with. (for example, if the total pool is 100 ethers and user contributed 10 ethers, he has contributed with 10% of the total pool).
In order to do so, I need to have access to the total pool. My first instinct was to have a variable totalPool which will keep track of the total value, therefore every time an address is paying the contract, totalPool += msg.value; However, while learning about the EVM, I kept reading how expensive it is to operate on the storage.
My question is, what is cheaper in terms of gas, to keep track of the total pool and operate on memory every time an address pays the contract, or to compute the total pool every time when I need to find out the ratio contribution?