Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade dependent contracts within a single transaction #5819

Open
janezpodhostnik opened this issue Apr 30, 2024 · 0 comments
Open

Upgrade dependent contracts within a single transaction #5819

janezpodhostnik opened this issue Apr 30, 2024 · 0 comments
Assignees

Comments

@janezpodhostnik
Copy link
Contributor

janezpodhostnik commented Apr 30, 2024

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
@janezpodhostnik janezpodhostnik self-assigned this Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant