use-ink / cargo-contract

Setup and deployment tool for developing Wasm based smart contracts via ink!
GNU General Public License v3.0
250 stars 120 forks source link

Cargo contract fails to deploy contract due to RPC error #945

Open forgetso opened 1 year ago

forgetso commented 1 year ago

Cargo contract version: cargo-contract-contract 2.0.0-rc-unknown-x86_64-unknown-linux-gnu

Substrate node: Version: 3.0.0-dev-1cc97dd3053

The contract was built with inkv4. From the toml:

[dependencies]
ink = { git = "https://github.com/paritytech/ink", rev="4655a8b4413cb50cbc38d1b7c173ad426ab06cde", default-features = false }

Dry run seems to work:

RUST_LOG=info cargo contract instantiate --args 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY 1000000000000 1000000000000 --constructor "default" --suri "//Alice" --value 20000000000000 --url "ws://localhost:9944"
 Dry-running default (skip with --skip-dry-run)
    Success! Gas required estimated at Weight(ref_time: 540831943, proof_size: 0)
Confirm transaction details: (skip with --skip-confirm)
 Constructor default
        Args 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY 1000000000000 1000000000000
   Gas limit Weight(ref_time: 540831943, proof_size: 0)
Submit? (Y/n): Y

I can see the error is something to do with ChargeAssetTxPayment. Could the issue be the proof size is set to 0?

Here is the stack from the substrate node:


   0: sp_panic_handler::set::{{closure}}
   1: <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call
             at /rustc/fc594f15669680fa70d255faec3ca3fb507c3405/library/alloc/src/boxed.rs:2032:9
      std::panicking::rust_panic_with_hook
             at /rustc/fc594f15669680fa70d255faec3ca3fb507c3405/library/std/src/panicking.rs:692:13
   2: std::panicking::begin_panic_handler::{{closure}}
             at /rustc/fc594f15669680fa70d255faec3ca3fb507c3405/library/std/src/panicking.rs:579:13
   3: std::sys_common::backtrace::__rust_end_short_backtrace
             at /rustc/fc594f15669680fa70d255faec3ca3fb507c3405/library/std/src/sys_common/backtrace.rs:137:18
   4: rust_begin_unwind
             at /rustc/fc594f15669680fa70d255faec3ca3fb507c3405/library/std/src/panicking.rs:575:5
   5: core::panicking::panic_fmt
             at /rustc/fc594f15669680fa70d255faec3ca3fb507c3405/library/core/src/panicking.rs:64:14
   6: kitchensink_runtime::api::dispatch
   7: <node_executor::ExecutorDispatch as sc_executor::native_executor::NativeExecutionDispatch>::dispatch
   8: std::thread::local::LocalKey<T>::with
   9: sc_executor::native_executor::WasmExecutor<H>::with_instance::{{closure}}
  10: sc_executor::wasm_runtime::RuntimeCache::with_instance
  11: <sc_executor::native_executor::NativeElseWasmExecutor<D> as sp_core::traits::CodeExecutor>::call
  12: sp_state_machine::execution::StateMachine<B,H,Exec>::execute_aux
  13: sp_state_machine::execution::StateMachine<B,H,Exec>::execute_using_consensus_failure_handler
  14: <sc_service::client::call_executor::LocalCallExecutor<Block,B,E> as sc_client_api::call_executor::CallExecutor<Block>>::contextual_call
  15: <sc_service::client::client::Client<B,E,Block,RA> as sp_api::CallApiAt<Block>>::call_api_at
  16: <kitchensink_runtime::RuntimeApiImpl<__SR_API_BLOCK__,RuntimeApiImplCall> as sp_offchain::OffchainWorkerApi<__SR_API_BLOCK__>>::__runtime_api_internal_call_api_at
  17: sp_transaction_pool::runtime_api::TaggedTransactionQueue::validate_transaction
  18: tracing::span::Span::in_scope
  19: sc_transaction_pool::api::validate_transaction_blocking
  20: <sc_transaction_pool::api::FullChainApi<Client,Block> as sc_transaction_pool::graph::pool::ChainApi>::validate_transaction::{{closure}}::{{closure}}
  21: sc_transaction_pool::api::spawn_validation_pool_task::{{closure}}
  22: <futures_util::future::future::map::Map<Fut,F> as core::future::future::Future>::poll
  23: <sc_service::task_manager::prometheus_future::PrometheusFuture<T> as core::future::future::Future>::poll
  24: <futures_util::future::select::Select<A,B> as core::future::future::Future>::poll
  25: <tracing_futures::Instrumented<T> as core::future::future::Future>::poll
  26: tokio::runtime::park::CachedParkThread::block_on
  27: tokio::runtime::handle::Handle::block_on
  28: <tokio::runtime::blocking::task::BlockingTask<T> as core::future::future::Future>::poll
  29: tokio::runtime::task::core::Core<T,S>::poll
  30: tokio::runtime::task::harness::Harness<T,S>::poll
  31: tokio::runtime::blocking::pool::Inner::run
  32: std::sys_common::backtrace::__rust_begin_short_backtrace
  33: core::ops::function::FnOnce::call_once{{vtable.shim}}
  34: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
             at /rustc/fc594f15669680fa70d255faec3ca3fb507c3405/library/alloc/src/boxed.rs:2000:9
      <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
             at /rustc/fc594f15669680fa70d255faec3ca3fb507c3405/library/alloc/src/boxed.rs:2000:9
      std::sys::unix::thread::Thread::new::thread_start
             at /rustc/fc594f15669680fa70d255faec3ca3fb507c3405/library/std/src/sys/unix/thread.rs:108:17
  35: start_thread
             at /build/glibc-SzIz7B/glibc-2.31/nptl/pthread_create.c:477:8
  36: clone
             at /build/glibc-SzIz7B/glibc-2.31/misc/../sysdeps/unix/sysv/linux/x86_64/clone.S:95

