Compare commits

..

3 Commits

Author SHA1 Message Date
Ori Newman
707b3a159e On estimateFee always assume that the recipient has ECDSA address 2024-09-18 14:43:57 +03:00
Ori Newman
decbcd8233 Estimate fee correctly for --send-all 2024-09-18 13:57:44 +03:00
Ori Newman
2d25c3d7a3 Fix estimateFee change value 2024-09-18 13:45:32 +03:00
4 changed files with 16 additions and 12 deletions

View File

@@ -196,9 +196,12 @@ func (s *server) selectUTXOsWithPreselected(preSelectedUTXOs []*walletUTXO, allo
})
totalValue += utxo.UTXOEntry.Amount()
estimatedRecipientValue := spendAmount
if isSendAll {
estimatedRecipientValue = totalValue
}
// We're overestimating a bit by assuming that any transaction will have a change output
fee, err = s.estimateFee(selectedUTXOs, feeRate, maxFee, true)
fee, err = s.estimateFee(selectedUTXOs, feeRate, maxFee, estimatedRecipientValue)
if err != nil {
return false, err
}
@@ -257,9 +260,9 @@ func (s *server) selectUTXOsWithPreselected(preSelectedUTXOs []*walletUTXO, allo
return selectedUTXOs, totalReceived, totalValue - totalSpend, nil
}
func (s *server) estimateFee(selectedUTXOs []*libkaspawallet.UTXO, feeRate float64, maxFee uint64, assumeChange bool) (uint64, error) {
fakePubKey := [util.PublicKeySize]byte{}
fakeAddr, err := util.NewAddressPublicKey(fakePubKey[:], s.params.Prefix)
func (s *server) estimateFee(selectedUTXOs []*libkaspawallet.UTXO, feeRate float64, maxFee uint64, recipientValue uint64) (uint64, error) {
fakePubKey := [util.PublicKeySizeECDSA]byte{}
fakeAddr, err := util.NewAddressPublicKeyECDSA(fakePubKey[:], s.params.Prefix) // We assume the worst case where the recipient address is ECDSA. In this case the scriptPubKey will be the longest.
if err != nil {
return 0, err
}
@@ -271,15 +274,15 @@ func (s *server) estimateFee(selectedUTXOs []*libkaspawallet.UTXO, feeRate float
// This is an approximation for the distribution of value between the recipient output and the change output.
var mockPayments []*libkaspawallet.Payment
if assumeChange {
if totalValue > recipientValue {
mockPayments = []*libkaspawallet.Payment{
{
Address: fakeAddr,
Amount: totalValue * 99 / 100,
Amount: recipientValue,
},
{
Address: fakeAddr,
Amount: totalValue / 100,
Amount: totalValue - recipientValue, // We ignore the fee since we expect it to be insignificant in mass calculation.
},
}
} else {

View File

@@ -72,7 +72,7 @@ func (s *server) mergeTransaction(
totalValue += output.Value
}
// We're overestimating a bit by assuming that any transaction will have a change output
fee, err := s.estimateFee(utxos, feeRate, maxFee, true)
fee, err := s.estimateFee(utxos, feeRate, maxFee, sentValue)
if err != nil {
return nil, err
}
@@ -253,7 +253,7 @@ func (s *server) createSplitTransaction(transaction *serialization.PartiallySign
totalSompi += selectedUTXOs[i-startIndex].UTXOEntry.Amount()
}
if len(selectedUTXOs) != 0 {
fee, err := s.estimateFee(selectedUTXOs, feeRate, maxFee, false)
fee, err := s.estimateFee(selectedUTXOs, feeRate, maxFee, totalSompi)
if err != nil {
return nil, err
}

View File

@@ -90,12 +90,13 @@ func parse(conf *parseConfig) error {
fmt.Println()
fee := allInputSompi - allOutputSompi
fmt.Printf("Fee:\t%d Sompi (%f KAS)\n\n", fee, float64(fee)/float64(constants.SompiPerKaspa))
fmt.Printf("Fee:\t%d Sompi (%f KAS)\n", fee, float64(fee)/float64(constants.SompiPerKaspa))
mass, err := server.EstimateMassAfterSignatures(partiallySignedTransaction, keysFile.ECDSA, keysFile.MinimumSignatures, txMassCalculator)
if err != nil {
return err
}
fmt.Printf("Mass: %d grams\n", mass)
feeRate := float64(fee) / float64(mass)
fmt.Printf("Fee rate: %.2f Sompi/Gram\n", feeRate)
}

View File

@@ -17,7 +17,7 @@ const (
// appBuild is defined as a variable so it can be overridden during the build
// process with '-ldflags "-X github.com/kaspanet/kaspad/version.appBuild=foo"' if needed.
// It MUST only contain characters from validCharacters.
var appBuild string = "rc6"
var appBuild string = "rc7"
var version = "" // string used for memoization of version