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

near-sdk-sim calculates storage incorrectly #388

Closed
skyward-dev opened this issue Apr 29, 2021 · 4 comments · Fixed by #390
Closed

near-sdk-sim calculates storage incorrectly #388

skyward-dev opened this issue Apr 29, 2021 · 4 comments · Fixed by #390
Assignees

Comments

@skyward-dev
Copy link

For example, I'm trying to deploy wrap near contract with 10 NEAR. It works on the testnet, but doesn't work in the simulator tests.

let w_near = near.deploy_and_init(
            &W_NEAR_WASM_BYTES,
            WRAP_NEAR_ID.to_string(),
            "new",
            b"{}",
            to_yocto("10"),
            BASE_GAS,
        );

It looks like the simulator uses different storage per byte and fails with the following:

Outcome ExecutionOutcome {
    logs: [],
    receipt_ids: [
        `7qy1rGatQE1fCVd7V3neku5Hm9dvakY2LHiC8L3jERxh`,
        `5CBACqrLyeTEeVr3wB5dnyZ2LkYy2LAhospjfSMJjW9Z`,
    ],
    burnt_gas: 4673903491021,
    tokens_burnt: 467390349102100000000,
    status: Failure(Action #0: The account wrap.near wouldn't have enough balance to cover storage, required to have 6896582900000000000000000 yoctoNEAR more),
} was a failure
@evgenykuzyakov
Copy link
Contributor

Hmm. It looks like it uses old protocol version for some reason. Let me investigate.
cc @willemneal Have you seen it before?

@evgenykuzyakov evgenykuzyakov self-assigned this Apr 29, 2021
@willemneal
Copy link
Contributor

@evgenykuzyakov Yeah I think we need to republish the nearcore crates.

@evgenykuzyakov
Copy link
Contributor

I think the issue is the RuntimeStandalone doesn't upgrade the RuntimeConfig.
It's done in RuntimeConfig::getConfig(config, protocol_version) (or smth like that), which we don't call. We probably just need to call it at start and give default config.

evgenykuzyakov pushed a commit that referenced this issue May 3, 2021
* Expose `cur_block` and `genesis_config` from `RuntimeStandalone`. This allows to manipulate block time, e.g. set to a given timestamp.
* Use `RuntimeConfig::from_protocol_version` that fixes storage costs issue. Fixes: #388 
* Set root account balance to one billion tokens.

## Test plan:
- Modify FT test to verify storage cost fix by limiting initial deposit to 5 NEAR. It is not enough with old storage cost (50kb) and enough with new storage cost (500kb)

* make block time configurable to sim contract tests that depend on env::block_time

* Update near-sdk-sim/src/runtime.rs

Co-authored-by: Aleksey Kladov <[email protected]>

* use block_prod_time name to make it matches nearcore

* Expose cur_block. Fix storage cost

* Fix initial supply

* Modify FT test to verify storage cost fix

* Rework RuntimeConfig from genesis

Co-authored-by: Bo Yao <[email protected]>
Co-authored-by: Aleksey Kladov <[email protected]>
@evgenykuzyakov
Copy link
Contributor

Publishing [3.2.0] now. It should have correct storage cost per byte.

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 a pull request may close this issue.

3 participants