Skip to content

Conversation

@andrewshvv
Copy link
Contributor

@andrewshvv andrewshvv commented Nov 24, 2016

Fixes #48.

@andrewshvv andrewshvv changed the title #48 Clearing and settling of HTLC's below the dust limit Clearing and settling of HTLC's below the dust limit #48 Nov 24, 2016
Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

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

Nice work!

With this PR we explicitly say that we safely support micro-payments on the mainchain while adhering to dust-limits.

My comments are pretty minor so we should be able to get this in pretty quickly. It's also a nice step towards adherence to the v1 spec!

Copy link
Member

Choose a reason for hiding this comment

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

Minor nit: the variable name and the godoc comment don't match up. This should be changed to read IsDust.

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, I need to check the spec, but we'll need to ensure that we're storing their value for the dust-limit. This is necessary since we modify their commitment transactions with updates and will need to ensure we adhere to their required dust limit. We don't care about what their dust-limit is as long as they respect our limit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As I described below I don't separate the dust limit on their and our , the dust limit which I store it is negotiated value and it should be identical for both sides.

Copy link
Member

Choose a reason for hiding this comment

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

Minor suggestion: we can eliminate some unnecessary nesting here if we modify the fragment to read:

if _, err := r.Read(scratch[:1]); err != nil {
    retur nil, err
}

if scratch[0] == 1 {
    h.Incoming = true
} else {
    h.Incoming = false
}

Copy link
Member

Choose a reason for hiding this comment

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

Same applies to the fragment below.

Copy link
Member

Choose a reason for hiding this comment

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

We currently don't have a "default" configuration yet for values like the dust-limit, so can you add a TODO here to use the default dust-limit value (or perhaps query a dynamic indicator here?

As written now, this isn't strictly correct since it it just echoes back what they chose, but in practice it works currently.

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, so on second thought, I think we actually need to retain the state of the dust-limit of both sides since the state machine needs to decide separately for incoming/outgoing HTLC's. Otherwise we may run into a "commitment divergence" due to different decisions about if a HTLC constituted a dust value or not.

Copy link
Contributor Author

@andrewshvv andrewshvv Dec 1, 2016

Choose a reason for hiding this comment

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

As far as I understand we negotiate the dust limit on funding request/response messages. After that we have identical dust limit on both sides and may make the decision - should we include HTLC in commitment transaction or not - relaying on this negotiated dust limit, could you please elaborate why we need to have different dust limits for both sides?

Copy link
Member

Choose a reason for hiding this comment

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

The dust limits aren't negotiated like the fees are within the current spec draft. Instead, both sides have their own distinct dust limits, as both sides ay have different degrees of concfomrat w.r.t to what they think a valid dust-limit is.

As a result, there needs to be two dust-limits, one which must be adhered to when the remote side adds HTLC's to our commitment transactions, and one which we need to be cognizant of where we're triggering updates to their commitment transaciton.

Copy link
Member

Choose a reason for hiding this comment

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

The error here shouldn't be ignored.

Copy link
Member

Choose a reason for hiding this comment

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

One additional assertion we can throw in is that if we obtain the current commitment transaction for both sides, the HTLC output shouldn't be present on either of them.

Copy link
Member

Choose a reason for hiding this comment

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

I have a branch locally which starts to factor out paramter like this into a FundingConfig struct which includes all the parameters as are currently defined within the spec.

Copy link
Member

Choose a reason for hiding this comment

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

Nice catch! I think one of my prior commits adding a new test-case accidentally removed this test.

Copy link
Member

Choose a reason for hiding this comment

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

Nice, happy to see this removed. This was left over from when we were toying around with a CLTV based channel construction (assuming there isn't a malleability fix).

@andrewshvv andrewshvv force-pushed the add_dust_check branch 4 times, most recently from c5c1092 to 0b388be Compare December 1, 2016 17:52
@andrewshvv
Copy link
Contributor Author

andrewshvv commented Dec 1, 2016

@Roasbeef With last commit a have added additional logic to properly negotiate the dust_limit value, the general process is:

  • (Alice): sends request in which she propose some dust_limit_alice.
  • (Bob): receives request and estimates dust_limit_bob.
    • if dust_limit_alice > dust_limit_bob: Bob creates some interval in which he accepts bigger dust limit. If dust_limit_alice belongs to this interval we ok with Alice number. If not we send ErrorGeneric.
    • if dust_limit_alice < dust_limit_bob then Bob insist on their dust limit and send bigger amount in response, he can't go lower as far as from his point of view transaction with such dust limit will be rejected by the miners.
  • (Alice): receives the response and:
    • if dust_limit_bob > dust_limit_alice: Alice creates some interval in which she accepts bigger dust limit. If dust_limit_bob belongs to this interval we ok with Bob number. If not we send ErrorGeneric.
    • if dust_limit_bob < dust_limit_alice: then we send ErrorGeneric as far as we already told Bob that we can't go with lower dust limit.

@andrewshvv andrewshvv force-pushed the add_dust_check branch 4 times, most recently from de71bc9 to 1455220 Compare December 6, 2016 14:43
Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

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

Alright, I think this is the final round of review changes.

I like the bit of refactoring that's taken place within the fundingManager in the latest set of commits!

Copy link
Member

Choose a reason for hiding this comment

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

Minor nit: can you drop the Our|Their prefix from the DustLimit fields here? The PoV context really doesn't apply here since these are wire messages rather than state which is stored locally.

Copy link
Member

Choose a reason for hiding this comment

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

Same comment here about dropping the prefix.

peer.go Outdated
Copy link
Member

Choose a reason for hiding this comment

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

Nice catch, this bit of code was unnecessary due to similar logic already residing within the fundingManager.handleErrorGeneric method.

Copy link
Member

@Roasbeef Roasbeef Dec 9, 2016

Choose a reason for hiding this comment

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

This line causes the travis build to fail:

--- FAIL: TestCheckDustLimit (0.01s)
channel_test.go:875: for this test to work bob dust limit should be bigger than alice dust limit at least on 2 satoshi

I don't think this line is needed. It seems that the value of the HTLC within the test simply needs to be above Alice's dust limit, but below Bob's dust limit .

Copy link
Contributor Author

@andrewshvv andrewshvv Dec 12, 2016

Choose a reason for hiding this comment

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

Aghhh... :) Thanks! Because of this multi-hop test I had started forget to check the reason of test failure...

I don't think this line is needed. It seems that the value of the HTLC within the test simply needs to be above Alice's dust limit, but below Bob's dust limit.

done

@andrewshvv andrewshvv force-pushed the add_dust_check branch 4 times, most recently from aa6b03d to e7b55a4 Compare December 12, 2016 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants