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

Atomic swap #52

Merged
merged 36 commits into from
Aug 30, 2020
Merged

Atomic swap #52

merged 36 commits into from
Aug 30, 2020

Conversation

maurolacy
Copy link
Contributor

@maurolacy maurolacy commented Aug 23, 2020

Implementation of atomic swaps, for native tokens.

@maurolacy maurolacy requested a review from ethanfrey August 23, 2020 11:25
@maurolacy maurolacy marked this pull request as draft August 23, 2020 11:25
@maurolacy maurolacy self-assigned this Aug 23, 2020
@maurolacy
Copy link
Contributor Author

maurolacy commented Aug 23, 2020

Integration tests done. Except for query() integ tests, which are failing with:

thread 'test_query' panicked at 'VM error: CommunicationErr { source: InvalidRegion { source: LengthExceedsCapacity { length: 1931622946, capacity: 1919247470, backtrace: Backtrace(()) } } }', ...

The error is precisely when calling the query() VM wrapper. Will investigate more tomorrow; posting here in case you know something about it. Thanks.

Update: I'm assuming I'm doing something wrong, but cannot find the issue. Here's PoC code for the error: https://github.com/CosmWasm/cosmwasm-plus/tree/atomic-swap-integ_test_query

The error is only with the QueryMsg::List message type; the QueryMsg::Details message works fine.

I had to add the "iterator" feature to cosmwasm-vm, in order to use it. Maybe something related to that? I'll continue looking.

@maurolacy maurolacy marked this pull request as ready for review August 23, 2020 19:29
@ethanfrey
Copy link
Member

You have to add the iterator feature to both cosmwasm-vm and cosmwasm-storage, but I assume you did.

This seems to show you are trying to send an enormous buffer or one with negative size. Can you link to the exact line that returns this error? I will eyeball it and see if I see anything obvious before digging down. You should never be able to create such an error with the higher-level APIs you use

@maurolacy
Copy link
Contributor Author

maurolacy commented Aug 24, 2020

You have to add the iterator feature to both cosmwasm-vm and cosmwasm-storage, but I assume you did.

Yes.

This seems to show you are trying to send an enormous buffer or one with negative size. Can you link to the exact line that returns this error? I will eyeball it and see if I see anything obvious before digging down.

There's now PoC code in the atomic-swap-integ_test_query branch.

The last line of integ_test_query() produces the error.

To reproduce:

cargo wasm
cargo integration-test --tests integ_test_query

Thanks.

@ethanfrey
Copy link
Member

Interesting. Two points:

I don't see the equivalent test here: https://github.com/CosmWasm/cosmwasm-plus/blob/atomic-swap-integ_test_query/contracts/atomic-swap/src/contract.rs rather just a details query. Can you make a unit test on the ListQuery to see what it says? It will give you more detail info on any error.

Looking at this https://github.com/CosmWasm/cosmwasm-examples/blob/master/erc20/tests/integration.rs#L378 it seems you do the same thing (unless you want to just unwrap it there, but that is not a functional change).

@ethanfrey
Copy link
Member

Also, I have been removing integration tests in this repo, as I hadn't found a bug with them before (besides the cosmwasm contracts that were there to debug it). I would like to hunt down what happens here, but if we figure out why this is broken, I would generally, just focus on the unit tests and maybe remove all these.

Also, good to add your contract to .circleci/config so this is covered by CI (maybe after removing the integration tests that slow things down a lot)

@maurolacy
Copy link
Contributor Author

maurolacy commented Aug 24, 2020

Interesting. Two points:

I don't see the equivalent test here: https://github.com/CosmWasm/cosmwasm-plus/blob/atomic-swap-integ_test_query/contracts/atomic-swap/src/contract.rs rather just a details query. Can you make a unit test on the ListQuery to see what it says? It will give you more detail info on any error.

