Skip to content
This repository has been archived by the owner on Dec 1, 2023. It is now read-only.

Deploy through Accounts #276

Merged

Conversation

ericnordelo
Copy link
Member

@ericnordelo ericnordelo commented Nov 2, 2022

Fixes #259, #277

@ericnordelo ericnordelo marked this pull request as draft November 2, 2022 14:59
@ericnordelo ericnordelo changed the title feat: add main logic Deploy through Accounts Nov 2, 2022
@ericnordelo ericnordelo marked this pull request as ready for review November 3, 2022 14:18
@ericnordelo ericnordelo linked an issue Nov 3, 2022 that may be closed by this pull request
Copy link
Contributor

@andrew-fleming andrew-fleming left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking really good, @ericnordelo! I left a few comments.

Also, I think we should add some tests for deploy_contract from deploy.py and account.py. We can probably reuse most of the existing deploy tests with some adjustments.

README.md Outdated Show resolved Hide resolved
src/nile/core/account.py Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
src/nile/cli.py Show resolved Hide resolved
ericnordelo and others added 3 commits November 8, 2022 12:36
Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>
Copy link
Contributor

@andrew-fleming andrew-fleming left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! I left some comments :)

Some other notes:

src/nile/core/deploy.py Outdated Show resolved Hide resolved
Comment on lines 80 to 83
if unique:
# Match UDC address generation
salt = compute_hash_chain(data=[account.address, salt])
deployer_for_address_generation = deployer_address
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about including a random salt generator for deployments without --salt like StarkWare does? => https://github.com/starkware-libs/cairo-lang/blob/master/src/starkware/starknet/cli/starknet_cli.py#L846-L847

Otherwise, trying to deploy multiple instances of the same contract will result in:

raise StarkException(code=code, message=message) starkware.starkware_utils.error_handling.StarkException: (500, {'code': <StarknetErrorCode.CONTRACT_ADDRESS_UNAVAILABLE: 1>, 'message': 'Requested contract address 1999693730423262048654525999365022023777068478432229193013554800567845966099 is unavailable for deployment.'})

Users can add salt to avoid this, but automating salt seems preferable

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we agree^, I definitely suggest adding some salt tests

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this salt should be part of the protocol (like nonce in Ethereum deployments), but I am not sure why it is left to be passed from the end users (am I missing an important reason?). With this said, agreeing on a format for the automatic generation of this salt, I think, is content enough for another issue/PR. Shouldn't be any problem with releasing this version, right? I don't see a reason to delay it to another milestone.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this salt should be part of the protocol

I agree in general haha but since we're deploying contracts through an account.send tx, the burden seems to fall on Nile. When Nile interacts with the starknet_cli directly (and when Nile most likely bypasses the cli in the future), I imagine defining a salt generator will not be necessary

agreeing on a format for the automatic generation of this salt, I think, is content enough for another issue/PR

That sounds reasonable to me

I don't see a reason to delay it to another milestone.

I don't disagree

Copy link
Contributor

@martriay martriay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes! This is almost done

README.md Outdated Show resolved Hide resolved
src/nile/core/account.py Outdated Show resolved Hide resolved
src/nile/core/deploy.py Outdated Show resolved Hide resolved
src/nile/signer.py Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
ericnordelo and others added 2 commits November 15, 2022 21:22
Co-authored-by: Martín Triay <martriay@gmail.com>
Co-authored-by: Martín Triay <martriay@gmail.com>
andrew-fleming
andrew-fleming previously approved these changes Nov 15, 2022
Copy link
Contributor

@andrew-fleming andrew-fleming left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The improvements look great! Making the API consistent with nile deploy <key> <contract> is much more intuitive, so kudos on the change!

I left a +1 to Marto's comment in removing the _tx on the signer methods. I don't think there's much to gain with it included.

Otherwise, this looks good to go for me :)

@ericnordelo
Copy link
Member Author

I left a +1 to Marto's comment in removing the _tx on the signer methods. I don't think there's much to gain with it included.

The _tx can be removed, but the change I wanted to introduce was replacing sign_transaction by sign_invoke, because sign_transaction sounded like it could be used to sign declares, or deploy_account, transaction, and this is not the case (_tx was because it looked better to me atm sign_invoke_tx than sign_invoke)

@andrew-fleming
Copy link
Contributor

_tx was because it looked better to me atm sign_invoke_tx than sign_invoke

That's fair...sign_invoke doesn't look that great. I don't mind sign_execute though as previously mentioned, but no objections by me if we keep it as is

@ericnordelo
Copy link
Member Author

That's fair...sign_invoke doesn't look that great. I don't mind sign_execute though as previously mentioned, but no objections by me if we keep it as is

I chose invoke over execute to follow the starknet source code wording (as you can see here.)

@martriay
Copy link
Contributor

martriay commented Nov 17, 2022

I get the point, but Invoke is a legacy term for when you could call any arbitrary entry point. I don't think following legacy terminology adds much clarity to users now that invoke is just a proxy to call __execute__ with it.

That being said, I don't think it makes a big difference either, I lean towards execute but no strong opinions really.

@ericnordelo
Copy link
Member Author

I get the point, but Invoke is a legacy term for when you could call any arbitrary entry point. I don't think following legacy terminology adds much clarity to users now that invoke is just a proxy to call execute with it.

That sounds fair, but we are still using invoke (not execute) in important parts of the project, like in logging for cli (with nile send for example, and other commands), in the README as well, or in the source code where we have call_or_invoke, and invoke type for transactions as some examples. I think sign_invoke is more consistent with what we have, but we could refactor this in a separate issue if you agree.

martriay
martriay previously approved these changes Nov 18, 2022
Copy link
Contributor

@martriay martriay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

either sign_invoke or sing_execute are fine with me as long as we drop _tx. this is ready :)

@ericnordelo
Copy link
Member Author

either sign_invoke or sing_execute are fine with me as long as we drop _tx. this is ready :)

Removed the _tx suffix :)

Copy link
Contributor

@andrew-fleming andrew-fleming left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we're good to go!

@martriay martriay merged commit 6fee778 into OpenZeppelin:main Nov 18, 2022
@ericnordelo ericnordelo deleted the feat/deploy-through-account-#259 branch November 18, 2022 23:52
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add warning about deploy deprecation make nile deploy go through an account
3 participants