-
Notifications
You must be signed in to change notification settings - Fork 388
feat: discounted fees for confidential transactions #1317
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c1661b2
discount: introduce config args
delta1 9cbd3e0
discount: add policy/discount.h
delta1 b7b2288
discount: implement mempool logic
delta1 c85f0d4
discount: implement net processing
delta1 4807f3e
discount: change miner tx ordering
delta1 52962c1
discount: allow wallet to create discount txs
delta1 3ebc353
discount: add functional tests
delta1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright (c) 2009-2010 Satoshi Nakamoto | ||
// Copyright (c) 2009-2021 The Bitcoin Core developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#ifndef BITCOIN_POLICY_DISCOUNT_H | ||
#define BITCOIN_POLICY_DISCOUNT_H | ||
|
||
#include <consensus/consensus.h> | ||
#include <cstdint> | ||
#include <primitives/transaction.h> | ||
#include <version.h> | ||
|
||
/** | ||
* Calculate a smaller virtual size for discounted Confidential Transactions. | ||
*/ | ||
static inline int64_t GetDiscountVirtualTransactionSize(const CTransaction& tx, int64_t nSigOpCost = 0, unsigned int bytes_per_sig_op = 0) | ||
{ | ||
int64_t size_bytes = ::GetSerializeSize(tx, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS) * (WITNESS_SCALE_FACTOR - 1) + ::GetSerializeSize(tx, PROTOCOL_VERSION); | ||
int64_t sigop_bytes = nSigOpCost * bytes_per_sig_op; | ||
|
||
int64_t weight = std::max(size_bytes, sigop_bytes); | ||
|
||
// for each confidential output | ||
for (size_t i = 0; i < tx.vout.size(); ++i) { | ||
const CTxOut& output = tx.vout[i]; | ||
if (i < tx.witness.vtxoutwit.size()) { | ||
// subtract the weight of the output witness, except the 2 bytes used to serialize the empty proofs | ||
size_t witness_size = ::GetSerializeSize(tx.witness.vtxoutwit[i], PROTOCOL_VERSION); | ||
assert(witness_size >= 2); | ||
weight -= (witness_size - 2); | ||
} | ||
if (output.nValue.IsCommitment()) { | ||
// subtract the weight difference of amount commitment (33) vs explicit amount (9) | ||
weight -= (33 - 9); | ||
} | ||
if (output.nNonce.IsCommitment()) { | ||
// subtract the weight difference of nonce commitment (33) vs no nonce (1) | ||
weight -= 32; | ||
} | ||
} | ||
assert(weight > 0); | ||
|
||
size_t discountvsize = (weight + WITNESS_SCALE_FACTOR - 1) / WITNESS_SCALE_FACTOR; | ||
|
||
assert(discountvsize > 0); | ||
return discountvsize; | ||
} | ||
|
||
#endif // BITCOIN_POLICY_DISCOUNT_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.