Made block streaming interruptible #705
Made block streaming interruptible #705
Conversation
… when necessary. But it's not used for now. Required for later rollback processing.
@@ -30,7 +36,7 @@ pub trait Api { | |||
got_block: &mut F, | |||
) -> Result<()> | |||
where | |||
F: FnMut(&HeaderHash, &Block, &RawBlock) -> (); | |||
F: FnMut(&HeaderHash, &Block, &RawBlock) -> BlockReceivingFlag; |
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.
This one will break any other trait users (not sure if there are any). The only alternative, I guess, is to add an alternative get_blocks
function with a default implementation. Do we want that?
In grpc, we have an API producing futures-0.1 streams for incoming blocks. Interrupting there is the matter of dropping the stream. But this is the old |
@mzabaluev, yes, it seems that way, cuz the protocol used from the Bridge only accepts a callback function that gets called with every new block and only previously returned |
But also requires changes, because right at the moment any result of the callback lambda is just ignored somewhere in between a caller and the protocol: https://github.com/input-output-hk/rust-cardano/pull/705/files#diff-009abb88e20c2ce711e56e1a1bbd482dL220 |
@vincenthz @NicolasDP @mzabaluev, is it ok, or should we switch to using |
|
@vantuz-subhuman Did you decide that you don't want it? |
@mzabaluev, sorry for a delayed response (vacation 🙂). We are currently working on reworking the interruption logic in our code, to use |
@mzabaluev, so far we have only one major problem with switching to use errors - this function call: https://github.com/input-output-hk/rust-cardano/blob/68d8d586f0247b89c91b9cfc98b828d8f59274ad/exe-common/src/network/native.rs#L214-L223
The problem is that One possible solution is to make higher level lambda from |
A brief look suggests that a closure that is passed to
|
@mzabaluev, that's the problem, that A diagram of scope here looks like this:
Logically So if internal function call returns higher level Calling lover level The only possible solutions I see is to either narrow potential error type for |
Kinda like:
|
Underlying Something like:
This prolly can be done with a custom type, like:
@mzabaluev, is this what you meant by a special purpose error type? 🤔
|
Other option could be to just reopen this PR that uses returning an enum with two options, tho 😁 |
@vantuz-subhuman Is it not practical to extend |
Yeah, that makes sense to me, that's why I initially proposed that If that's ok to you - I will do it like this. |
So it could be e.g. #[derive(Debug)]
struct StopHammerTime;
fn stream_blocks<F> ( got_blocks: &mut F ) -> Result<(), protocol::Error>
where F: FnMut(RawBlock) -> Result<(), StopHammerTime> |
It seems that I have confused your response:
To mean that |
Oh BTW, the closure does not need to be passed under a mutable reference. The mutable data capture is already baked into the generic parameter. This would do: fn stream_blocks<F> (got_blocks: F) -> Result<(), protocol::Error>
where F: FnMut(RawBlock) -> Result<(), StopHammerTime> (also remember to |
Yeah, makes sense to me. Also realised that making callback to return My bad. I'm going with something like this, declared in the Api module: Thank you for the support! 🙌 |
Added internal functionality that allows to interrupt block-streaming when necessary. But it's not used for now. Required for later rollback processing.
Part of #693 (comment)