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

Include existing claim amount in the max biddable amount for a publish #1108

Merged
merged 4 commits into from Feb 22, 2018

Conversation

hackrush01
Copy link
Contributor

@hackrush01 hackrush01 commented Feb 9, 2018

Fixes updating a claim when update's bid amount is greater than wallet balance but it can use the claim's original amount to complete the transaction.

@hackrush01 hackrush01 self-assigned this Feb 9, 2018
@lbry-bot lbry-bot assigned jackrobison and unassigned hackrush01 Feb 9, 2018
@hackrush01
Copy link
Contributor Author

Forgot changelog.

@lyoshenka lyoshenka requested review from eukreign and removed request for jackrobison February 9, 2018 15:09
@lbry-bot lbry-bot assigned eukreign and unassigned jackrobison Feb 9, 2018
Copy link
Member

@jackrobison jackrobison left a comment

Choose a reason for hiding this comment

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

Instead of removing the balance checks you should update them to use fresh numbers from lbryum. lbrynet.core.Wallet.update_balance probably is what you're looking for

@@ -715,8 +715,6 @@ def _publish_stream(self, name, bid, claim_dict, file_path=None, certificate_id=
publisher = Publisher(self.session, self.lbry_file_manager, self.session.wallet,
certificate_id)
parse_lbry_uri(name)
if bid <= 0.0:
Copy link
Member

Choose a reason for hiding this comment

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

The reason this is here is because otherwise we have to possibly make a stream before lbryum would tell us something is wrong

@@ -1969,10 +1967,6 @@ def jsonrpc_publish(self, name, bid, metadata=None, file_path=None, fee=None, ti
if bid <= 0.0:
raise Exception("Invalid bid")

if bid >= self.session.wallet.get_balance():
raise InsufficientFundsError('Insufficient funds. ' \
Copy link
Member

Choose a reason for hiding this comment

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

Same reason as the other bid check

Copy link
Member

Choose a reason for hiding this comment

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

Also, this should be formatted as something like:

raise InsufficientFundsError(
  'Insufficient funds. Make sure you have enough LBC to deposit.'
)

Or perhaps, if the message is constant it should just be built-in to the InsufficientFundsError. How many different messages do we need for this exception?

@@ -1969,10 +1967,6 @@ def jsonrpc_publish(self, name, bid, metadata=None, file_path=None, fee=None, ti
if bid <= 0.0:
raise Exception("Invalid bid")

if bid >= self.session.wallet.get_balance():
raise InsufficientFundsError('Insufficient funds. ' \
Copy link
Member

Choose a reason for hiding this comment

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

Also, this should be formatted as something like:

raise InsufficientFundsError(
  'Insufficient funds. Make sure you have enough LBC to deposit.'
)

Or perhaps, if the message is constant it should just be built-in to the InsufficientFundsError. How many different messages do we need for this exception?

@@ -217,7 +217,7 @@ def update_balance():
d.addCallback(lambda _: self.assertEqual(5, wallet.get_balance()))
d.addCallback(lambda _: wallet.reserve_points('testid', 2))
d.addCallback(lambda _: wallet.claim_name('test', 4, test_claim_dict))
self.assertFailure(d, InsufficientFundsError)
self.assertFailure(d, Exception)
Copy link
Member

Choose a reason for hiding this comment

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

Testing for Exception seems a bit dangerous. This would pass the test on any exception, even if it has nothing to do with the error being tested.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is what is returned from lbryum I guess, maybe I need to look at the lbryum error messages too.
Also would it be bad practice if I check the error message string and then decide which exception to raise?? Something like

if claim["msg"] == "Insufficient funds":
  Raise InsufficientFundsError()

here ^ claim is the JSON signature returned from lbryum

Copy link
Member

Choose a reason for hiding this comment

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

Checking for an error condition in a response from lbryum and throwing an appropriate exception makes sense to me. Although lbryum is not consistent about the insufficient funds errors, maybe we need to add error codes first as @kauffj suggested in another issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, the function for checking the above stuff in lbryum is a bit convoluted, with many abstract returns. Maybe I'll check for error message in daemon and raise specific Exceptions for possible cases, and a different but non-generic and descriptive errors for the rest of the cases.

@lbry-bot lbry-bot assigned hackrush01 and unassigned eukreign and hackrush01 Feb 12, 2018
@hackrush01
Copy link
Contributor Author

@jackrobison
lbrynet.core.Wallet.update_balance only gets the updated wallet balance, but the issue I'm trying to fix is this #748.

For e.g. I have:
10 LBC in wallet
Claim qwerty with bid 20 LBC
I should be able to update qwerty's bid to 25 LBC, which would require spending the claimtrietx input coin. This already has support in lbryum, just removing the checks from the daemon for it.

@lbry-bot lbry-bot assigned hackrush01 and unassigned hackrush01 Feb 13, 2018
@jackrobison
Copy link
Member

Perhaps you could add a function to the lbryum wallet to return the maximum spendable amount for an update. Something like:

def get_maximum_claim_amount(self, claim_id=None):
    return confirmed_balance + current_claim_amount or 0

Then have lbrynet publish check that the bid is less than this amount instead of the balance.

Copy link
Member

@eukreign eukreign left a comment

Choose a reason for hiding this comment

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

A few minor things. Otherwise, LGTM!

@defer.inlineCallbacks
def get_max_usable_balance_for_claim(self, claim_name):
amt = yield self._run_cmd_as_defer_to_thread('get_max_spendable_amt_for_claim', claim_name)
defer.returnValue(amt)
Copy link
Member

Choose a reason for hiding this comment

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

You can simplify this to just:

def get_max_usable_balance_for_claim(self, claim_name):
    return self._run_cmd_as_defer_to_thread('get_max_spendable_amt_for_claim', claim_name)

@defer.inlineCallbacks turns a method into something that returns a Deferred but _run_cmd_as_defer_to_thread() already returns a Deferred, so you can skip all the indirection and just return the result of _run_cmd_as_defer_to_thread().

amt = yield self.session.wallet.get_max_usable_balance_for_claim(name)
if bid > amt:
raise InsufficientFundsError(
"Please lower the bid value, the max amount you can specify for this claim is {}"
Copy link
Member

Choose a reason for hiding this comment

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

In user facing messages we should spell out 'max' as maximum. If this text doesn't make it to the user then never mind.

@hackrush01 hackrush01 force-pushed the update_fix branch 3 times, most recently from 3559d28 to 99dda5f Compare February 20, 2018 04:11
CHANGELOG.md Outdated
@@ -26,7 +26,8 @@ at anytime.
* `get` failing with a non-useful error message when given a uri for a channel claim
* exception checking in several wallet unit tests
* daemon not erring properly for non-numeric values being passed to the `bid` parameter for the `publish` method
*
* publish command to allow updating claims with bid amount higher than wallet balance(by spending the claimtrietx coin) (https://github.com/lbryio/lbry/issues/748)
Copy link
Member

Choose a reason for hiding this comment

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

Commands, classes, functions, and argument names should be decorated with code ( `) tags. In this entry, publish and bid should be decorated.

Copy link
Member

Choose a reason for hiding this comment

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

higher than wallet balance

How much higher? Could be rephrased: with a bid amount higher than the wallet balance, so long as the amount is less than the wallet balance plus the bid amount of the claim being updated

@@ -975,6 +976,9 @@ def _update_balance(self):
lambda result: Decimal(result['confirmed']) + Decimal(result.get('unconfirmed', 0.0)))
return d

def get_max_usable_balance_for_claim(self, claim_name):
Copy link
Member

Choose a reason for hiding this comment

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

Please add a matching dummy method in Wallet too

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!

@lbry-bot lbry-bot assigned hackrush01 and unassigned jackrobison Feb 20, 2018
@jackrobison jackrobison changed the title Update fix Include existing claim amount in the max biddable amount for a publish Feb 20, 2018
@hackrush01
Copy link
Contributor Author

@jackrobison I made the required changes. Please check.

@jackrobison jackrobison merged commit dafa80c into master Feb 22, 2018
@lyoshenka lyoshenka deleted the update_fix branch February 22, 2018 21:46
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.

None yet

3 participants