# req-070 Given a bucket, `bucket`, if the procedure `is_bucket_balance_up_to_date(bucket)` as described in req-035 returns TRUE, then `bucket.balance` is equal to the difference between the amounts of the drips into it and the amounts of the transactions out of it. Sources: req-036, ass-008 Satisfied by: req-030, req-070, req-071, req-072, req-073 ## Proof Grant req-030, req-070, req-071, req-072, req-073. Let `bucket` be a bucket, and suppose that `is_bucket_balance_up_to_date(bucket)` as described in req-035 returns TRUE. It follows that: - `bucket.balance_cache_key` is of the form `:` - The first part is the ID of a drip: call it `drip` - There is no `drip_2` such that `drip_2.timestamp > drip.timestamp` - The first part is the ID of a transaction: call it `transaction` - There is no `transaction_2` such that `transaction_2.timestamp > transaction.timestamp` Given req-071, when `bucket.balance_cache_key` was last set to this value, running `calculate_bucket_balance(bucket)` immediately afterwards would have left `bucket.balance_cache_key` and `bucket.balance` unchanged, even under the pretence that `is_bucket_balance_up_to_date(bucket)` returns FALSE. Given req-030, running `calculate_bucket_balance(bucket)` at that time under that pretence would have set `bucket.balance` to the difference between the amounts of the drips into the bucket and the amounts of the transactions out of the bucket. Since there is no `drip_2` such that `drip_2.bucket_id = bucket.id` and `drip_2.timestamp > drip.timestamp`, it follows that there are no more drips into the bucket now than there were then. Symmetrically, it follows that there are no more transactions out of the bucket now than there were then. Given req-072, it follows that there were no more drips into the bucket then than there are now. It follows that there are the same drips into the bucket then and now. It follows from that, given req-072, that the amounts of the drips into the bucket are the same now as they were then. Given req-073, and the assumption that the time we are considering is the last time `bucket.balance_cache_key` was set, it follows that no transactions have been deleted or updated since then, and so it likewise follows that the amounts of the transactions are the same now as they were then. It follows that the difference between the amounts of the drips into it and the amounts of the transactions out of it has not changed since then. Since that is ex hypothesi equal to the value of `bucket.balance` which was set at that time, and since ex hypothesi that is the same value of `bucket.balance` which obtains now, it follows that `bucket.balance` is equal to the difference between the amounts of the drips into the bucket and the amounts of the transactions out of the bucket. QED.