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

Storage Limit issues #23

Closed
forgetso opened this issue Jan 7, 2022 · 5 comments
Closed

Storage Limit issues #23

forgetso opened this issue Jan 7, 2022 · 5 comments

Comments

@forgetso
Copy link
Contributor

forgetso commented Jan 7, 2022

This node seems to not work with the recent changes surrounding storage limits.

When uploading contracts the following error is received:

contracts.StorageDepositLimitExhausted(More storage was created than allowed by the storage deposit limit.)

A normal substrate node started with cargo run --release -- --dev --tmp -lerror,runtime::contracts=debug works using the same configuration of polkadotjs and deploy script.

I have even upgraded the substrate contracts node to a recent substrate commit to see if that was the issue but it still fails on deployment.

https://github.com/prosopo-io/substrate-contracts-node/tree/storage_deposit_limit (Synced to paritytech/substrate@7409589)

I can create a PR for this if you like.

polkadot-js versions:

    "@polkadot/api": "7.2.1",
    "@polkadot/api-contract": "7.2.1",
    "@polkadot/types": "7.2.1",
    "@polkadot/keyring": "8.2.2",
    "@polkadot/util": "8.2.2",
    "@polkadot/wasm-crypto": "4.5.1",
    "@polkadot/util-crypto": "8.2.2",
@forgetso
Copy link
Contributor Author

forgetso commented Jan 10, 2022

The issue seems to be the inconsistent default values assigned to Alice in the substrate-contracts-node versus substrate.

  • In substrate the accounts are seeded with 1,000,000,000,000,000,000,000.
  • In substrate-contracts-node the accounts are seeded with 1,152,921,504,606,846,976 (1<<60).

Both scripts use the same deploy script which passes a value of 20000 UNIT to the contract.

The substrate deploy succeeds whereas the substrate-contracts-node fails with contracts.StorageDepositLimitExhausted.

It doesn't seem to make any difference as I increase the sent value. It always fails with the same error. The highest value I tried was 2000000000000000 UNIT

To reproduce, you can clone our smart contract repo and run the deploy script with substrate-contracts-node built with default values of 1,000,000,000,000,000,000,000 and 1,152,921,504,606,846,976.

git clone https://github.com/prosopo-io/protocol \
&& cd protocol \
&& yarn \
&& yarn build \
&& yarn redspot run scripts/deploy.ts

You can either use latest contracts node (1ab14fe) or clone the forked node which is updated to paritytech/substrate@7409589. The error appears on both.

git clone https://github.com/paritytech/substrate-contracts-node/ \
&& cd substrate-contracts-node \
&& cargo build --release

However, there is a caveat that we are using a slightly modified version of ink that allows for SpreadAllocate on enum. The contract will not build without this.

@athei
Copy link
Member

athei commented Jan 10, 2022

Does the error also happen with the unmodified substrate node (the man if you just use cargo run in the substrate repo)?

@forgetso
Copy link
Contributor Author

The error does not happen with the unmodified substrate repo. I've outlined what I've tested below.

Package Balance Result
substrate 1,000,000,000,000,000,000,000 succeeds
substrate 1<<60 ???
substrate contracts node 1<<60 fails
substrate contracts node 1,000,000,000,000,000,000,000 succeeds

Clearly this could be further narrowed down by checking substrate with the initial balances as 1<<60. I've not had time to check this out as currently trying to finish up work for a Web3 milestone.

@forgetso
Copy link
Contributor Author

forgetso commented Jan 10, 2022

I thought I'd solved this by using the substrate node but it seems I get the same error after running a few contract functions, eventually hitting the limit. I added some debug to substrate to see what's going on when storage deposit limit is specified as null in redspot / polkadotjs.

2022-01-10 21:05:18
Storage Deposit Limit 123576914103721

2022-01-10 21:05:18
Storage Amount Required 411000000000000

I'm not sure what the number 123576914103721 is. It doesn't appear to be the max of u64 or similar, and I don't know where it's being set. But it's lower than the required storage amount for my function (4.11e15), which is an issue.

If I manually set the storage_deposit_limit to anything larger than ~9e15 I get an error in polkadotjs, preventing me from setting a large enough limit.

Error: createType(Call):: Call: failed decoding balances.transfer:: Struct: failed on args: {"dest":"MultiAddress","value":"Compact<u128>"}:: Struct: failed on value: Compact<u128>:: Assertion failed

TLDR: it could be an issue with the API and not the substrate contracts node.

@forgetso
Copy link
Contributor Author

The confusion was caused by the differing initial balances for Alice etc. After this was taken into consideration, it turns out I can send a large enough initial deposit to my account by passing the number through BN, getting around the StorageDepositLimitExhausted.

e.g. send a large initial deposit to my testing account
new BN("100000000000000000") // it's important that a string is passed

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

No branches or pull requests

2 participants