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

Fix bugs in two examples + Fix master CI #820

Merged
merged 8 commits into from
Jun 17, 2021
Merged

Fix bugs in two examples + Fix master CI #820

merged 8 commits into from
Jun 17, 2021

Conversation

cmichi
Copy link
Collaborator

@cmichi cmichi commented Jun 16, 2021

  • Fixes the broken master CI (clippy).
  • Fixes two bugs in our examples, which I discovered while adding ink-waterfall tests for those examples.
    In the case of contract-transfer I added a waterfall test which also checks if the debug_println! in that contract example actually appears on the console.

It needs to be possible to send value with the transaction,
because `t.transferred_value` in this function could be set
to > 0.
Clippy fails otherwise:

	= note: `-D clippy::enum-variant-names` implied by `-D warnings`
	= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#enum_variant_names
@cmichi cmichi requested a review from Robbepop June 16, 2021 17:52
It needs to be possible to send value with the transaction,
because `t.transferred_value` in this function could be set
to > 0.
/// Its return value indicates whether the called transaction was successful.
/// This can be called by anyone.
#[ink(message)]
#[ink(message, payable)]
pub fn invoke_transaction(
&mut self,
trans_id: TransactionId,
) -> Result<(), Error> {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As a side note: There is another issue with this method. It internally uses

.map_err(|_| Error::TransactionFailed);

which currently would not revert the transaction. This will only happen once we have implemented error forwarding.
Currently, in this error case, the transaction would be taken (i.e. removed) out of the StorageStash, but not be executed due to the error. It would then not be possible to give the execution another try, since the transaction has been removed.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah this is a very important point made and acts as yet another motivator to implement storage reversal on error for non-ink-as-dependency calls. In the meantime we are required to panic in these critical cases.

ink_env = { version = "3.0.0-rc3", path = "../../crates/env", default-features = false }
ink_env = { version = "3.0.0-rc3", path = "../../crates/env", default-features = false, features = [ "ink-debug" ] }
Copy link
Collaborator

Choose a reason for hiding this comment

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

A better way was to introduce an ink-debug feature and forward that to ink_env.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So the problem with this approach is that cargo-contract builds with --no-default-features. But there is a ticket to forward an ink-debug feature: use-ink/cargo-contract#284.

But for now it means that if somebody builds contract-transfer with cargo-contract right now we need to explicitly enable the feature for ink_env like done in this PR, otherwise the user will not see the debug output.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We should raise the priority of the --debug flag on cargo-contract then.

/// Its return value indicates whether the called transaction was successful.
/// This can be called by anyone.
#[ink(message)]
#[ink(message, payable)]
pub fn invoke_transaction(
&mut self,
trans_id: TransactionId,
) -> Result<(), Error> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah this is a very important point made and acts as yet another motivator to implement storage reversal on error for non-ink-as-dependency calls. In the meantime we are required to panic in these critical cases.

Copy link
Collaborator

@Robbepop Robbepop left a comment

Choose a reason for hiding this comment

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

Issue created: #823

Approved.

@cmichi cmichi merged commit 41aa104 into master Jun 17, 2021
@cmichi cmichi deleted the cmichi-misc-fixes branch June 17, 2021 12:46
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

Successfully merging this pull request may close these issues.

None yet

2 participants