I am trying to update the code of a smart contract using the chain-extension functionality instead of using the ink_env::set_code_hash
method. The contract pallet successfully emits the ContractCodeUpdated
event with the expected values. Still, after the execution of the contract, the state changes are not persisted and the contract continues to use its original code hash (though changes made in the contract's own storage persists).
The sample code can be found here (https://github.com/realnimish/contract-upgrade-test).
Reproduction steps
- Create a chain extension that takes an input -
(Contract Address, New Code Hash)
and calls the Contracts::set_code extrinsic and returns the result. impl-chain-ext - Create an ink! contract (C1) which interacts with the chain-extension and deploy it. impl-C1
- Create another ink! contract (C2) which can call C1 to update its code and deploy it. impl-C2
- Create an ink! contract (C3) to which C2 should update to and upload it. impl-C3
- Call the C2 contract method which calls C1 and updates itself to C3 code. impl-unit-test
Expected Outcome: Contract C2 now has the code_hash of C3
Actual Outcome: Contract C2's code_hash doesn't change after the execution even though Contract pallet emits that the contract code has been updated and the smart contract call doesn't fail.