pendulum-chain / pendulum

GNU General Public License v3.0
43 stars 14 forks source link

Implement and test potential solution for mock-skip blocks on runtimes #486

Open bogdanS98 opened 4 months ago

bogdanS98 commented 4 months ago

Continuation from this ticket. This ticket comes directly as an action point from #190.

Context and recap

We are currently using an isolated foucoco-based runtime for wasm-deploy testings. This variant of the runtime allows us to skip blocks for testing purposes by calling a modified pallet contracts which in turns modifies the reported block number that the contracts see.

We want to remove this extra repository and have this functionality on the main Foucoco repository itself.

Solution to explore

We would like to create a new pallet that would be conditionally compiled with a test feature flag (or equivalent). This pallet will have at least one extrinsic, which will not take fee nor check signature, that will set the desired block we would like the chain to report during contracts execution.

For this, we can leverage the on_initialize hook. When called, we will store the current block number and then call directly the set_block_number method of the frame system pallet and set it to the desired value.

Then, when on_finalize is called, this pallet should revert the changes done on the frame system pallet. The idea is that only during execution of extrinsic the block reported is different to what it should actually be, and does not interfere with production of blocks. See the lifecycle of hooks and extrinsics for context.

Since this will likely introduce an issue with the validity of any transaction made whenever the block has been changed (see this comment for more details), we need to modify the instances were wasm-deploy submits extrinsics to the chain such that the transaction is specified as Immortal. The calls are formed here and here either for deployment or call to an existing contract. Since api-solang already allows for specifying a modifyExtrinsic function, this would be a good place modify the transaction from Mortal to Immortal.

Testing

Ultimately, we are currently using the functionality to skip blocks here. Once the new solution is in place, we should be able to modify the skipBlock function so it calls the new pallet and test if the solution works.