JoshOrndorff / recipes

A Hands-On Cookbook for Aspiring Blockchain Chefs
GNU General Public License v3.0
378 stars 187 forks source link

Charity can't donate 499 femto at first #308

Closed manxiaqu closed 4 years ago

manxiaqu commented 4 years ago

I know that to make the pallet account works, it must have minimum_balance currency which in my point is ensured by add_extra_genesis in

decl_storage! {
    trait Store for Module<T: Trait> as SimpleTreasury {
        // No storage items of our own, but we still need decl_storage to initialize the pot
    }
    add_extra_genesis {
        build(|_config| {
            // Create the charity's pot of funds, and ensure it has the minimum required deposit
            let _ = T::Currency::make_free_balance_be(
                &<Module<T>>::account_id(),
                T::Currency::minimum_balance(),
            );
        });
    }
}

when I call donate method to donate 499 femto, it fails of transfer currency. But when I donate 500 femto, it success. I think it's affected by pub const ExistentialDeposit: u128 = 500;. But if add_extra_genesis works, the pallet account should have minimum_balance before I send the donate transaction. I am not sure this is the correct behavior or not? If it is, then why should it fail? Am I miss something.

danforbes commented 4 years ago

Is this in reference to a particular recipe, @manxiaqu?

manxiaqu commented 4 years ago

Have facing the above problem in 2.0.0-alpha.6, haven't tested it in other release versions. I am using the polkadot.js explorer as the ui to send transactions.

I will test it in rc3 to check this exist or not.

manxiaqu commented 4 years ago

The problem seems also in rc3.0.

