dominant-strategies / go-quai

Official Go Implementation of the Quai Network
GNU General Public License v3.0
2.37k stars 459 forks source link

[State] - Add State priced per Block in Gas for Quai + Documentation #1975

Closed mibuono closed 1 week ago

mibuono commented 1 month ago

Unit tests are required here - need to be able to test this before regression testing which is a separate task.

mibuono commented 1 month ago

New field in header + controller that modifys that field.

4 tasks:

  1. Controller task - create a moving average filter for the base fee. Make it a multiplier on the base.

  2. Need to check the state trie fill rates - if the rate is filled, then the state base fee needs to go up more than the base fee. Need to know current size of state trie, and the state change in the block. Gas used, state used per block - need to track both. Need a field in the block called state fee.

  3. Self destruct task - implement self destruct to pay gas back credited back at the current state rate. So you could spend it on state or spend it on gas.

  4. Need to check the gas limit: at the end of the transaction in order for it gas used + previous gas used must be < gas limit.

Notes:

What happens when someone gets paid back at a higher rate than the gas they spent to do it? Is there a gas refund in the end?
-Can't refund more than the person put in. You can only

Treat it as Gas - so a user can havea. refund that is greater than what they put in.

What happens if someone destroys a huge amount of data and gets more gas than the gas limit for a block?

If gas used in the transaction pushes us past the limit, transaction should fail.

alanorwick commented 1 month ago

Current plan: add a ceiling / limit for state per block. users will use the miner tip using the block. pricing the SLOAD / SSTORE opcodes using the size of the trie associated.

Tricky party: The SSTORE operation is not one single API / state operation - 6 different cases. How do we simplify/price that?