ava-labs / hypersdk

Opinionated Framework for Building Hyper-Scalable Blockchains on Avalanche
Other
202 stars 109 forks source link

Move state keys from actions to transaction #1651

Open tsachiherman opened 3 weeks ago

tsachiherman commented 3 weeks ago

Why ?

The currently used state keys are defined on the action level, and are mean to support actions that execute arbitrary code that might touch some arbitrary set of keys.

While this is all fine, the preloading and execution is always on the transaction level. Moving these keys to reside at the transaction level would align with the transaction execution atomicity as well as reduce the transaction size due to duplicate keys.

aaronbuchwald commented 3 weeks ago

ref https://github.com/ava-labs/hypersdk/blob/0a2d991a0877ee4921f6ed0b31e4525a061b3a65/chain/processor.go#L52

Each action is executed with the TStateView that includes state keys from all of the actions and the transaction. This can cause potentially unexpected behavior where if action1 specifies a state keys that action2 reads, but did not specify, then action2 will actually be able to successfully use that state key.