FuelLabs / fuel-core

Rust full node implementation of the Fuel v2 protocol.
Other
58.02k stars 2.78k forks source link

The `state_root` calculation for the `Create` transaction takes an eternity #1143

Closed xgreenx closed 1 year ago

xgreenx commented 1 year ago

If the user provided a vast number of storage slots(in the Create transaction) during the contract creation, it takes a lot of time to calculate the state_root.

We currently use a default value 255 for the ConsensusParameters::max_storage_slots, so it is not critical. But if we want to support duplication of the contract with their state, we need to speed up this process and increase the default max_storage_slots.

freesig commented 1 year ago
bvrooman commented 1 year ago

Our current approach is based on the idea that we can implement a new algorithm that takes advantage of having all the leaves of the Sparse Merkle tree up front. Theoretically, this knowledge can be used to reduce or eliminate redundant calculations when compared to sequentially updating the SMT for each leaf, where we recalculate the root at each update operation.

This means: