flow-go
flow-go copied to clipboard
Upgrade dependent contracts within a single transaction
Problem Definition
In the following situation:
- there is a contract B0 that depends on contract A0
- we want to update contract A0 and B0 to A1 and B1 in a way where B0 breaks when A0 is updated to A1 and B1 is broken if it uses A0
flowchart TD
B0 --> A0
B0 --> A1
B1 --> A0
B1 --> A1
linkStyle 0,3 stroke:green
linkStyle 1,2 stroke:red
This is impossible to do without having an intermittent state where B is broken.
This is because contract updates are only effective after the transaction has finished. So the transaction:
tx {
Update A0 to A1
Update B0 to B1
}
would fail because at the second instruction B1 is importing A0 as A0 only updates to A1 after the transaction body is executed.
An instance of this occurring was an update to system contracts where one system contract was updated, and a few blocks later the other was updated. In between those transactions the system transaction always failed.
relevant discord conversation: https://discord.com/channels/613813861610684416/1108968095982293002/1210247669683986442
Proposed Solution
While contract updates are delayed until the end of the transaction we could use the updated contract code for cadence type checking for the subsequent updates in the same transaction.
tx {
// Actual update is delayed until the end of the transaction
Update A0 to A1
// When type checking B1 use code from A1 instead of that of A0
Update B0 to B1
}
Definition of Done
- Contracts can be updated so that dependant contracts are updated within the same transaction