Skip to content
This repository has been archived by the owner on Mar 23, 2021. It is now read-only.

Announce protocol using libp2p #2283

Merged
merged 2 commits into from Mar 24, 2020
Merged

Announce protocol using libp2p #2283

merged 2 commits into from Mar 24, 2020

Conversation

rishflab
Copy link
Member

@rishflab rishflab commented Mar 19, 2020

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.

Copy link
Contributor

@thomaseizinger thomaseizinger left a 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:

  1. 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.

  2. 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 the ConfirmationReceived event. That will allow the caller (Alice) to match, which of the calls she made was actually successful and which one failed.

  3. 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 ?

cnd/src/network/protocols/announce/behaviour.rs Outdated Show resolved Hide resolved
}

fn inject_connected(&mut self, _peer_id: PeerId, _endpoint: ConnectedPoint) {
// No need to do anything, both this node and connected peer now have a
Copy link
Contributor

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).

Copy link
Member Author

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 {
Copy link
Contributor

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.

Copy link
Member Author

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.

cnd/src/network/protocols/announce/handler.rs Outdated Show resolved Hide resolved
Comment on lines 127 to 128
if !self.dial_queue.is_empty() {
let upgrade = self.dial_queue.remove(0).unwrap(); // Cannot fail, queue is not empty.
Copy link
Contributor

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()

Copy link
Collaborator

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>`

Copy link
Contributor

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 :)

Copy link
Member Author

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(..)

Copy link
Collaborator

@tcharding tcharding Mar 24, 2020

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.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Tracking issue: #2306

cnd/src/network/protocols/announce/mod.rs Outdated Show resolved Hide resolved
cnd/src/network/protocols/announce/protocol.rs Outdated Show resolved Hide resolved
@rishflab rishflab force-pushed the announce-rishab branch 4 times, most recently from 2768d98 to acf4f23 Compare March 23, 2020 06:18
Copy link
Collaborator

@tcharding tcharding left a 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.

@tcharding tcharding self-requested a review March 23, 2020 06:29
@rishflab rishflab marked this pull request as ready for review March 24, 2020 02:36
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.
Copy link
Contributor

@thomaseizinger thomaseizinger left a 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 :)

@thomaseizinger
Copy link
Contributor

@tcharding @rishflab

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 :)

@tcharding
Copy link
Collaborator

  1. 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.

I'm with 1 for now because I'm feeling lazy.

@tcharding
Copy link
Collaborator

I assume connection handling will be followed up :)

@Rishab can you please create a ticket, I don't see one there yet. Thanks.

Copy link
Member Author

@rishflab rishflab left a 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:

  1. 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.
  2. 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 the ConfirmationReceived event. That will allow the caller (Alice) to match, which of the calls she made was actually successful and which one failed.
  3. 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 {
Copy link
Member Author

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.

@tcharding
Copy link
Collaborator

@tcharding @rishflab

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 accept full responsibility here, process fail by me. I should have communicated more with you @rishflab and not made assumptions. Live and learn :)

@mergify
Copy link
Contributor

mergify bot commented Mar 24, 2020

bors r+

@tcharding tcharding mentioned this pull request Mar 24, 2020
@bors
Copy link
Contributor

bors bot commented Mar 24, 2020

Build succeeded

@bors bors bot merged commit c028f2f into dev Mar 24, 2020
@thomaseizinger thomaseizinger deleted the announce-rishab branch March 24, 2020 06:15
@rishflab rishflab linked an issue Mar 25, 2020 that may be closed by this pull request
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement the "announce" protocol
3 participants