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 coinbase transaction amount returned by filtertransactions #971

Merged
merged 2 commits into from
Apr 15, 2019

Conversation

cmihai
Copy link
Member

@cmihai cmihai commented Apr 12, 2019

This commit cherry-picks the GetAmount changes from #811 and fixes the filtertransactions RPC output for coinbase transactions, setting the "fee" field to zero and "amount" to the reward received by the miner. Previously, as a side-effect of the algorithm, it was the other way around.

See also #779 and #961.

entry.pushKV("abandoned", wtx.isAbandoned());
}

// UNIT-E: TODO: get staked transactions
Copy link
Member Author

Choose a reason for hiding this comment

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

For the reason why this branch was removed, see #779 (comment).

@cmihai cmihai requested review from Nizametdinov and a team April 12, 2019 13:24
@cmihai cmihai self-assigned this Apr 12, 2019
@cmihai cmihai added the rpc label Apr 12, 2019
thothd
thothd approved these changes Apr 12, 2019
src/wallet/rpcwalletext.cpp Outdated Show resolved Hide resolved
src/wallet/rpcwalletext.cpp Outdated Show resolved Hide resolved
src/wallet/rpcwalletext.cpp Outdated Show resolved Hide resolved
src/wallet/rpcwalletext.cpp Show resolved Hide resolved
output.pushKV("amount", ValueFromAmount(s.amount));
outputs.push_back(output);
amount -= s.amount;
if (receivedOutputs.count(s.vout) == 0) {
Copy link
Member

Choose a reason for hiding this comment

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

I think the implementation of GetAmounts is wrong as it can put one output both to sent and received lists. But maybe it's needed to show internal transfers.

@thothd thothd self-requested a review April 13, 2019 08:33
@thothd thothd added this to the 0.1 milestone Apr 15, 2019
@castarco
Copy link

castarco commented Apr 15, 2019

Although I understand the spirit of the change, I'm not sure about changing the meaning of the "amount" field for coinbase transactions. I would prefer to add fields like "reward", "collected_fees" & "used_stake" that only appears for them, and remove the "amount" field.

Copy link
Member

@thothd thothd left a comment

Choose a reason for hiding this comment

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

@cmihai can you verify this change on top of the already running alpha testnet?

Currently, a transaction amount and fee are calculated by the
following algorithm:

* The 'fee' is the difference between a transaction's sum of outputs and
its sum of inputs.

* The 'amount' is the difference between the sum of its outputs and the
sum of those outputs that are sent to the node itself.

This makes sense for a regular transaction, however, for a coinbase Tx,
the amount will be zero, because all of its outputs are sent to the node
itself.

This commit special-cases coinbase Txs and sets the amount to the fee
itself, which is what most people expect to see.

Signed-off-by: Mihai Ciumeica <mihai@thirdhash.com>
@cmihai cmihai force-pushed the fix-coinbase-amount-display branch from 8c46560 to abbe7e0 Compare April 15, 2019 09:12
@cmihai
Copy link
Member Author

cmihai commented Apr 15, 2019

Although I understand the spirit of the change, I'm not sure about changing the meaning of the "amount" field for coinbase transactions. I would prefer to add fields like "reward", "collected_fees" & "used_stake" that only appears for them, and remove the "amount" field.

@castarco that's a good idea, but it's not a one-line change since 1) for now, filtertransactions only deals with a transaction's outputs, and the stake is an input, and 2) the block reward and the fees are combined into the first output. Let's first have the RPC output make some kind of sense to the client, and then we can add new fields.

Signed-off-by: Mihai Ciumeica <mihai@thirdhash.com>
Copy link
Member

@Nizametdinov Nizametdinov left a comment

Choose a reason for hiding this comment

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

utACK 36ea74b

Copy link

@castarco castarco left a comment

Choose a reason for hiding this comment

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

utACK 36ea74b

@cmihai cmihai merged commit c8d807d into dtr-org:master Apr 15, 2019
@cmihai cmihai deleted the fix-coinbase-amount-display branch April 15, 2019 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants