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

core, pm: validate payment sender #1210

Merged
merged 1 commit into from
Dec 3, 2019
Merged

Conversation

kyriediculous
Copy link
Contributor

What does this pull request do? Explain your changes. (required)
This PR adds functionality that allows an orchestrator to check whether a broadcaster is coming near to the end of its unlock period. If this is the case the orchestrator will not accept segments nor payments from that broadcaster.

This is accomplished by a recipient.ValidateSender(sender ethcommon.Address) error method that is called in Orchestrator.ProcessPayment(). This method currently does a single check against an unlock period but can be extended with other functionality if needed.

This structure allows us to leverage a RoundsWatcher and SenderWatcher instance that is already active on SenderMonitor. The methods for SenderMonitor are (for good reason) not directly accessible on the Recipient interface that Orchestrator uses, therefore the call graph is core.Orchestrator.ProcessPayment -> Recipient.ValidateSender -> SenderMonitor.IsLocked.

Alternatively, we could have added a method to Orchestrator that accomplishes the same thing, but we would have had to add SenderWatcher and RoundsWatcher instances to LivepeerNode specifically for this. It thus seems a cleaner tradeoff to have a "wrapper/forwarding" function in Recipient.

Specific updates (required)

  • Added a new method Recipient.ValidateSender(sender ethcommon.Address) error
  • Added a new method SenderMonitor.IsLocked(sender ethcommon.Address) error
  • Call Recipient.ValidateSender in Orchestrator.ProcessPayment , short circuit if the sender is nearing its unlock period
  • Added the above methods to stubs

How did you test each of these updates (required)
Ran unit tests

Does this pull request close any open issues?
Fixes #1183

Checklist:

  • README and other documentation updated
  • Node runs in OSX and devenv
  • All tests in ./test.sh pass

pm/sendermonitor.go Show resolved Hide resolved
pm/sendermonitor.go Outdated Show resolved Hide resolved
pm/recipient.go Outdated
@@ -134,6 +136,11 @@ func (r *recipient) Stop() {
close(r.quit)
}

// ValidateSender checks whether sender is a valid ticket sender
func (r *recipient) ValidateSender(sender ethcommon.Address) error {
Copy link
Member

Choose a reason for hiding this comment

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

Instead of adding an additional method to the Recipient public API we could validate the sender in ReceiveTicket():

func (r *recipient) ReceiveTicket(...) (string, bool, error) {
    ...

    if err := r.sm.ValidateSender(ticket.Sender); err != nil {
        return err
    }

    if err := r.val.ValidateTicket(...); err != nil {
        return err
    }

    ...
}

I see the benefits of this approach as:

  • Reduces the # of public API changes in this PR from 2 to 1 since we would only have to change the SenderMonitor public API
  • Eliminates the need to modify the core.Orchestrator impl and its tests

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What I don't like about that is that we would be validating the sender for each ticket in the case where a payment constitutes multiple tickets. This seems like an inefficiency to me as we want to validate the sender of a payment as a whole rather than separate tickets.

We could return an unacceptable payment error from ReceiveTicket but this will still try to redeem winning tickets, which I don't see as fair towards B as these errors can be ephemeral and we don't add credit but are redeeming tickets.

Then again we could do if won && !unacceptableReceiveErr {...} or break the loop upon an unacceptableReceiveError

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in d4b2a96, but I force pushed since the implementation is substantially different and the diffs wouldn't really matter here I guess.

Copy link
Member

Choose a reason for hiding this comment

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

What I don't like about that is that we would be validating the sender for each ticket in the case where a payment constitutes multiple tickets.

The first ticket should fail validation and we would not validate the rest of the tickets in the batch which seems ok.

We could return an unacceptable payment error from ReceiveTicket but this will still try to redeem winning tickets

The error returned would already be considered an unacceptable payment error since we are not returning an AcceptableError from ReceiveTicket() when the sender validation fails.

which I don't see as fair towards B as these errors can be ephemeral and we don't add credit but are redeeming tickets.

O should use the strategy that best serves its interest - in this case, it should always redeem a valid winning ticket if it receives one. We're treating a sender validation error the same way that we would treat an unacceptable payment error that is triggered due to a sender exceeding its max error count - we will not credit the sender and will not transcode the segment, but if the ticket wins we will still redeem it.

pm/sendermonitor.go Outdated Show resolved Hide resolved
pm/stub.go Outdated Show resolved Hide resolved
Copy link
Member

@yondonfu yondonfu left a comment

Choose a reason for hiding this comment

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

LGTM 🚢

@kyriediculous kyriediculous merged commit 09f3589 into master Dec 3, 2019
@kyriediculous kyriediculous deleted the nv/unlocked-sender-check branch December 3, 2019 01: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.

Orchestrator should stop working if a broadcaster's funds are unlocked
2 participants