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

Fix unconfirmed balance, accurately report fees #32

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

AwfulCrawler
Copy link

Problem:

Wallet may report incorrect balance before all transactions are confirmed. This is because dust amounts from change are added to fee by default, but not subtracted from the change amount when counting the wallet balance. The reported fee in the confirmation message of simplewallet also does not take this into account.

For example, try sending 1.123456 from one wallet to another.

Suggested fix:

In wallet2::transfer, after transaction details and dust amount from change has been determined,
record dust, fee and change amount according to the dust policy:

-ptx.fee += dust if dust is added to fee
-ptx.dust = dust only if dust is not added to fee and not kept in change according to dust policy;
otherwise ptx.dust = 0.
-change_dts.amount -= dust if dust is added to fee or sent elsewhere according to dust policy
-modify wallet confirmation message to accurately report fees and account for different dust policies

I removed the if statement around the confirm message in simplewallet since I prefer alway-confirm behaviour, but that is just my preference.

-Always confirm (just my preference)

-Confirmation message more verbose, takes into account dust added to fee and dust sent elsewhere (depending on dust policy)
-While transaction is unconfirmed wallet was returning incorrect balance.

-Fixed by subtracting the dust added to fee or sent elsewhere from the change amount

-Add dust added to fee to the ptx.

-ptx.dust is now zero if dust is added to fee or included in change.  Only non-zero when sent elsewhere.
Removing note to self
Removing notes to self
@iamsmooth
Copy link
Contributor

Is this original work on adapted from another coin?

@AwfulCrawler
Copy link
Author

Being as strict as possible, I copied this:

for (size_t n = 0; n < ptx_vector.size(); ++n)
{
total_fee += ptx_vector[n].fee;
...
}

from Monero. I didn't take anything else from another coin.

EDIT: I think Monero might have a similar issue from just looking at the corresponding code.

@iamsmooth
Copy link
Contributor

OK thanks for the clarification. I will review it ASAP.

Thanks for our code contribution!

@AwfulCrawler
Copy link
Author

Do you think it would be a good idea to just get rid of the dust_policy (apart from maybe the dust_threshold part)? This would also fix the bug instead of merging this pull request.

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