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

[wallet] panic: 'attempt to subtract with overflow' when sending small quantities #396

Closed
AsrielBelacqua opened this issue Nov 29, 2017 · 6 comments

Comments

@AsrielBelacqua
Copy link

wallet listener log: http://termbin.com/zmmi

I was trying to send a tiny quantity (1e-8 grins). Wallet send output:

Nov 29 00:17:07.655 INFO Using configuration file at: /home/stelmaria/src/grin/target/debug/grin.toml
Nov 29 00:17:07.660 DEBG Using wallet seed file at: ./wallet.seed
Nov 29 00:17:07.892 DEBG Refreshing wallet outputs
Nov 29 00:17:09.668 INFO Acquiring wallet lock ...
Nov 29 00:17:09.670 DEBG Attempting to acquire wallet lock
Nov 29 00:17:09.834 INFO ... released wallet lock
Nov 29 00:17:09.974 INFO Acquiring wallet lock ...
Nov 29 00:17:09.974 DEBG Attempting to acquire wallet lock
Nov 29 00:17:10.155 INFO ... released wallet lock
Nov 29 00:17:14.198 DEBG Posting partial transaction to http://127.0.0.1:13415/v1/receive/transaction
Nov 29 00:17:14.236 ERRO Error sending transaction - status: 500 Internal Server Error
Nov 29 00:17:14.237 ERRO Communication with receiver failed. Aborting transaction
Nov 29 00:17:14.237 INFO Acquiring wallet lock ...
Nov 29 00:17:14.237 DEBG Attempting to acquire wallet lock
Nov 29 00:17:14.351 INFO cleaning up unused change output from wallet
Nov 29 00:17:14.391 INFO ... released wallet lock
Nov 29 00:17:14.392 ERRO Tx not sent: Hyper(Status)
@antiochp
Copy link
Member

Hmm - probably related to the fact we are (incorrectly) building the tx as "receiver pays the fee" when we should be "sender pays the fee" (related #274).
So we're likely trying to subtract a fee thats larger the total amount being sent.

@mably
Copy link

mably commented Dec 18, 2017

I might have been hit by the same bug: https://hastebin.com/yujufatozu.rb

I was trying to list my wallet outputs, the process crashed.

@heunglee
Copy link
Contributor

The receiver tries to subtract fee from amount and the result becomes negative and overflow takes place. The problem is that fee is more than the amount. It is not matter of who subtracts fee.
It is necessary to review fee policy for micro grin transfers, such as adjustment of weight of fee for micro grin transfers.

[test case]
I sent 0.00000001 grin coin.
So from the receiver part, the amount was 10, and the fee was 1000000 grin coin.

thread '' panicked at 'attempt to subtract with overflow', wallet/src/receiver.rs:

fn receive_transaction
let out_amount = amount - fee;

For reference, the function to calculate fee is:

const DEFAULT_BASE_FEE: u64 = consensus::MILLI_GRIN;

/// Transaction fee calculation
pub fn tx_fee(input_len: usize, output_len: usize, base_fee: Option) -> u64 {
let use_base_fee = match base_fee {
Some(bf) => bf,
None => DEFAULT_BASE_FEE,
};
let mut tx_weight = -1 * (input_len as i32) + 4 * (output_len as i32) + 1;
if tx_weight < 1 {
tx_weight = 1;
}

(tx_weight as u64) * use_base_fee

}

@heunglee
Copy link
Contributor

Until the issue #274 and how to do with amount less than fee w.r.t business requirement finalized, I propose a solution for this issue. When it receives amount less than calculated transaction fee, the receiver sends back error, such as "Error::MoreFeeThanAmount"???

@ignopeverell
Copy link
Contributor

Yes, an explicit error would already be a lot better.

yeastplume pushed a commit that referenced this issue Jan 12, 2018
…l quantities #396 (#603)

* Fund calculation inconsistent (#582)

* [wallet] panic: 'attempt to subtract with overflow' when sending small quantities (#396)
yeastplume pushed a commit that referenced this issue Jan 12, 2018
…ow' when sending small quantities #396 (#604)

* Add 'sent' to wallet info output (#288)

* Fund calculation inconsistent (#582)

* [wallet] panic: 'attempt to subtract with overflow' when sending small quantities (#396)

* [wallet] panic: 'attempt to subtract with overflow' when sending small quantities (#396)
@quentinlesceller
Copy link
Member

Fixed by #694.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants