flow-cli icon indicating copy to clipboard operation
flow-cli copied to clipboard

Handling contract updates on emulator

Open devbugging opened this issue 2 years ago • 1 comments

A Cadence developer will during the development process frequently change contracts which makes keeping the contract updated on the emulator a challenge. The Flow mainnet/testnet has limitations on updating the contracts which are too strict to support the initial development of contracts. This problem is present on flow dev but also on Playground. Bellow are two ways of how we are or could handle changes. Each with some downsides.

Current state Current state handling allows contract updates by removing and redeploying the new contract which can lead to a case where a resource was saved in an account but the contract update removes the resource altogether making the stored resource invalid.

Blocks Account Alice Account Bob State Comment
1 Foo(contract ver:1) X  
2 Foo(contract ver:2) Created  
3 Foo(contract ver:2)    
4 Foo(contract ver:2), Zoo(resource) Zoo(resource)  
5 Foo(contract ver:3 - removed Zoo resource type), Zoo(resource) Zoo(resource) Non-existing resource Zoo on account Alice and Bob

State handling with reset State handling with reset always resets the state after updating the contract thus also clearing the accounts with possible no-longer valid types, however, it presents another problem where any accounts created after will no longer exist.

Blocks Account Alice Account Bob State Comment
1 Foo(contract ver:1) X  
1 Foo(contract ver:2) X  
      Reset state
2 Foo(contract ver:2) Created  
1 Foo(contract ver:3) X  
      Reset state
1 Foo(contract ver:3),Zoo(resource) Created  
2 Foo(contract ver:4),Zoo(resource) Zoo(resource)  
      Reset state
1 Foo(contract ver:4) X  

devbugging avatar Apr 20 '23 14:04 devbugging