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

swap: always allow debt-reducing messages #1922

Merged
merged 27 commits into from
Nov 13, 2019
Merged

Conversation

mortelli
Copy link
Contributor

@mortelli mortelli commented Oct 31, 2019

This PR changes the SWAP Add function so that debt-reducing messages are always processed.

It also updates the relevant tests.

closes #1921

@mortelli mortelli added in progress incentives builds on open PR Builds on a PR that is not yet merged. It is blocked until then and the diff won't make sense yet. labels Oct 31, 2019
@mortelli mortelli self-assigned this Oct 31, 2019
@mortelli mortelli changed the title swap: always allow debt reduction messages swap: always allow debt-reducing messages Nov 1, 2019
@mortelli mortelli removed the builds on open PR Builds on a PR that is not yet merged. It is blocked until then and the diff won't make sense yet. label Nov 5, 2019
…uction

# Conflicts:
#	swap/protocol_test.go
#	swap/swap.go
#	swap/swap_test.go
@mortelli mortelli marked this pull request as ready for review November 5, 2019 12:49
@@ -302,8 +302,8 @@ func (s *Swap) Add(amount int64, peer *protocols.Peer) (err error) {

// Check if balance with peer is over the disconnect threshold
balance := swapPeer.getBalance()
if balance >= s.params.DisconnectThreshold {
return fmt.Errorf("balance for peer %s is over the disconnect threshold %d, disconnecting", peer.ID().String(), s.params.DisconnectThreshold)
Copy link
Member

@ralph-pichler ralph-pichler Nov 5, 2019

Choose a reason for hiding this comment

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

I wonder how useful this is without also preventing the sending of debt-incurring messages on the other node. If only a single debt incurring message arrives we immediately disconnect (and the other node may not even be aware of the fact that it is now above the threshold if the balances are not in perfect sync).

Copy link
Contributor Author

@mortelli mortelli Nov 5, 2019

Choose a reason for hiding this comment

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

i guess we could prevent sending debt-increasing messages when near the disconnect threshold.

that would have the consequence of never dropping peers (if nodes do not behave maliciously)... not sure if we want this or not.

also: what we do when returning an error here is probably best to keep in mind when we deal with the changes to the retrieve protocol, error handling, the blacklist and such (meaning: if we really drop a peer after returning this error or not)

Copy link
Contributor

Choose a reason for hiding this comment

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

This is definitely not useful if there would actually be a disconnect at the disconnect threshold and if that disconnect threshold would be triggered more than once.
We need to implement on the requesting node that it won't send any debt-incurring messages after the payment threshold (note: not the disconnect threshold, we need this buffer) has been reached and there are no funds to pay.

Copy link
Contributor

Choose a reason for hiding this comment

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

For now, I would say it is useful and we should perhaps leave a comment in the code to address this issue when at a later point the error indeed causes a disconnect

swap/swap.go Outdated
@@ -302,8 +302,8 @@ func (s *Swap) Add(amount int64, peer *protocols.Peer) (err error) {

// Check if balance with peer is over the disconnect threshold
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you update this comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done!

Copy link
Contributor

@Eknir Eknir left a comment

Choose a reason for hiding this comment

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

Good PR. Nice and simple :) .
We should keep in mind that when the error that is being returned is actually causing a disconnect, we need to discipline the requesting node to never request chunks when he is past the payment threshold with a particular peer.

@mortelli
Copy link
Contributor Author

Good PR. Nice and simple :) .
We should keep in mind that when the error that is being returned is actually causing a disconnect, we need to discipline the requesting node to never request chunks when he is past the payment threshold with a particular peer.

i wouldn't rush with this one, although maybe it's good to have an issue created to remember this discussion.

but i am thinking that maybe this would affect forwarding, no?

Copy link
Contributor

@holisticode holisticode left a comment

Choose a reason for hiding this comment

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

Approved.

But indeed we need to create an issue, and although it is not highest priority, it is also not just to "remember this discussion" - it is something we have to do.

The creditor node also needs to keep track of the disconnect threshold and prevent a debit-incurring message in the first place, because at the moment where it locally accounts, but the peer disconnects, we need to consider the balances out-of-sync. While this may be ok short term, it can be irrecoverable if the nodes later resume (for example because the other paid the cheque).

Also to note here is that if the message is Receiver pays, and the peer would cross the disconnect threshold, then this not only means that the peer is disconnected, but also that the original message is not sent (in this case the other peer doesn't even ever account for it) - just informative..

@mortelli
Copy link
Contributor Author

mortelli commented Nov 13, 2019

Approved.

But indeed we need to create an issue, and although it is not highest priority, it is also not just to "remember this discussion" - it is something we have to do.

The creditor debitor node also needs to keep track of the disconnect threshold and prevent a debit-incurring message in the first place, because at the moment where it locally accounts, but the peer disconnects, we need to consider the balances out-of-sync. While this may be ok short term, it can be irrecoverable if the nodes later resume (for example because the other paid the cheque).

I understand your point, but I am not immediately convinced by this. This also—I think—ties in to what @ralph-pichler commented here.

If we prevent the debitor node from sending messages which would put it over the disconnect threshold, wouldn't this prevent peers being dropped/disconnected in most cases?

I am not aware of this being necessarily what we want. In fact, didn't we implement the disconnect threshold to drop bad peers in the first place? (leaving aside the technical details of protocols which prevent this from actually happening in some cases).

Also, it's still not clear to me how it would affect forwarding.

Also to note here is that if the message is Receiver pays, and the peer would cross the disconnect threshold, then this not only means that the peer is disconnected, but also that the original message is not sent (in this case the other peer doesn't even ever account for it) - just informative..

I think in this case we don't account for it either, but you are right that the peer would be dropped.

Besides this, I think @Eknir raised a different issue which can also be discussed:

We should keep in mind that when the error that is being returned is actually causing a disconnect, we need to discipline the requesting node to never request chunks when he is past the payment threshold with a particular peer.

@mortelli
Copy link
Contributor Author

@holisticode in any case, I think something similar/equivalent to what you are saying is described in Situation 1 here. Is this correct?

If so, it's still an open problem we need to solve. And the suggestion of preventing messages from the debitor which would put it over the disconnect threshold in the creditor would mitigate this.

@holisticode
Copy link
Contributor

@mortelli yes, it's described there and the suggestion would address it. That is why I would like to see an issue for this. Again, maybe not highest priority, but certainly important.

@mortelli mortelli merged commit 301fcac into master Nov 13, 2019
@mortelli mortelli deleted the swap-allow-debt-reduction branch November 13, 2019 19:24
@acud acud added this to the 0.5.3 milestone Nov 25, 2019
@mortelli mortelli mentioned this pull request Jan 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

always allow debt-reducing messages
6 participants