Conversation
34f85e9
to
b53e0e1
Compare
9930605
to
6f011d8
Compare
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.
Really nice work @rishflab & @tcharding ! :)
50% review done!
One challenging question though:
What happens if Alice announces two swaps with the same digest at the same time to Bob? How is she going to tell the responses apart if the event only contains the digest?
I see three possible ways of going about this:
-
We ignore it, making it ambiguous for Alice, which of the announced swaps has which SwapId.
This could actually be feasible because if the swaps have the same digest, they are literally the same and it shouldn't matter if Bob is prepared for both or just one. There should be no problems downstream. -
We return a unique "token" (struct with a random/monotonically-increasing u32 inside) from the
start_announce_protocol
function that we will carry along internally and also emit in theConfirmationReceived
event. That will allow the caller (Alice) to match, which of the calls she made was actually successful and which one failed. -
We force the caller to pass some context information into the function and emit that one back in the event. Basically the same as (2) but we just don't have control over the data.
- (1) sounds like a shortcut but it may actually be feasible.
- (2) is the most "isolated" solution and does not assume anything about the rest of the program
- (3) could be interesting because we are already going to have an identifier for this: the "local" swap id we use to index the created swap data in the database.
I think we could go for all 3 solutions (or are there even more?).
Opinions @rishflab @tcharding ?
} | ||
|
||
fn inject_connected(&mut self, _peer_id: PeerId, _endpoint: ConnectedPoint) { | ||
// No need to do anything, both this node and connected peer now have a |
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.
We will need to keep track of our connections here same as we do in our current NetworkBehaviour (called ComitNode
I think).
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.
creating a follow up pr
}, | ||
} | ||
|
||
impl NetworkBehaviourEventProcess<BehaviourEvent> for Announce { |
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.
We shouldn't need this at this level.
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.
Will we need this trait implemented to combine this announce protocol with the other protocols? We weren't completely sure what this trait does it the chat example had it implemented. They were using it to print events so it was difficult to infer what its actual purpose was.
if !self.dial_queue.is_empty() { | ||
let upgrade = self.dial_queue.remove(0).unwrap(); // Cannot fail, queue is not empty. |
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.
Change this to an if let Some(event) = self.dial_queue.pop()
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.
error[E0599]: no method named `pop` found for struct `std::collections::VecDeque<network::protocols::announce::protocol::OutboundConfig>` in the current scope
--> cnd/src/network/protocols/announce/handler.rs:125:46
|
125 | if let Some(event) = self.dial_queue.pop() {
| ^^^ method not found in `std::collections::VecDeque<network::protocols::announce::protocol::OutboundConfig>`
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.
Ah if it is a VecDeque
the fn is called pop_front
or something, look it up in the docs :)
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.
yeh changed it to pop_front with if let Some(..)
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, this one was never resolved. I had a quick hack, and it looks like this is a bigger issue than just using the correct function. We (mis)use a Vec
as a FILO queue for events
and we (mis)use a VecDequeue
as a FIFO queue for dial_queue
. We should decide what behaviour we actually want here and also we should use the data structures correctly. Since bors is running I'll add a ticket for this.
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.
Tracking issue: #2306
2768d98
to
acf4f23
Compare
acf4f23
to
9be18ab
Compare
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.
Excluding the connection stuff, LGTM.
Disable clippy type complexity for function defined by libp2p. For the futures we use, add a type that aliases all the pin/box/dyn stuff.
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.
I assume connection handling will be followed up :)
Have the two of you talked about the problem I pointed out in my previous review in regards to simultaneous swaps? I don't see an response to that here :) |
I'm with |
@Rishab can you please create a ticket, I don't see one there yet. Thanks. |
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.
Really nice work @rishflab & @tcharding ! :)
50% review done!
One challenging question though:What happens if Alice announces two swaps with the same digest at the same time to Bob? How is she going to tell the responses apart if the event only contains the digest?
I see three possible ways of going about this:
- We ignore it, making it ambiguous for Alice, which of the announced swaps has which SwapId.
This could actually be feasible because if the swaps have the same digest, they are literally the same and it shouldn't matter if Bob is prepared for both or just one. There should be no problems downstream.- We return a unique "token" (struct with a random/monotonically-increasing u32 inside) from the
start_announce_protocol
function that we will carry along internally and also emit in theConfirmationReceived
event. That will allow the caller (Alice) to match, which of the calls she made was actually successful and which one failed.- We force the caller to pass some context information into the function and emit that one back in the event. Basically the same as (2) but we just don't have control over the data.
- (1) sounds like a shortcut but it may actually be feasible.
- (2) is the most "isolated" solution and does not assume anything about the rest of the program
- (3) could be interesting because we are already going to have an identifier for this: the "local" swap id we use to index the created swap data in the database.
I think we could go for all 3 solutions (or are there even more?).
Opinions @rishflab @tcharding ?
Don't feel like I have the knowledge/foresight at this point to make a decision on this. I am thinking we should come back to it after adding integration tests.
}, | ||
} | ||
|
||
impl NetworkBehaviourEventProcess<BehaviourEvent> for Announce { |
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.
Will we need this trait implemented to combine this announce protocol with the other protocols? We weren't completely sure what this trait does it the chat example had it implemented. They were using it to print events so it was difficult to infer what its actual purpose was.
I accept full responsibility here, process fail by me. I should have communicated more with you @rishflab and not made assumptions. Live and learn :) |
bors r+ |
Build succeeded |
We think we have the overall structure and event propagation sorted. I think we should add tests at the network behaviour level like the chat example in libp2p to confirm everything is working how we expect.