From 4b804f702445f6e72ec516179186ec8587694f88 Mon Sep 17 00:00:00 2001 From: sputn1ck Date: Thu, 1 Jun 2023 16:45:12 +0200 Subject: [PATCH] multi: fix overflow on feerate As we multiply the feerate by 1000, if the uint16 feerate is set higher than 66 we would encounter an overflow and as such we could never have a higher feerate than 65. --- cmd/chantools/closepoolaccount.go | 6 +++--- cmd/chantools/recoverloopin.go | 4 ++-- cmd/chantools/rescuefunding.go | 4 ++-- cmd/chantools/sweepremoteclosed.go | 6 +++--- cmd/chantools/sweeptimelock.go | 8 ++++---- cmd/chantools/sweeptimelockmanual.go | 6 +++--- cmd/chantools/zombierecovery_makeoffer.go | 4 ++-- doc/chantools_closepoolaccount.md | 2 +- doc/chantools_recoverloopin.md | 2 +- doc/chantools_rescuefunding.md | 2 +- doc/chantools_sweepremoteclosed.md | 2 +- doc/chantools_sweeptimelock.md | 2 +- doc/chantools_sweeptimelockmanual.md | 2 +- doc/chantools_zombierecovery_makeoffer.md | 2 +- 14 files changed, 26 insertions(+), 26 deletions(-) diff --git a/cmd/chantools/closepoolaccount.go b/cmd/chantools/closepoolaccount.go index 6a1c865..4321064 100644 --- a/cmd/chantools/closepoolaccount.go +++ b/cmd/chantools/closepoolaccount.go @@ -42,7 +42,7 @@ type closePoolAccountCommand struct { AuctioneerKey string Publish bool SweepAddr string - FeeRate uint16 + FeeRate uint32 MinExpiry uint32 MaxNumBlocks uint32 @@ -91,7 +91,7 @@ obtained by running 'pool accounts list' `, cc.cmd.Flags().StringVar( &cc.SweepAddr, "sweepaddr", "", "address to sweep the funds to", ) - cc.cmd.Flags().Uint16Var( + cc.cmd.Flags().Uint32Var( &cc.FeeRate, "feerate", defaultFeeSatPerVByte, "fee rate to "+ "use for the sweep transaction in sat/vByte", ) @@ -158,7 +158,7 @@ func (c *closePoolAccountCommand) Execute(_ *cobra.Command, _ []string) error { func closePoolAccount(extendedKey *hdkeychain.ExtendedKey, apiURL string, outpoint *wire.OutPoint, auctioneerKey *btcec.PublicKey, - sweepAddr string, publish bool, feeRate uint16, minExpiry, + sweepAddr string, publish bool, feeRate uint32, minExpiry, maxNumBlocks, maxNumAccounts, maxNumBatchKeys uint32) error { signer := &lnd.Signer{ diff --git a/cmd/chantools/recoverloopin.go b/cmd/chantools/recoverloopin.go index 831b0b7..211a8b3 100644 --- a/cmd/chantools/recoverloopin.go +++ b/cmd/chantools/recoverloopin.go @@ -25,7 +25,7 @@ type recoverLoopInCommand struct { Vout uint32 SwapHash string SweepAddr string - FeeRate uint16 + FeeRate uint32 StartKeyIndex int NumTries int @@ -73,7 +73,7 @@ func newRecoverLoopInCommand() *cobra.Command { &cc.SweepAddr, "sweep_addr", "", "address to recover "+ "the funds to", ) - cc.cmd.Flags().Uint16Var( + cc.cmd.Flags().Uint32Var( &cc.FeeRate, "feerate", 0, "fee rate to "+ "use for the sweep transaction in sat/vByte", ) diff --git a/cmd/chantools/rescuefunding.go b/cmd/chantools/rescuefunding.go index dedc92d..9cb17cb 100644 --- a/cmd/chantools/rescuefunding.go +++ b/cmd/chantools/rescuefunding.go @@ -45,7 +45,7 @@ type rescueFundingCommand struct { RemotePubKey string SweepAddr string - FeeRate uint16 + FeeRate uint32 APIURL string rootKey *rootKey @@ -115,7 +115,7 @@ chantools rescuefunding \ cc.cmd.Flags().StringVar( &cc.SweepAddr, "sweepaddr", "", "address to sweep the funds to", ) - cc.cmd.Flags().Uint16Var( + cc.cmd.Flags().Uint32Var( &cc.FeeRate, "feerate", defaultFeeSatPerVByte, "fee rate to "+ "use for the sweep transaction in sat/vByte", ) diff --git a/cmd/chantools/sweepremoteclosed.go b/cmd/chantools/sweepremoteclosed.go index cf11960..1220829 100644 --- a/cmd/chantools/sweepremoteclosed.go +++ b/cmd/chantools/sweepremoteclosed.go @@ -29,7 +29,7 @@ type sweepRemoteClosedCommand struct { APIURL string Publish bool SweepAddr string - FeeRate uint16 + FeeRate uint32 rootKey *rootKey cmd *cobra.Command @@ -77,7 +77,7 @@ Supported remote force-closed channel types are: cc.cmd.Flags().StringVar( &cc.SweepAddr, "sweepaddr", "", "address to sweep the funds to", ) - cc.cmd.Flags().Uint16Var( + cc.cmd.Flags().Uint32Var( &cc.FeeRate, "feerate", defaultFeeSatPerVByte, "fee rate to "+ "use for the sweep transaction in sat/vByte", ) @@ -122,7 +122,7 @@ type targetAddr struct { } func sweepRemoteClosed(extendedKey *hdkeychain.ExtendedKey, apiURL, - sweepAddr string, recoveryWindow uint32, feeRate uint16, + sweepAddr string, recoveryWindow uint32, feeRate uint32, publish bool) error { var ( diff --git a/cmd/chantools/sweeptimelock.go b/cmd/chantools/sweeptimelock.go index c8f0ce2..74a29a4 100644 --- a/cmd/chantools/sweeptimelock.go +++ b/cmd/chantools/sweeptimelock.go @@ -29,7 +29,7 @@ type sweepTimeLockCommand struct { Publish bool SweepAddr string MaxCsvLimit uint16 - FeeRate uint16 + FeeRate uint32 rootKey *rootKey inputs *inputFlags @@ -71,7 +71,7 @@ parameter to 144.`, &cc.MaxCsvLimit, "maxcsvlimit", defaultCsvLimit, "maximum CSV "+ "limit to use", ) - cc.cmd.Flags().Uint16Var( + cc.cmd.Flags().Uint32Var( &cc.FeeRate, "feerate", defaultFeeSatPerVByte, "fee rate to "+ "use for the sweep transaction in sat/vByte", ) @@ -125,7 +125,7 @@ type sweepTarget struct { func sweepTimeLockFromSummary(extendedKey *hdkeychain.ExtendedKey, apiURL string, entries []*dataformat.SummaryEntry, sweepAddr string, - maxCsvTimeout uint16, publish bool, feeRate uint16) error { + maxCsvTimeout uint16, publish bool, feeRate uint32) error { targets := make([]*sweepTarget, 0, len(entries)) for _, entry := range entries { @@ -213,7 +213,7 @@ func sweepTimeLockFromSummary(extendedKey *hdkeychain.ExtendedKey, apiURL string func sweepTimeLock(extendedKey *hdkeychain.ExtendedKey, apiURL string, targets []*sweepTarget, sweepAddr string, maxCsvTimeout uint16, - publish bool, feeRate uint16) error { + publish bool, feeRate uint32) error { // Create signer and transaction template. signer := &lnd.Signer{ diff --git a/cmd/chantools/sweeptimelockmanual.go b/cmd/chantools/sweeptimelockmanual.go index 1a30401..25004c9 100644 --- a/cmd/chantools/sweeptimelockmanual.go +++ b/cmd/chantools/sweeptimelockmanual.go @@ -30,7 +30,7 @@ type sweepTimeLockManualCommand struct { Publish bool SweepAddr string MaxCsvLimit uint16 - FeeRate uint16 + FeeRate uint32 TimeLockAddr string RemoteRevocationBasePoint string @@ -92,7 +92,7 @@ address is always the one that's longer (because it's P2WSH and not P2PKH).`, "maximum number of channel updates to try, set to maximum "+ "number of times the channel was used", ) - cc.cmd.Flags().Uint16Var( + cc.cmd.Flags().Uint32Var( &cc.FeeRate, "feerate", defaultFeeSatPerVByte, "fee rate to "+ "use for the sweep transaction in sat/vByte", ) @@ -144,7 +144,7 @@ func (c *sweepTimeLockManualCommand) Execute(_ *cobra.Command, _ []string) error func sweepTimeLockManual(extendedKey *hdkeychain.ExtendedKey, apiURL string, sweepAddr, timeLockAddr string, remoteRevPoint *btcec.PublicKey, maxCsvTimeout, maxNumChannels uint16, maxNumChanUpdates uint64, - publish bool, feeRate uint16) error { + publish bool, feeRate uint32) error { // First of all, we need to parse the lock addr and make sure we can // brute force the script with the information we have. If not, we can't diff --git a/cmd/chantools/zombierecovery_makeoffer.go b/cmd/chantools/zombierecovery_makeoffer.go index b479034..7464e25 100644 --- a/cmd/chantools/zombierecovery_makeoffer.go +++ b/cmd/chantools/zombierecovery_makeoffer.go @@ -26,7 +26,7 @@ import ( type zombieRecoveryMakeOfferCommand struct { Node1 string Node2 string - FeeRate uint16 + FeeRate uint32 rootKey *rootKey cmd *cobra.Command @@ -60,7 +60,7 @@ a counter offer.`, &cc.Node2, "node2_keys", "", "the JSON file generated in the"+ "previous step ('preparekeys') command of node 2", ) - cc.cmd.Flags().Uint16Var( + cc.cmd.Flags().Uint32Var( &cc.FeeRate, "feerate", defaultFeeSatPerVByte, "fee rate to "+ "use for the sweep transaction in sat/vByte", ) diff --git a/doc/chantools_closepoolaccount.md b/doc/chantools_closepoolaccount.md index e5b929b..7cf05d2 100644 --- a/doc/chantools_closepoolaccount.md +++ b/doc/chantools_closepoolaccount.md @@ -32,7 +32,7 @@ chantools closepoolaccount \ --apiurl string API URL to use (must be esplora compatible) (default "https://blockstream.info/api") --auctioneerkey string the auctioneer's static public key (default "028e87bdd134238f8347f845d9ecc827b843d0d1e27cdcb46da704d916613f4fce") --bip39 read a classic BIP39 seed and passphrase from the terminal instead of asking for lnd seed format or providing the --rootkey flag - --feerate uint16 fee rate to use for the sweep transaction in sat/vByte (default 30) + --feerate uint32 fee rate to use for the sweep transaction in sat/vByte (default 30) -h, --help help for closepoolaccount --maxnumaccounts uint32 the number of account indices to try at most (default 20) --maxnumbatchkeys uint32 the number of batch keys to try at most (default 500) diff --git a/doc/chantools_recoverloopin.md b/doc/chantools_recoverloopin.md index f983881..a6f1dd9 100644 --- a/doc/chantools_recoverloopin.md +++ b/doc/chantools_recoverloopin.md @@ -23,7 +23,7 @@ chantools recoverloopin \ ``` --apiurl string API URL to use (must be esplora compatible) (default "https://blockstream.info/api") --bip39 read a classic BIP39 seed and passphrase from the terminal instead of asking for lnd seed format or providing the --rootkey flag - --feerate uint16 fee rate to use for the sweep transaction in sat/vByte + --feerate uint32 fee rate to use for the sweep transaction in sat/vByte -h, --help help for recoverloopin --loop_db_path string path to the loop database file --num_tries int number of tries to try to find the correct key index (default 1000) diff --git a/doc/chantools_rescuefunding.md b/doc/chantools_rescuefunding.md index 9345f50..69093fb 100644 --- a/doc/chantools_rescuefunding.md +++ b/doc/chantools_rescuefunding.md @@ -44,7 +44,7 @@ chantools rescuefunding \ --channeldb string lnd channel.db file to rescue a channel from; must contain the pending channel specified with --channelpoint --confirmedchannelpoint string channel outpoint that got confirmed on chain (:); normally this is the same as the --dbchannelpoint so it will be set to that value ifthis is left empty --dbchannelpoint string funding transaction outpoint of the channel to rescue (:) as it is recorded in the DB - --feerate uint16 fee rate to use for the sweep transaction in sat/vByte (default 30) + --feerate uint32 fee rate to use for the sweep transaction in sat/vByte (default 30) -h, --help help for rescuefunding --localkeyindex uint32 in case a channel DB is not available (but perhaps a channel backup file), the derivation index of the local multisig public key can be specified manually --remotepubkey string in case a channel DB is not available (but perhaps a channel backup file), the remote multisig public key can be specified manually diff --git a/doc/chantools_sweepremoteclosed.md b/doc/chantools_sweepremoteclosed.md index ea457f1..02163b1 100644 --- a/doc/chantools_sweepremoteclosed.md +++ b/doc/chantools_sweepremoteclosed.md @@ -34,7 +34,7 @@ chantools sweepremoteclosed \ ``` --apiurl string API URL to use (must be esplora compatible) (default "https://blockstream.info/api") --bip39 read a classic BIP39 seed and passphrase from the terminal instead of asking for lnd seed format or providing the --rootkey flag - --feerate uint16 fee rate to use for the sweep transaction in sat/vByte (default 30) + --feerate uint32 fee rate to use for the sweep transaction in sat/vByte (default 30) -h, --help help for sweepremoteclosed --publish publish sweep TX to the chain API instead of just printing the TX --recoverywindow uint32 number of keys to scan per derivation path (default 200) diff --git a/doc/chantools_sweeptimelock.md b/doc/chantools_sweeptimelock.md index 33f7a7b..0c8b429 100644 --- a/doc/chantools_sweeptimelock.md +++ b/doc/chantools_sweeptimelock.md @@ -31,7 +31,7 @@ chantools sweeptimelock \ ``` --apiurl string API URL to use (must be esplora compatible) (default "https://blockstream.info/api") --bip39 read a classic BIP39 seed and passphrase from the terminal instead of asking for lnd seed format or providing the --rootkey flag - --feerate uint16 fee rate to use for the sweep transaction in sat/vByte (default 30) + --feerate uint32 fee rate to use for the sweep transaction in sat/vByte (default 30) --fromchanneldb string channel input is in the format of an lnd channel.db file --fromsummary string channel input is in the format of chantool's channel summary; specify '-' to read from stdin -h, --help help for sweeptimelock diff --git a/doc/chantools_sweeptimelockmanual.md b/doc/chantools_sweeptimelockmanual.md index d5813eb..cce3187 100644 --- a/doc/chantools_sweeptimelockmanual.md +++ b/doc/chantools_sweeptimelockmanual.md @@ -36,7 +36,7 @@ chantools sweeptimelockmanual \ ``` --apiurl string API URL to use (must be esplora compatible) (default "https://blockstream.info/api") --bip39 read a classic BIP39 seed and passphrase from the terminal instead of asking for lnd seed format or providing the --rootkey flag - --feerate uint16 fee rate to use for the sweep transaction in sat/vByte (default 30) + --feerate uint32 fee rate to use for the sweep transaction in sat/vByte (default 30) --fromchanneldb string channel input is in the format of an lnd channel.db file --fromsummary string channel input is in the format of chantool's channel summary; specify '-' to read from stdin -h, --help help for sweeptimelockmanual diff --git a/doc/chantools_zombierecovery_makeoffer.md b/doc/chantools_zombierecovery_makeoffer.md index a5367a2..3a3db26 100644 --- a/doc/chantools_zombierecovery_makeoffer.md +++ b/doc/chantools_zombierecovery_makeoffer.md @@ -29,7 +29,7 @@ chantools zombierecovery makeoffer \ ``` --bip39 read a classic BIP39 seed and passphrase from the terminal instead of asking for lnd seed format or providing the --rootkey flag - --feerate uint16 fee rate to use for the sweep transaction in sat/vByte (default 30) + --feerate uint32 fee rate to use for the sweep transaction in sat/vByte (default 30) -h, --help help for makeoffer --node1_keys string the JSON file generated in theprevious step ('preparekeys') command of node 1 --node2_keys string the JSON file generated in theprevious step ('preparekeys') command of node 2