I converted it to a minimal test, just to show / pinpoint the issue. I have the full integ test for query, and I can commit it if you like, for example in the original branch (it will break the build, though). Anyway, the unit test for query() has a QueryMsg::List (see https://github.com/CosmWasm/cosmwasm-plus/blob/95ba038f4403c64c2a30bb81e11ca0aa4e31f541/contracts/atomic-swap/src/contract.rs#L577), and it works fine. What also works (as I've checked manually) is QueryMsg::Details. It's only QueryMsg::List that's broken in the VM.

Looking at this https://github.com/CosmWasm/cosmwasm-examples/blob/master/erc20/tests/integration.rs#L378 it seems you do the same thing (unless you want to just unwrap it there, but that is not a functional change).

If I add the unwrap()it's the same; this is just the minimal way to reproduce the problem. In fact, I've checked and the query() implementation (the one in contract.rs) is never called... there seem to be an issue with arguments parsing in the VM, as far as I can tell at this point.

@maurolacy
Copy link
Contributor Author

Also, I have been removing integration tests in this repo, as I hadn't found a bug with them before (besides the cosmwasm contracts that were there to debug it). I would like to hunt down what happens here, but if we figure out why this is broken, I would generally, just focus on the unit tests and maybe remove all these.

OK.

Also, good to add your contract to .circleci/config so this is covered by CI (maybe after removing the integration tests that slow things down a lot)

Will do.

@ethanfrey
Copy link
Member

Huh, I ran this code and played with unit tests and get the same issue.

The all_swap_ids code seems proper as well. Maybe we have some vm error iterating over an empty range. I should add a test for that to the cosmwasm.

Update: I did update the test to List a non-empty bucket and the same issue.

@ethanfrey
Copy link
Member

@maurolacy

I am off for a bit, but if you want to dig deeper, can you try to add an equivalent test to https://github.com/CosmWasm/cosmwasm/blob/master/contracts/queue/tests/integration.rs (which uses the iterator a bunch). You may just want to add a new query that works like you current List one here: https://github.com/CosmWasm/cosmwasm/blob/master/contracts/queue/src/contract.rs#L115-L124 and then test it with unit test and integration test.

If you get that to fail, then we are much closer to a fix - iterating in one repo. You can also import cosmwasm-storage for the same prefix store approach if it doesn't fail without it.

@maurolacy
Copy link
Contributor Author

Will do.

@maurolacy
Copy link
Contributor Author

OK, I've created unit and integration tests under the queue contract in cosmwasm, and the integration test fails.

The error is similar, but not exactly the same:

thread 'query_list' panicked at 'VM error: CommunicationErr { source: RegionLengthTooBig { length: 1663187490, max_length: 65536, backtrace: Backtrace(()) } }', ...

(Numbers are always the same).

I cannot push the branch as I don't have permission.

I'll create an issue to track this, and document stuff there.

@maurolacy
Copy link
Contributor Author

Created issue: CosmWasm/cosmwasm#508

@maurolacy
Copy link
Contributor Author

Pushing the query() integration test just for reference / completeness.

Will remove integrations tests later as agreed.

@ethanfrey
Copy link
Member

Thanks, I will review tomorrow... been super busy the last days - sorry.

Can you rebase on master since I did merge a lot recently?

@CLAassistant
Copy link

CLAassistant commented Aug 26, 2020

CLA assistant check
All committers have signed the CLA.

Copy link
Member

@ethanfrey ethanfrey left a comment

Choose a reason for hiding this comment

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

Thanks for building this out. I have also made some enhancements to the patterns in cosmwasm-plus the last week: pagination, new Expiration type, version calculation, etc. And make a lot of references to update to those newer specs. I think I only see one bug, and a few missing tests (and a few types that can be adjusted).

Please make the requested updates and this should be good to merge.

.circleci/config.yml Outdated Show resolved Hide resolved
Cargo.toml Outdated Show resolved Hide resolved
contracts/atomic-swap/Cargo.toml Outdated Show resolved Hide resolved
contracts/atomic-swap/examples/schema.rs Outdated Show resolved Hide resolved
contracts/atomic-swap/src/msg.rs Outdated Show resolved Hide resolved
contracts/atomic-swap/src/contract.rs Outdated Show resolved Hide resolved
contracts/atomic-swap/src/contract.rs Outdated Show resolved Hide resolved
contracts/atomic-swap/src/contract.rs Outdated Show resolved Hide resolved
contracts/atomic-swap/src/contract.rs Outdated Show resolved Hide resolved
contracts/atomic-swap/src/contract.rs Outdated Show resolved Hide resolved
Copy link
Member

@ethanfrey ethanfrey left a comment

Choose a reason for hiding this comment

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

Looks good. A few minor nitpics, I will merge this and you can address those in your next PR if you wish.

Also note #69 which you can gladly take on if you wish.

contracts/cw20-atomic-swap/README.md Show resolved Hide resolved
contracts/cw20-atomic-swap/examples/schema.rs Show resolved Hide resolved
contracts/cw20-atomic-swap/src/msg.rs Show resolved Hide resolved
contracts/cw20-atomic-swap/src/state.rs Show resolved Hide resolved
contracts/cw20-atomic-swap/src/state.rs Show resolved Hide resolved
contracts/cw20-atomic-swap/src/state.rs Show resolved Hide resolved
@ethanfrey ethanfrey merged commit 2ac4994 into master Aug 30, 2020
@ethanfrey ethanfrey deleted the atomic-swap branch August 30, 2020 18:05
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.

3 participants