-
Notifications
You must be signed in to change notification settings - Fork 667
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
rpc v2: backpressure chainhead_v1_follow
#6058
base: master
Are you sure you want to change the base?
Conversation
chainhead_follow_v1
chainhead_v1_follow
bot fmt |
@pkhry https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7571594 was started for your command Comment |
@pkhry Command |
substrate/client/rpc-spec-v2/src/chain_head/chain_head_follow.rs
Outdated
Show resolved
Hide resolved
substrate/client/rpc-spec-v2/src/chain_head/chain_head_follow.rs
Outdated
Show resolved
Hide resolved
substrate/client/rpc-spec-v2/src/chain_head/chain_head_follow.rs
Outdated
Show resolved
Hide resolved
substrate/client/rpc-spec-v2/src/chain_head/chain_head_follow.rs
Outdated
Show resolved
Hide resolved
substrate/client/rpc-spec-v2/src/chain_head/chain_head_follow.rs
Outdated
Show resolved
Hide resolved
substrate/client/rpc-spec-v2/src/chain_head/chain_head_follow.rs
Outdated
Show resolved
Hide resolved
where | ||
S: Stream<Item = T> + Unpin + Send + 'static, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok nice catch :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC, this was causing the lifetime issue Pavlo mentioned before, nice catch indeed :D
substrate/client/rpc-spec-v2/src/chain_head/chain_head_follow.rs
Outdated
Show resolved
Hide resolved
substrate/client/rpc-spec-v2/src/chain_head/chain_head_follow.rs
Outdated
Show resolved
Hide resolved
substrate/client/rpc-spec-v2/src/chain_head/chain_head_follow.rs
Outdated
Show resolved
Hide resolved
substrate/client/rpc-spec-v2/src/chain_head/chain_head_follow.rs
Outdated
Show resolved
Hide resolved
substrate/client/rpc-spec-v2/src/chain_head/chain_head_follow.rs
Outdated
Show resolved
Hide resolved
@@ -53,6 +53,10 @@ use std::{ | |||
/// `Initialized` event. | |||
const MAX_FINALIZED_BLOCKS: usize = 16; | |||
|
|||
/// Maximum amount of events buffered by submit_events | |||
/// before dropping the stream. | |||
const MAX_BUFFERED_EVENTS: usize = 4; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set to 512
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
512 sounds good to me
events.push(event); | ||
} | ||
|
||
assert_eq!(events.len(), 64); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dq: i'm not that familiar with testing libs but why subscription falls out at 63 instead of 511 here?
the error from overflowing buffer still happens tho
cc: @niklasad1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2024-10-15T15:07:45.783080Z TRACE jsonrpsee-server: [Methods::subscribe] Method: chainHead_v1_follow, params: Some(RawValue([false]))
2024-10-15T15:07:45.783324Z DEBUG rpc-spec-v2: [follow][id="8999421366389847"] Subscription accepted
2024-10-15T15:07:45.783524Z INFO sc_rpc::utils: Starting subscription=chainHead_v1_followEvent
2024-10-15T15:07:45.783642Z TRACE jsonrpsee-server: [Methods::inner_call] Method: chainHead_v1_follow, response: {"jsonrpc":"2.0","id":0,"result":8999421366389847}
2024-10-15T15:07:47.380636Z DEBUG jsonrpsee-server: [Subscription::next]: rx {"jsonrpc":"2.0","method":"chainHead_v1_followEvent","params":{"subscription":8999421366389847,"result":{"event":"initialized","finalizedBlockHashes":["0xb4b48648e4869cffd7333c79458c3db011b9d6556af2a53eb5a186763837a73c"]}}}
2024-10-15T15:07:47.382317Z DEBUG rpc-spec-v2: [follow][id="8999421366389847"] Failed to handle stream notification ExceededLimits
2024-10-15T15:07:47.382353Z DEBUG rpc-spec-v2: [follow][id="8999421366389847"] Failed to handle stream notification SubscriptionAbsent
2024-10-15T15:07:47.383164Z DEBUG rpc-spec-v2: [follow][id="8999421366389847"] Subscription removed
It looks like you are hitting max block pinning limits
when you import so many blocks.
Thus, it may be better to just add subscription buffer cap
to the ChainHeadConfig to make it easy to change for tests etc and it's a bit extreme to import 512 blocks for a unit test.
substrate/client/rpc-spec-v2/src/chain_head/chain_head_follow.rs
Outdated
Show resolved
Hide resolved
substrate/client/rpc-spec-v2/src/chain_head/chain_head_follow.rs
Outdated
Show resolved
Hide resolved
let _ = sink.send(&FollowEvent::<String>::Stop).await; | ||
// No need to propagate this error further, the client disconnected. | ||
return Ok(()) | ||
let stream = stream |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit tempting to add something similar to pipe_from_stream
that takes a TryStream i.,e that produces Result<T, Error>
and bails on the first error similar to how try_for_each
works to avoid having this channel to be injected here just to get back the error and then quit....
Nothing that needs to be addressed in this PR but would be neat :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added to the pr
substrate/client/rpc-spec-v2/src/chain_head/chain_head_follow.rs
Outdated
Show resolved
Hide resolved
substrate/client/rpc-spec-v2/src/chain_head/chain_head_follow.rs
Outdated
Show resolved
Hide resolved
substrate/client/rpc-spec-v2/src/chain_head/chain_head_follow.rs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks for handling this @pkhry 🙏
substrate/client/rpc-spec-v2/src/chain_head/chain_head_follow.rs
Outdated
Show resolved
Hide resolved
substrate/client/rpc-spec-v2/src/chain_head/chain_head_follow.rs
Outdated
Show resolved
Hide resolved
Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com> Co-authored-by: Alexandru Vasile <60601340+lexnv@users.noreply.github.com>
Description
closes #5871
This PR changes the outgoing stream to abort and send a
Stop
event downstream in the case that client doesn't keep up with the producer.Integration
In depth notes about how this PR should be integrated by downstream projects. This part is mandatory, and should be
reviewed by reviewers, if the PR does NOT have the
R0-Silent
label. In case of aR0-Silent
, it can be ignored.Review Notes
rpc::Subscription::pipe_from_stream
- now takesSelf
param by reference, change was made to allow sending events to theSubscription
after calls topipe_from_stream
.chainhead_follow::submit_events
- now usesAbortable
stream to end it early in case