paritytech / subxt

Interact with Substrate based nodes in Rust or WebAssembly
Other
390 stars 236 forks source link

Ensures poll order wrt subscription ID's #1620

Open pkhry opened 1 month ago

pkhry commented 1 month ago

Description

Under current implementation unstable backend will be re-trying to make a call with a fixed amount of attempts instead of backing off on backend reconnection and waiting for newly initialized subscription_id.(see #1567 and comments in the mr referenced there)

The implementation here is adding a .reconnected() method for the backend and a new wrapper function that will poll _.reconnected() and action_being_retried.

So with this new wrapper flowchart will go like this in a loop:

reconnected.next() = None, action = Pending => {
  cancel action;
  return Error(Subscription_droppped)
}
reconnected.next() = Some(true), action = Pending => {
  // Subscription received FollowEvent::Initialized
  loop again to retry the action
}
reconnected.next() = Some(false), action = Pending => {
  // Subscription received FollowEvent::Stop
  loop { 
    reconnected.next() until it returns Some(true)
  }  
  loop again to retry the action
}
reconnected.next() = Pending, action = Ready(result) => {
  try polling the pending `reconnected.next()` and if it is None {
   return result from the action
  } else {
    loop { 
       reconnected.next() until it returns Some(true)
    }
    loop again to retry the action
  }
}

Not sure whether we need to track FollowEvent::Initialized() in reconnected() as code that grabs subscription_id will wait for the new subscription id after being re-run again

closes #1567