-
Notifications
You must be signed in to change notification settings - Fork 14
app: Use relayFee setting #153
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
Open
JoeGruffins
wants to merge
3
commits into
decred:master
Choose a base branch
from
JoeGruffins:userelayfee
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -841,15 +841,6 @@ def updateTip(self): | |
log.error("failed to retrieve tip from blockchain: %s" % formatTraceback(e)) | ||
raise DecredError("no tip data retrieved") | ||
|
||
def relayFee(self): | ||
""" | ||
Return the current transaction fee. | ||
|
||
Returns: | ||
int: Atoms per kB of encoded transaction. | ||
""" | ||
return txscript.DefaultRelayFeePerKb | ||
|
||
def saveBlockHeader(self, header): | ||
""" | ||
Save the block header to the database. | ||
|
@@ -861,13 +852,25 @@ def saveBlockHeader(self, header): | |
self.heightMap[header.height] = bHash | ||
self.headerDB[bHash] = header | ||
|
||
def sendToAddress(self, value, address, keysource, utxosource, feeRate=None): | ||
def checkFeeRate(self, relayFee): | ||
""" | ||
Check that the relay fee is lower than the allowed max of | ||
txscript.HighFeeRate. | ||
""" | ||
if relayFee > txscript.HighFeeRate: | ||
raise DecredError( | ||
f"relay fee of {relayFee} is above the allowed max of {txscript.HighFeeRate}" | ||
) | ||
|
||
def sendToAddress( | ||
self, value, address, keysource, utxosource, relayFee, allowHighFees=False | ||
): | ||
""" | ||
Send the amount in atoms to the specified address. | ||
|
||
Args: | ||
value int: The amount to send, in atoms. | ||
address str: The base-58 encoded address. | ||
value (int): The amount to send, in atoms. | ||
address (str): The base-58 encoded address. | ||
keysource func(str) -> PrivateKey: A function that returns the | ||
private key for an address. | ||
utxosource func(int, func(UTXO) -> bool) -> list(UTXO): A function | ||
|
@@ -876,11 +879,18 @@ def sendToAddress(self, value, address, keysource, utxosource, feeRate=None): | |
amount. If the filtering function is provided, UTXOs for which | ||
the function return a falsey value will not be included in the | ||
returned UTXO list. | ||
MsgTx: The newly created transaction on success, `False` on failure. | ||
relayFee (int): Transaction fees in atoms per kb. | ||
allowHighFees (bool): Optional. Default is False. Whether to allow | ||
fees higher than txscript.HighFeeRate. | ||
|
||
Returns: | ||
MsgTx: The newly created transaction. Raises an exception on error. | ||
""" | ||
if not allowHighFees: | ||
self.checkFeeRate(relayFee) | ||
self.updateTip() | ||
outputs = makeOutputs([(address, value)], self.netParams) | ||
return self.sendOutputs(outputs, keysource, utxosource, feeRate) | ||
return self.sendOutputs(outputs, keysource, utxosource, relayFee, allowHighFees) | ||
|
||
def broadcast(self, txHex): | ||
""" | ||
|
@@ -962,7 +972,9 @@ def confirmUTXO(self, utxo, block=None, tx=None): | |
pass | ||
return False | ||
|
||
def sendOutputs(self, outputs, keysource, utxosource, feeRate=None): | ||
def sendOutputs( | ||
self, outputs, keysource, utxosource, relayFee, allowHighFees=False | ||
): | ||
""" | ||
Send the `TxOut`s to the address. | ||
|
||
|
@@ -982,12 +994,17 @@ def sendOutputs(self, outputs, keysource, utxosource, feeRate=None): | |
sufficient to complete the transaction. If the filtering | ||
function is provided, UTXOs for which the function return a | ||
falsey value will not be included in the returned UTXO list. | ||
relayFee (int): Transaction fees in atoms per kb. | ||
allowHighFees (bool): Optional. Default is False. Whether to allow | ||
fees higher than txscript.HighFeeRate. | ||
|
||
Returns: | ||
newTx MsgTx: The sent transaction. | ||
utxos list(UTXO): The spent UTXOs. | ||
newUTXOs list(UTXO): Length 1 array containing the new change UTXO. | ||
""" | ||
if not allowHighFees: | ||
self.checkFeeRate(relayFee) | ||
total = 0 | ||
inputs = [] | ||
scripts = [] | ||
|
@@ -998,14 +1015,13 @@ def sendOutputs(self, outputs, keysource, utxosource, feeRate=None): | |
changeScriptVersion = txscript.DefaultScriptVersion | ||
changeScriptSize = txscript.P2PKHPkScriptSize | ||
|
||
relayFeePerKb = feeRate * 1e3 if feeRate else self.relayFee() | ||
for (i, txout) in enumerate(outputs): | ||
checkOutput(txout, relayFeePerKb) | ||
checkOutput(txout, relayFee) | ||
|
||
Comment on lines
1017
to
1020
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was converted here. So I guess it did take atoms/b. Should I revert? Or try to make everything atoms/b? Either is fine with me, but some accepting atoms/byte and other atoms/kb is confusing. |
||
signedSize = txscript.estimateSerializeSize( | ||
[txscript.RedeemP2PKHSigScriptSize], outputs, changeScriptSize | ||
) | ||
targetFee = txscript.calcMinRequiredTxRelayFee(relayFeePerKb, signedSize) | ||
targetFee = txscript.calcMinRequiredTxRelayFee(relayFee, signedSize) | ||
targetAmount = sum(txo.value for txo in outputs) | ||
|
||
while True: | ||
|
@@ -1034,7 +1050,7 @@ def sendOutputs(self, outputs, keysource, utxosource, feeRate=None): | |
signedSize = txscript.estimateSerializeSize( | ||
scriptSizes, outputs, changeScriptSize | ||
) | ||
requiredFee = txscript.calcMinRequiredTxRelayFee(relayFeePerKb, signedSize) | ||
requiredFee = txscript.calcMinRequiredTxRelayFee(relayFee, signedSize) | ||
remainingAmount = total - targetAmount | ||
if remainingAmount < requiredFee: | ||
targetFee = requiredFee | ||
|
@@ -1055,7 +1071,7 @@ def sendOutputs(self, outputs, keysource, utxosource, feeRate=None): | |
changeVout = -1 | ||
changeAmount = round(total - targetAmount - requiredFee) | ||
if changeAmount != 0 and not txscript.isDustAmount( | ||
changeAmount, changeScriptSize, relayFeePerKb | ||
changeAmount, changeScriptSize, relayFee | ||
): | ||
if len(changeScript) > txscript.MaxScriptElementSize: | ||
raise DecredError( | ||
|
@@ -1110,7 +1126,7 @@ def sendOutputs(self, outputs, keysource, utxosource, feeRate=None): | |
|
||
return newTx, utxos, newUTXOs | ||
|
||
def purchaseTickets(self, keysource, utxosource, req): | ||
def purchaseTickets(self, keysource, utxosource, req, allowHighFees=False): | ||
""" | ||
Based on dcrwallet (*Wallet).purchaseTickets. | ||
purchaseTickets indicates to the wallet that a ticket should be | ||
|
@@ -1120,11 +1136,13 @@ def purchaseTickets(self, keysource, utxosource, req): | |
available. | ||
|
||
Args: | ||
keysource account.KeySource: a source for private keys. | ||
keysource (account.KeySource): a source for private keys. | ||
utxosource func(int, filterFunc) -> (list(UTXO), bool): a source for | ||
UTXOs. The filterFunc is an optional function to filter UTXOs, | ||
and is of the form func(UTXO) -> bool. | ||
req account.TicketRequest: the ticket data. | ||
req (account.TicketRequest): the ticket data. | ||
allowHighFees (bool): Optional. Default is False. Whether to allow | ||
fees higher than txscript.HighFeeRate. | ||
|
||
Returns: | ||
(splitTx, tickets) tuple: first element is the split transaction. | ||
|
@@ -1135,6 +1153,9 @@ def purchaseTickets(self, keysource, utxosource, req): | |
addresses. | ||
|
||
""" | ||
if not allowHighFees: | ||
self.checkFeeRate(req.txFee) | ||
self.checkFeeRate(req.ticketFee) | ||
self.updateTip() | ||
# account minConf is zero for regular outputs for now. Need to make that | ||
# adjustable. | ||
|
@@ -1205,10 +1226,6 @@ def purchaseTickets(self, keysource, utxosource, req): | |
"unsupported voting address type %s" % votingAddress.__class__.__name__ | ||
) | ||
|
||
ticketFeeIncrement = req.ticketFee | ||
if ticketFeeIncrement == 0: | ||
ticketFeeIncrement = self.relayFee() | ||
|
||
# Make sure that we have enough funds. Calculate different | ||
# ticket required amounts depending on whether or not a | ||
# pool output is needed. If the ticket fee increment is | ||
|
@@ -1232,7 +1249,7 @@ def purchaseTickets(self, keysource, utxosource, req): | |
] | ||
estSize = txscript.estimateSerializeSizeFromScriptSizes(inSizes, outSizes, 0) | ||
|
||
ticketFee = txscript.calcMinRequiredTxRelayFee(ticketFeeIncrement, estSize) | ||
ticketFee = txscript.calcMinRequiredTxRelayFee(req.ticketFee, estSize) | ||
neededPerTicket = ticketFee + ticketPrice | ||
|
||
# If we need to calculate the amount for a pool fee percentage, | ||
|
@@ -1270,14 +1287,9 @@ def purchaseTickets(self, keysource, utxosource, req): | |
# User amount. | ||
splitOuts.append(msgtx.TxOut(value=userAmt, pkScript=splitPkScript,)) | ||
|
||
txFeeIncrement = req.txFee | ||
if txFeeIncrement == 0: | ||
txFeeIncrement = self.relayFee() | ||
|
||
# Send the split transaction. | ||
# sendOutputs takes the fee rate in atoms/byte | ||
splitTx, splitSpent, internalOutputs = self.sendOutputs( | ||
splitOuts, keysource, utxosource, int(txFeeIncrement / 1000) | ||
splitOuts, keysource, utxosource, req.txFee, allowHighFees | ||
) | ||
|
||
# Generate the tickets individually. | ||
|
@@ -1373,7 +1385,7 @@ def purchaseTickets(self, keysource, utxosource, req): | |
) | ||
return (splitTx, tickets), splitSpent, internalOutputs | ||
|
||
def revokeTicket(self, tx, keysource, redeemScript): | ||
def revokeTicket(self, tx, keysource, redeemScript, relayFee, allowHighFees=False): | ||
""" | ||
Revoke a ticket by signing the supplied redeem script and broadcasting | ||
the raw transaction. | ||
|
@@ -1384,12 +1396,17 @@ def revokeTicket(self, tx, keysource, redeemScript): | |
the private key used for signing. | ||
redeemScript (byte-like): the 1-of-2 multisig script that delegates | ||
voting rights for the ticket. | ||
relayFee (int): Transaction fees in atoms per kb. | ||
allowHighFees (bool): Optional. Default is False. Whether to allow | ||
fees higher than txscript.HighFeeRate. | ||
|
||
Returns: | ||
MsgTx: the signed revocation. | ||
""" | ||
if not allowHighFees: | ||
self.checkFeeRate(relayFee) | ||
|
||
revocation = txscript.makeRevocation(tx, self.relayFee()) | ||
revocation = txscript.makeRevocation(tx, relayFee) | ||
|
||
signedScript = txscript.signTxOutput( | ||
self.netParams, | ||
|
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.