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

[Stacks 2.1] Consider defaulting to versioned-smart-contracts after 2.1 hardfork #1346

Closed
zone117x opened this issue Aug 29, 2022 · 0 comments · Fixed by #1463
Closed

[Stacks 2.1] Consider defaulting to versioned-smart-contracts after 2.1 hardfork #1346

zone117x opened this issue Aug 29, 2022 · 0 comments · Fixed by #1463
Assignees
Milestone

Comments

@zone117x
Copy link
Member

zone117x commented Aug 29, 2022

Related to #1341

The above PR adds the capability to create and deserialize the new versioned-smart-contracts tx types, which is helpful for projects to upgrade to before the 2.1 fork so that codebases are prepared for the fork.

However, the builder functions default to creating a Stacks 2.0 regular smart-contract tx type so that codebases don't create a bad tx type that won't work before the 2.1 fork.

Once the 2.1 hardfork is live, this library should then publish a new version that defaults to versioned-smart-contracts in order to avoid a lot of developer confusion when Clarity2 features are used in the contract source code, but the tx fails when the explicit clarityVersion arg is not specified.

This would ensure the typical usage will just work before and after Stacks 2.1:

const transaction = await makeContractDeploy({
  contractName,
  codeBody,
  senderKey
});

Alternatively, makeContractDeploy(...) could detect if 2.1 is live and use that for the default, but this would require an additional network call. And AFAIK there's currently not a great way to detect if 2.1 is live. Right now, it would involve something like:

async function is21HardforkLive(): Promise<boolean> {
  const req = await fetch(`/v2/data_var/ST000000000000000000002AMW42H/pox-2/configured?proof=0`);
  const body = await req.text();
  if (req.ok) {
    // This might only return true after "period 2" (after PoX cycle N+1 after the Stacks 2.1 fork), see https://github.com/stacksgov/sips/blob/c0fb33e0fc2b62e8e6d4ed85fb4b4aa289bb6042/sips/sip-015/sip-015-network-upgrade.md#specification
    // Might be more accurate to instead just `return true` here, i.e. if status is 2xx then pox-2 contract has been deployed, which I think means Stacks 2.1 has activated.
    return JSON.parse(body)['data'] === '0x03'; // Clarity boolean-true
  } else if (req.status === 404 && body === 'Data var not found') {
    return false;
  } else {
    throw new Error(`Unexpected response: ${req.status} - ${body}`);
  }
}

The first approach makes more sense to me, but I'm open to either or other suggestions.

@zone117x zone117x changed the title [Stacks 2.1] Consider defaulting to versioned-smart-contracts _after_ 2.1 hardfork [Stacks 2.1] Consider defaulting to versioned-smart-contracts after 2.1 hardfork Aug 29, 2022
@janniks janniks added this to the Q3-2022 milestone Sep 26, 2022
@saralab saralab modified the milestones: Q3-2022, Q4-2022 Sep 30, 2022
@janniks janniks added the P1 label Oct 19, 2022
@janniks janniks linked a pull request Nov 16, 2022 that will close this issue
@janniks janniks removed a link to a pull request Nov 16, 2022
@janniks janniks removed the P1 label Feb 2, 2023
@lgalabru lgalabru added this to DevTools Feb 2, 2023
@github-project-automation github-project-automation bot moved this to 🆕 New in DevTools Feb 2, 2023
@lgalabru lgalabru modified the milestones: Q4-2022, Q1-2023 Feb 2, 2023
@lgalabru lgalabru moved this from 🆕 New to 🔖 To do in DevTools Feb 3, 2023
@lgalabru lgalabru moved this from 🔖 To do to ❄️ Icebox in DevTools Feb 3, 2023
@lgalabru lgalabru moved this from ❄️ Icebox to 🔖 To do in DevTools Feb 3, 2023
@github-project-automation github-project-automation bot moved this from 🔖 To do to ✅ Done in DevTools Mar 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants