gringotts icon indicating copy to clipboard operation
gringotts copied to clipboard

AccountChest logic changes

Open GroobleDierne opened this issue 3 months ago • 3 comments

The goal of this PR is to change the way transactions from and towards account chests works in order to avoid loading chunks on every transaction.

The idea behind this is to store in the database the balance of every AccountChest, when a transaction is made, the system will check if the account has enough money based on the sum of its vaults' balances stocked in DB or on the account's balance (not sure if this information is calculated on every call currently). If the account has enough money and the transaction can be made, a PendingTransaction will be emitted containing the targeted chest and the amount to credit/withdraw. Once a new chunk is naturally loaded, the pending transaction system will check if there is a transaction for a vault in that chunk and apply it if so. If the chunk is already loaded when the transaction occurs, no need to go through the pending system. Of course, the pending transactions need to be stocked in the database in case of a crash or server restart.

Additional features that I'm not sure are worth implementing at this point:

  • Possibility to set in the config a threshold of chunk loading per minute: the pending system would load the chunk and apply a set amount of transactions every minutes or so to avoid the queue increasing to much.
  • On server shutdown, apply every remaining transactions, it could significantly slow down the shutdown and some people could think of it as a bug and kill the server during the process.

I'm opening this pull request very early in the process to get reviews on the concept mainly from @nikosgram & @painOchoco .

GroobleDierne avatar Apr 04 '24 08:04 GroobleDierne