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

Clarify platform reading API #2925

Merged
merged 10 commits into from
Oct 27, 2022
Merged

Conversation

tomaka
Copy link
Contributor

@tomaka tomaka commented Oct 24, 2022

At the moment, the read_buffer function of the Platform trait (representing how the light client binds to the environment) returns either Some in normal situations or None if the connection has been either closed or reset.

This PR turns this Option into an enum with three variants: Open, Closed, and Reset.
This lets the code properly differentiate between these two latter situations.

Additionally, I've renamed "closed" to "reset" in the entire Wasm<->JS code (all the functions and variables), for clarity. While the Platform trait lets you report that the reading side is closed but the writing side still open, the JS code can't represent that state. Instead, it's either "connection open" or "connection reset".

This PR fixes #2782. The issue was that we were treating read_buffer() returning None as meaning "reading side closed", but actually the entire connection was already reset. We would then call send on the already-reset connection, leading to the error. This kind of confusion is exactly why I've performed the rename.

Copy link
Contributor

@mergify mergify bot left a comment

Choose a reason for hiding this comment

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

Automatically approving tomaka's pull requests. This auto-approval will be removed once more maintainers are active.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 24, 2022

twiggy diff report

Difference in .wasm size before and after this pull request.


 Delta Bytes │ Item
─────────────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       -8588 ┊ <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::h0711ca0ba338a70d
       +8588 ┊ <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::h384a1c5c7acfe64d
       -3556 ┊ <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::hdd0fe18794daa58f
       +3553 ┊ <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::hd88c036a7cac2580
       +2612 ┊ <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::h5d3970607b95455c
       -2577 ┊ <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::hf2dded58c85b01ef
        +787 ┊ alloc::collections::btree::remove::<impl alloc::collections::btree::node::Handle<alloc::collections::btree::node::NodeRef<alloc::collections::btree::node::marker::Mut,K,V,alloc::collections::btree::node::marker::Leaf>,alloc::collections::btree::node::marker::KV>>::remove_leaf_kv::h16fa840a475d6707
        -787 ┊ alloc::collections::btree::remove::<impl alloc::collections::btree::node::Handle<alloc::collections::btree::node::NodeRef<alloc::collections::btree::node::marker::Mut,K,V,alloc::collections::btree::node::marker::Leaf>,alloc::collections::btree::node::marker::KV>>::remove_leaf_kv::h5be42361ece6d245
        +768 ┊ alloc::collections::btree::node::BalancingContext<K,V>::bulk_steal_right::h03acf36ea99d4452
        -768 ┊ alloc::collections::btree::node::BalancingContext<K,V>::bulk_steal_right::h783d7952d52251d7
        -727 ┊ alloc::collections::btree::node::BalancingContext<K,V>::bulk_steal_left::h25cb0910f5571522
        +727 ┊ alloc::collections::btree::node::BalancingContext<K,V>::bulk_steal_left::hcbc5e5470c24cb9b
        -679 ┊ alloc::collections::btree::fix::<impl alloc::collections::btree::node::NodeRef<alloc::collections::btree::node::marker::Mut,K,V,alloc::collections::btree::node::marker::LeafOrInternal>>::fix_node_through_parent::h4f241eb21db42704
        +679 ┊ alloc::collections::btree::fix::<impl alloc::collections::btree::node::NodeRef<alloc::collections::btree::node::marker::Mut,K,V,alloc::collections::btree::node::marker::LeafOrInternal>>::fix_node_through_parent::h902389da6c188376
        +603 ┊ alloc::collections::btree::node::Handle<alloc::collections::btree::node::NodeRef<alloc::collections::btree::node::marker::Mut,K,V,alloc::collections::btree::node::marker::Leaf>,alloc::collections::btree::node::marker::Edge>::insert_recursing::hb25621d28e7c54fc
        -603 ┊ alloc::collections::btree::node::Handle<alloc::collections::btree::node::NodeRef<alloc::collections::btree::node::marker::Mut,K,V,alloc::collections::btree::node::marker::Leaf>,alloc::collections::btree::node::marker::Edge>::insert_recursing::hc58f3055b6604b73
        -585 ┊ alloc::collections::btree::node::BalancingContext<K,V>::do_merge::h48bbf604b993b3a7
        +585 ┊ alloc::collections::btree::node::BalancingContext<K,V>::do_merge::h89a88adfe44feb1b
        -585 ┊ alloc::collections::btree::node::BalancingContext<K,V>::do_merge::h906c794f25d9ab0a
        +585 ┊ alloc::collections::btree::node::BalancingContext<K,V>::do_merge::h963d820094dd7cbc
        +318 ┊ ... and 188 more.
        +587 ┊ Σ [208 Total Rows]

bin/wasm-node/CHANGELOG.md Outdated Show resolved Hide resolved
@tomaka tomaka added the automerge Automatically merge pull request as soon as possible label Oct 27, 2022
@mergify mergify bot merged commit 3c407df into paritytech:main Oct 27, 2022
@tomaka tomaka deleted the clarify-platform-rw-apis branch October 27, 2022 10:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Automatically merge pull request as soon as possible
Projects
None yet
Development

Successfully merging this pull request may close these issues.

WebSocket is already in CLOSING or CLOSED state.
2 participants