Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 8 additions & 16 deletions src/subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with substrate-subxt. If not, see <http://www.gnu.org/licenses/>.

use jsonrpsee_types::error::Error as RpcError;
use jsonrpsee_ws_client::WsSubscription as Subscription;
use sp_core::{
storage::{
Expand Down Expand Up @@ -95,14 +94,8 @@ impl<'a, T: Runtime> EventSubscription<'a, T> {
if self.finished {
return None
}
let change_set = match self.subscription.next().await {
Some(c) => c,
None => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The proper action should be to indicate that the subscription is dropped and need to restarted because after it returns None it shouldn't be polled anymore because the channel has been terminated.

If you poll if after None it will panic

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Which is exactly why I would expect it to return None, to indicate the stream has closed (much like with StreamExt).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Alright, that makes sense to me but perhaps we should document it because it's not obvious to me ^^

return Some(Err(
RpcError::Custom("RPC subscription dropped".into()).into()
))
}
};
// always return None if subscription has closed
let change_set = self.subscription.next().await?;
if let Some(hash) = self.block.as_ref() {
if &change_set.block == hash {
self.finished = true;
Expand Down Expand Up @@ -184,13 +177,12 @@ impl<T: Runtime> FinalizedEventStorageSubscription<T> {
return Some(storage_change)
}
let header: T::Header = self.subscription.next().await?;
if let Ok(storage_changes) = self
.rpc
.query_storage_at(&[self.storage_key.clone()], Some(header.hash()))
.await
{
self.storage_changes.extend(storage_changes);
}
self.storage_changes.extend(
self.rpc
.query_storage_at(&[self.storage_key.clone()], Some(header.hash()))
.await
.ok()?,
);
}
}
}
Expand Down