Skip to content

Commit

Permalink
ltc: switch to segwit
Browse files Browse the repository at this point in the history
This switches the LTC code to using and requiring segwit features.

This bumps the asset version to 1.  Note that we do not have a good
method for supporting multiple asset versions simultaneously, but
we can punt on that since LTC has not been deployed on mainnet
anywhere to my knowledge.
  • Loading branch information
chappjc committed Mar 30, 2022
1 parent bae9942 commit 06e6259
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 44 deletions.
15 changes: 7 additions & 8 deletions client/asset/btc/btc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,15 @@ import (
)

var (
tLogger dex.Logger
tCtx context.Context
tLotSize uint64 = 1e6 // 0.01 BTC
tRateStep uint64 = 10
tBTC = &dex.Asset{
tLogger dex.Logger
tCtx context.Context
tLotSize uint64 = 1e6 // 0.01 BTC
tBTC = &dex.Asset{
ID: 0,
Symbol: "btc",
Version: version,
SwapSize: dexbtc.InitTxSize,
SwapSizeBase: dexbtc.InitTxSizeBase,
SwapSize: dexbtc.InitTxSizeSegwit, // patched by tNewWallet, but default to segwit
SwapSizeBase: dexbtc.InitTxSizeBaseSegwit,
MaxFeeRate: 34,
SwapConf: 1,
}
Expand Down Expand Up @@ -2801,7 +2800,7 @@ func testTryRedemptionRequests(t *testing.T, segwit bool, walletType string) {
}

addBlocks := func(n int) {
var h int64 = 0
var h int64
// Make dummy transactions.
for i := 0; i < n; i++ {
node.addRawTx(h, otherTx())
Expand Down
4 changes: 2 additions & 2 deletions client/asset/ltc/ltc.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

const (
version = 0
version = 1
// BipID is the BIP-0044 asset ID.
BipID = 2
// defaultFee is the default value for the fallbackfee.
Expand Down Expand Up @@ -165,7 +165,7 @@ func NewWallet(cfg *asset.WalletConfig, logger dex.Logger, network dex.Network)
DefaultFeeRateLimit: defaultFeeRateLimit,
LegacyBalance: true,
LegacyRawFeeLimit: true,
Segwit: false,
Segwit: true,
}

return btc.BTCCloneWallet(cloneCFG)
Expand Down
11 changes: 5 additions & 6 deletions client/asset/ltc/regnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,16 @@ import (
dexbtc "decred.org/dcrdex/dex/networks/btc"
)

const alphaAddress = "mt9hgfXXbM3x7hewgEAovBwqoMAAnctJ4V"
// const alphaAddress = "rltc1qjld4f85m96rr77035c5yuhkz8apxlkkla0ftmz"

var (
tLotSize uint64 = 1e6
tRateStep uint64 = 10
tLTC = &dex.Asset{
tLotSize uint64 = 1e6
tLTC = &dex.Asset{
ID: 2,
Symbol: "ltc",
Version: version,
SwapSize: dexbtc.InitTxSize,
SwapSizeBase: dexbtc.InitTxSizeBase,
SwapSize: dexbtc.InitTxSizeSegwit,
SwapSizeBase: dexbtc.InitTxSizeBaseSegwit,
MaxFeeRate: 10,
SwapConf: 1,
}
Expand Down
72 changes: 46 additions & 26 deletions dex/networks/ltc/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ package ltc

import (
"decred.org/dcrdex/dex"
"decred.org/dcrdex/dex/networks/btc"
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcd/wire"
)

var (
Expand All @@ -18,34 +18,54 @@ var (
},
}
// MainNetParams are the clone parameters for mainnet.
MainNetParams = btc.ReadCloneParams(&btc.CloneParams{
PubKeyHashAddrID: 0x30,
ScriptHashAddrID: 0x32,
Bech32HRPSegwit: "ltc",
CoinbaseMaturity: 100,
Net: 0xdbb6c0fb,
})
MainNetParams = &chaincfg.Params{
Name: "mainnet",
Net: wire.BitcoinNet(0xdbb6c0fb),
CoinbaseMaturity: 100,
Bech32HRPSegwit: "ltc",
PubKeyHashAddrID: 0x30, // starts with L
ScriptHashAddrID: 0x32, // starts with M
PrivateKeyID: 0xB0, // starts with 6 (uncompressed) or T (compressed)
WitnessPubKeyHashAddrID: 0x06, // starts with p2
WitnessScriptHashAddrID: 0x0A, // starts with 7Xh
HDPrivateKeyID: [4]byte{0x04, 0x88, 0xad, 0xe4}, // starts with xprv
HDPublicKeyID: [4]byte{0x04, 0x88, 0xb2, 0x1e}, // starts with xpub
HDCoinType: 2,
}
// TestNet4Params are the clone parameters for testnet.
TestNet4Params = btc.ReadCloneParams(&btc.CloneParams{
PubKeyHashAddrID: 0x6f,
ScriptHashAddrID: 0x3a,
Bech32HRPSegwit: "tltc",
CoinbaseMaturity: 100,
Net: 0xf1c8d2fd,
})
TestNet4Params = &chaincfg.Params{
Name: "testnet4",
Net: wire.BitcoinNet(0xf1c8d2fd),
CoinbaseMaturity: 100,
Bech32HRPSegwit: "tltc",
PubKeyHashAddrID: 0x6f, // starts with m or n
ScriptHashAddrID: 0x3a, // starts with Q
PrivateKeyID: 0xef, // starts with 9 (uncompressed) or c (compressed)
WitnessPubKeyHashAddrID: 0x52, // starts with QW
WitnessScriptHashAddrID: 0x31, // starts with T7n
HDPrivateKeyID: [4]byte{0x04, 0x35, 0x83, 0x94}, // starts with tprv
HDPublicKeyID: [4]byte{0x04, 0x35, 0x87, 0xcf}, // starts with tpub
}
// RegressionNetParams are the clone parameters for simnet.
RegressionNetParams = btc.ReadCloneParams(&btc.CloneParams{
PubKeyHashAddrID: 0x6f,
ScriptHashAddrID: 0x3a,
Bech32HRPSegwit: "rltc",
RegressionNetParams = &chaincfg.Params{
Name: "regtest",
// Net is modified from the normal LTC regtest value since they never
// changed it from the BTC value (0xdab5bffa). The only place we
// currently use Net is in btcd/chaincfg.Register, where it is checked
// to prevent duplicate registration, so our only requirement is that it
// is unique. This one was just generated with a prng.
Net: wire.BitcoinNet(0x9acb0442),
CoinbaseMaturity: 100,
// Net is not the standard for LTC simnet, since they never changed it
// from the BTC value. The only place we currently use Net is in
// btcd/chaincfg.Register, where it is checked to prevent duplicate
// registration, so our only requirement is that it is unique. This one
// was just generated with a prng.
Net: 0x9acb0442,
})
Bech32HRPSegwit: "rltc",
// The rest of the magic values are the same as testnet.
PubKeyHashAddrID: 0x6f, // starts with m or n
ScriptHashAddrID: 0x3a, // starts with Q
PrivateKeyID: 0xef, // starts with 9 (uncompressed) or c (compressed)
WitnessPubKeyHashAddrID: 0x52, // starts with QW
WitnessScriptHashAddrID: 0x31, // starts with T7n
HDPrivateKeyID: [4]byte{0x04, 0x35, 0x83, 0x94}, // starts with tprv
HDPublicKeyID: [4]byte{0x04, 0x35, 0x87, 0xcf}, // starts with tpub
}
)

func init() {
Expand Down
4 changes: 2 additions & 2 deletions server/asset/ltc/ltc.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func init() {
}

const (
version = 0
version = 1
BipID = 2
assetName = "ltc"
)
Expand Down Expand Up @@ -78,7 +78,7 @@ func NewBackend(configPath string, logger dex.Logger, network dex.Network) (asse

return btc.NewBTCClone(&btc.BackendCloneConfig{
Name: assetName,
Segwit: false, // TODO: Change to true.
Segwit: true,
ConfigPath: configPath,
Logger: logger,
Net: network,
Expand Down

0 comments on commit 06e6259

Please sign in to comment.