Thread 'tokio-runtime-worker' panicked at 'Bad input data provided to validate_transaction: Could not decode `ChargeAssetTxPayment::asset_id`:
unexpected first byte decoding Option
', bin/node/runtime/src/lib.rs:1819

This is a bug. Please report it at:

    https://github.com/paritytech/substrate/issues/new
SkymanOne commented 1 year ago

Are you using substrate-contracts-node? If so, what version is it. We also released ink! 4 release candidate which you should use now.

forgetso commented 1 year ago

I can successfully deploy with substrate contracts node.

This deploy failure relates to building the following substrate version:

commit 1cc97dd30537997ff4c9827beb2ef0cac9c49063 (HEAD -> polkadot-v0.9.34, upstream/polkadot-v0.9.34)
➜  substrate git:(polkadot-v0.9.34) ✗ ./target/release/substrate --version
substrate 3.0.0-dev-1cc97dd3053

I'd like to test against this as well because substrate contracts node is in instant seal mode and its useful to test against 6s block times as well.

Thanks for the hint about inkv4 release candidate.

HCastano commented 1 year ago

@forgetso any updates here?

forgetso commented 1 year ago

Hi @HCastano, building the contract with the latest ink release candidate makes no difference when deploying. The same error message appears.

This time I was using the latest cargo contract release candidate built and installed locally.

cargo contract --version
cargo-contract-contract 2.0.0-rc.1-0a98d16-x86_64-unknown-linux-gnu

Substrate version is unchanged.

HCastano commented 1 year ago

@forgetso can you update your Substrate node to the polkadot-v0.9.37 branch and try again? Also, ink! 4.0 and cargo-contract 2.0 are out, so you should update to those as well.

If that doesn't help can you share the contract you're trying to deploy so we can try and reproduce it on our end?

forgetso commented 1 year ago

Hi, I upgraded cargo contract to version 2 using

cargo install cargo-contract --version 2.0.0
cargo contract --version
cargo-contract-contract 2.0.0-unknown-x86_64-unknown-linux-gnu

I upgraded substrate to branch polkadot-v0.9.37

./target/release/substrate  --version           
substrate 3.0.0-dev-f38bd6671d4

The contract builds with cargo contract but deploying still fails when deploying to the substrate node. Dry run succeeds.

RUST_LOG=info cargo contract instantiate --args 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY 1000000000000 1000000000000 --constructor "default" --suri "//Alice" --value 20000000000000 --url "ws://localhost:9944" 

 Dry-running default (skip with --skip-dry-run)
    Success! Gas required estimated at Weight(ref_time: 512696930, proof_size: 0)
Confirm transaction details: (skip with --skip-confirm)
 Constructor default
        Args 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY 1000000000000 1000000000000
   Gas limit Weight(ref_time: 512696930, proof_size: 0)
Submit? (Y/n): Y
ERROR: Rpc error: RPC error: RPC call failed: ErrorObject { code: ServerError(1002), message: "Verification Error: Runtime error: Execution failed: Runtime panicked: Bad input data provided to validate_transaction: Could not decode `ChargeAssetTxPayment::asset_id`:\n\tunexpected first byte decoding Option\n", data: Some(RawValue("RuntimeApi(\"Execution failed: Runtime panicked: Bad input data provided to validate_transaction: Could not decode `ChargeAssetTxPayment::asset_id`:\\n\\tunexpected first byte decoding Option\\n\")")) }

The contract is here. Use the linked branch.

forgetso commented 1 year ago

Can confirm this issue still exists with polkadot-v0.9.39 branch.

(base) ➜  substrate git:(polkadot-v0.9.39) ✗ ./target/release/substrate  --version                  
substrate 3.0.0-dev-1837f423b49

The contract does deploy with polkadot apps.

ascjones commented 1 year ago

This looks to be an instance of https://github.com/paritytech/cargo-contract/issues/524.

So it works for substrate-contracts-node because it uses PlainTip, but not for the substrate node-runtime