Besides, The test passed in my own branch that I implement a new pallet in super-runtime and didn't do anything to the charity pallet. Also I have run purge-chain to clean blockchain cache and then make the transaction donate 1 femto, and It passed. didn't know why. So I check out to the original Release RC3 (#294), 36d9410d970b8dc42a970f27c64aa4be5710b8a2, make the same step before and problem happens. It's weird! env:

ubuntu 16.04
kitchen-node 2.0.0-rc3-36d9410-x86_64-linux-gnu

console log:

ubuntu@ubuntu-XPS-13-9360:~/git/recipes$ ./target/release/kitchen-node purge-chain --dev
Are you sure to remove "/home/ubuntu/.local/share/kitchen-node/chains/dev/db"? [y/N]: y
"/home/ubuntu/.local/share/kitchen-node/chains/dev/db" removed.
ubuntu@ubuntu-XPS-13-9360:~/git/recipes$ ./target/release/kitchen-node --dev -lruntime=debug
2020-07-10 10:48:09.191 main WARN sc_cli::commands::run_cmd  Running in --dev mode, RPC CORS has been disabled.
2020-07-10 10:48:09.191 main INFO sc_cli::runner  Kitchen Node
2020-07-10 10:48:09.191 main INFO sc_cli::runner  ✌️  version 2.0.0-rc3-36d9410-x86_64-linux-gnu
2020-07-10 10:48:09.191 main INFO sc_cli::runner  ❤️  by Joshy Orndorff:4meta5:Jimmy Chu, 2019-2020
2020-07-10 10:48:09.191 main INFO sc_cli::runner  📋 Chain specification: Development
2020-07-10 10:48:09.191 main INFO sc_cli::runner  🏷  Node name: cut-way-5922
2020-07-10 10:48:09.191 main INFO sc_cli::runner  👤 Role: AUTHORITY
2020-07-10 10:48:09.191 main INFO sc_cli::runner  💾 Database: RocksDb at /home/ubuntu/.local/share/kitchen-node/chains/dev/db
2020-07-10 10:48:09.191 main INFO sc_cli::runner  ⛓  Native runtime: super-runtime-1 (super-runtime-1.tx1.au1)
2020-07-10 10:48:09.435 main INFO sc_service::client::client  🔨 Initializing Genesis block/state (state: 0x42ec…e593, header-hash: 0x7b63…3b6a)
2020-07-10 10:48:09.461 main INFO sc_service::builder  📦 Highest known block at #0
2020-07-10 10:48:09.461 main WARN sc_service::builder  Using default protocol ID "sup" because none is configured in the chain specs
2020-07-10 10:48:09.461 main INFO sub-libp2p  🏷  Local node identity is: 12D3KooWRYSL9YDSty3yq9rXpNoKH7mCaeGuwv9Lhw74goCxuvJi (legacy representation: QmXX7sa2U8LpLvcbWX2HdA9UcURTpTvJEjuAxdeq8N1nmT)
2020-07-10 10:48:09.463 tokio-runtime-worker INFO substrate_prometheus_endpoint::known_os  〽️ Prometheus server started at 127.0.0.1:9615
2020-07-10 10:48:14.465 tokio-runtime-worker INFO substrate  💤 Idle (0 peers), best: #0 (0x7b63…3b6a), finalized #0 (0x7b63…3b6a), ⬇ 0 ⬆ 0
2020-07-10 10:48:19.468 tokio-runtime-worker INFO substrate  💤 Idle (0 peers), best: #0 (0x7b63…3b6a), finalized #0 (0x7b63…3b6a), ⬇ 0 ⬆ 0
2020-07-10 10:48:24.466 tokio-runtime-worker INFO substrate  💤 Idle (0 peers), best: #0 (0x7b63…3b6a), finalized #0 (0x7b63…3b6a), ⬇ 0 ⬆ 0
2020-07-10 10:48:29.466 tokio-runtime-worker INFO substrate  💤 Idle (0 peers), best: #0 (0x7b63…3b6a), finalized #0 (0x7b63…3b6a), ⬇ 0 ⬆ 0
2020-07-10 10:48:34.466 tokio-runtime-worker INFO substrate  💤 Idle (0 peers), best: #0 (0x7b63…3b6a), finalized #0 (0x7b63…3b6a), ⬇ 0 ⬆ 0
2020-07-10 10:48:34.825 tokio-runtime-worker INFO sc_basic_authorship::basic_authorship  🙌 Starting consensus session on top of parent 0x7b6331866d25f63e6edb9b8ec4b28bab3b92300e47b8a86d4d8e1b2544a43b6a
2020-07-10 10:48:34.835 tokio-blocking-driver DEBUG runtime  DispatchError
2020-07-10 10:48:34.835 tokio-blocking-driver DEBUG runtime  Can't make donation
2020-07-10 10:48:34.835 tokio-blocking-driver DEBUG runtime  PostInfo: 
2020-07-10 10:48:34.835 tokio-blocking-driver DEBUG runtime  actual_weight=
2020-07-10 10:48:34.835 tokio-blocking-driver DEBUG runtime  max-weight
2020-07-10 10:48:34.838 tokio-blocking-driver INFO sc_basic_authorship::basic_authorship  🎁 Prepared block for proposing at 1 [hash: 0x362fd4746cd5ff48834eccbfec2ab68a77e9d9bbea4be142964d733f1952274c; parent_hash: 0x7b63…3b6a; extrinsics (2): [0x598e…c4db, 0x580c…e9d6]]
2020-07-10 10:48:34.841 tokio-runtime-worker DEBUG runtime  DispatchError
2020-07-10 10:48:34.841 tokio-runtime-worker DEBUG runtime  Can't make donation
2020-07-10 10:48:34.841 tokio-runtime-worker DEBUG runtime  PostInfo: 
2020-07-10 10:48:34.841 tokio-runtime-worker DEBUG runtime  actual_weight=
2020-07-10 10:48:34.841 tokio-runtime-worker DEBUG runtime  max-weight

@danforbes

danforbes commented 4 years ago

Hi, @manxiaqu - I apologize for my confusion (I am not the primary maintainer of this project), but I'm still not quite sure what you're doing when you encounter these errors :persevere: Is there a particular Recipe you are working through or a particular use case you are trying to achieve. This is always a good resource: How do I ask a good question? [Stack Overflow]

manxiaqu commented 4 years ago

@danforbes Sorry for the fuzzy description. I try to reorganize it as belows:

System information

recipes version: 2.0.0-rc3 rust version: nightly-x86_64-unknown-linux-gnu (default) rustc 1.45.0-nightly (a74d1862d 2020-05-14) OS & Version: ubuntu 16.04 Commit hash : 36d9410d970b8dc42a970f27c64aa4be5710b8a2

What I do

Start the kitchen-node and use polkadot ui to send standard donate extrinsic to blockchain.

image

Expected behaviour

The donate extrinsic should success.

Actual behaviour

It failed.

image

Steps to reproduce the behaviour

  1. clone the recipes
  2. checkout to 36d9410d970b8dc42a970f27c64aa4be5710b8a2
  3. compile the kitchen-node
  4. using https://polkadot.js.org/apps/#/extrinsics connect to local node.
  5. send 499 femto using donate method of charity pallet

Backtrace

2020-07-13 10:57:51.833 main WARN sc_cli::commands::run_cmd  Running in --dev mode, RPC CORS has been disabled.
2020-07-13 10:57:51.833 main INFO sc_cli::runner  Kitchen Node
2020-07-13 10:57:51.833 main INFO sc_cli::runner  ✌️  version 2.0.0-rc3-36d9410-x86_64-linux-gnu
2020-07-13 10:57:51.833 main INFO sc_cli::runner  ❤️  by Joshy Orndorff:4meta5:Jimmy Chu, 2019-2020
2020-07-13 10:57:51.833 main INFO sc_cli::runner  📋 Chain specification: Development
2020-07-13 10:57:51.833 main INFO sc_cli::runner  🏷  Node name: lowly-belief-5043
2020-07-13 10:57:51.833 main INFO sc_cli::runner  👤 Role: AUTHORITY
2020-07-13 10:57:51.833 main INFO sc_cli::runner  💾 Database: RocksDb at /home/ubuntu/.local/share/kitchen-node/chains/dev/db
2020-07-13 10:57:51.833 main INFO sc_cli::runner  ⛓  Native runtime: super-runtime-1 (super-runtime-1.tx1.au1)
2020-07-13 10:57:52.194 main INFO sc_service::client::client  🔨 Initializing Genesis block/state (state: 0x42ec…e593, header-hash: 0x7b63…3b6a)
2020-07-13 10:57:52.251 main INFO sc_service::builder  📦 Highest known block at #0
2020-07-13 10:57:52.252 main WARN sc_service::builder  Using default protocol ID "sup" because none is configured in the chain specs
2020-07-13 10:57:52.252 main INFO sub-libp2p  🏷  Local node identity is: 12D3KooWRYSL9YDSty3yq9rXpNoKH7mCaeGuwv9Lhw74goCxuvJi (legacy representation: QmXX7sa2U8LpLvcbWX2HdA9UcURTpTvJEjuAxdeq8N1nmT)
2020-07-13 10:57:52.273 tokio-runtime-worker INFO substrate_prometheus_endpoint::known_os  〽 Prometheus server started at 127.0.0.1:9615
2020-07-13 10:57:57.274 tokio-runtime-worker INFO substrate  💤 Idle (0 peers), best: #0 (0x7b63…3b6a), finalized #0 (0x7b63…3b6a), ⬇ 0 ⬆ 0
2020-07-13 10:58:02.274 tokio-runtime-worker INFO substrate  💤 Idle (0 peers), best: #0 (0x7b63…3b6a), finalized #0 (0x7b63…3b6a), ⬇ 0 ⬆ 0
2020-07-13 10:58:06.102 tokio-runtime-worker INFO sc_basic_authorship::basic_authorship  🙌 Starting consensus session on top of parent 0x7b6331866d25f63e6edb9b8ec4b28bab3b92300e47b8a86d4d8e1b2544a43b6a
2020-07-13 10:58:06.117 tokio-blocking-driver DEBUG runtime  DispatchError
2020-07-13 10:58:06.117 tokio-blocking-driver DEBUG runtime  Can't make donation
2020-07-13 10:58:06.117 tokio-blocking-driver DEBUG runtime  PostInfo: 
2020-07-13 10:58:06.117 tokio-blocking-driver DEBUG runtime  actual_weight=
2020-07-13 10:58:06.117 tokio-blocking-driver DEBUG runtime  max-weight

As the log says, the donate extrinsic failed of Can't make donation . I don't know the reason why it fails. Here's something I thought:

To make a account stored by blockchain, it should have minimum_balance, So if one try to send amount of currency below 500 to a new account, It will always fails.

And the kitchen-node ExistentialDeposit is set to 500(https://github.com/substrate-developer-hub/recipes/blob/master/runtimes/super-runtime/src/lib.rs#L193), the minimum_balance of currency should be 500 femto. So when I try to donate currency below 500 It will always fail. Also when I try to donate 500 femto, It does success. All subsequent donate extrinsics after the first 500 donate extrinsic will always success whatever amount(below 500) of currency I donate.

But, what confuse me is the charity pallet's account should have the minimum required deposit by code: https://github.com/substrate-developer-hub/recipes/blob/master/pallets/charity/src/lib.rs#L44. and thus make the donate extrinsic blow 500 success.

wheresaddie commented 4 years ago

can you clarify if you are trying to work on a recipe/tutorial or what is the outcome you are trying to achieve and myself or @danforbes will see if we can help you achieve or debug this? I understand you want the donate extrinsic blow 500 to succeeded and are getting an error- is that the final outcome you are wanting, for it to compile?

manxiaqu commented 4 years ago

I just follow the tutorial on https://substrate.dev/recipes/3-entrees/charity.html (no amount limit of currency in it) and encounter the error. I am not trying to achieve some goals or make donate extrinsic blow 500 success. What I want is the reason why the extrinsic failed(in my point, it should success).

wheresaddie commented 4 years ago

got it- thanks for the clarification-- let me defer to @jimmychu0807 and @danforbes

jimmychu0807 commented 4 years ago

Hi @manxiaqu Thanks for raising this issue. After some investigation, I realize the charity pot actually start with a balance of 0 instead of the minimum_balance as set in the add_extra_genesis section. This is tracked as an issue #309.

We will look into this and release a fix soon.

manxiaqu commented 4 years ago

Got it, Thank you for your reply.

danforbes commented 4 years ago

Amazing! Thank you so much, everyone :pray: