Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

paych: fix voucher amount verification #3821

Merged
merged 3 commits into from
Oct 2, 2020
Merged

Conversation

dirkmc
Copy link
Contributor

@dirkmc dirkmc commented Sep 14, 2020

Payment channels can be

  • Outbound: the payment channel is from the local node’s account to another account.
    For example when a client wants to retrieve data
    • The client creates an outbound payment channel on-chain to the node that has the data
    • The client creates a voucher locally
    • The client checks that creating the voucher will not exceed the remaining balance in the channel
    • The client sends the voucher directly to the data provider
  • Inbound: the payment channel from a remote account to the local node’s account.
    For example when a data provider receives a voucher on a payment channel
    • The data provider fetches the payment channel for the voucher from chain state
    • The data provider checks that adding the voucher will not exceed the remaining balance in the channel
    • The data provider adds the voucher to its local datastore
    • At some later stage (typically when the channel is Settled) the data provider submits the vouchers on-chain

The payment channel state includes a field toSend, which is the sum of submitted vouchers in all lanes.

When a voucher is created on an Inbound payment channel or received and added on an Outbound payment channel we:

  • Sum the total voucher amount across all lanes (including the new voucher)
  • Check that the total voucher amount + toSend <= channel balance

However toSend already includes the amount for submitted vouchers. So in fact we should not include toSend when comparing the total voucher amount to the channel balance.

Currently we fetch vouchers from the datastore and from channel state. However in order to reach channel state, the vouchers must have been either

  • created by the local node on an Outbound channel
  • received and added by the local node on an Inbound channel

Therefore the vouchers should already be in the datastore, there’s no need to fetch them from channel state. So this PR changes the code to only get vouchers from the datastore.
Update: After talking with @magik6k we decided not to change this behaviour

@dirkmc dirkmc force-pushed the fix/paych-voucher-verify branch 2 times, most recently from 53e6c3c to 93375cc Compare September 14, 2020 09:53
@magik6k magik6k merged commit d3effe5 into master Oct 2, 2020
@magik6k magik6k deleted the fix/paych-voucher-verify branch October 2, 2020 21:27
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