Skip to content

Commit

Permalink
Added new coins: Vertcoin regtest and dummy USD chain (for demo purpo…
Browse files Browse the repository at this point in the history
…se) (#367)

* Added new coins: Vertcoin regtest and dummy USD chain (for demo purpose)

* Changed diff checking for regtest

* Adds new resync logic to the two new coins

* Corrected PoW for VTC regtest
  • Loading branch information
gertjaap authored and adiabat committed Sep 20, 2018
1 parent 7c76edb commit 08677e4
Show file tree
Hide file tree
Showing 5 changed files with 283 additions and 8 deletions.
6 changes: 5 additions & 1 deletion coinparam/difficulty.go
Expand Up @@ -54,7 +54,7 @@ func calcDiffAdjustBitcoin(start, end *wire.BlockHeader, p *Params) uint32 {
func diffBitcoin(
headers []*wire.BlockHeader, height int32, p *Params) (uint32, error) {

ltcmode := p.Name == "litetest4" || p.Name == "litereg" ||
ltcmode := p.Name == "litetest4" || p.Name == "litereg" || p.Name == "vtcreg" ||
p.Name == "litecoin" || p.Name == "vtctest" || p.Name == "vtc"

//if p.Name == "regtest" {
Expand Down Expand Up @@ -269,3 +269,7 @@ func diffVTCtest(headers []*wire.BlockHeader, height int32, p *Params) (uint32,
// Run KGW
return calcDiffAdjustKGW(headers, height, p)
}

func diffVTCregtest(headers []*wire.BlockHeader, height int32, p *Params) (uint32, error) {
return p.PowLimitBits, nil
}
139 changes: 139 additions & 0 deletions coinparam/dummyusd.go
@@ -0,0 +1,139 @@
package coinparam

import (
"time"

"github.com/mit-dci/lit/btcutil/chaincfg/chainhash"
"github.com/mit-dci/lit/wire"
)

// DummyUsdNetParams for DummyUsd fork defines the network parameters for the DummyUsd network.
var DummyUsdNetParams = Params{
Name: "dollar",
NetMagicBytes: 0x44535564,
DefaultPort: "26999",
DNSSeeds: []string{},

// Chain parameters
GenesisBlock: &DummyUsdGenesisBlock,
GenesisHash: &DummyUsdGenesisHash,
PoWFunction: func(b []byte, height int32) chainhash.Hash {
return chainhash.DoubleHashH(b)
},
DiffCalcFunction: diffBitcoin,
// func(r io.ReadSeeker, height, startheight int32, p *Params) (uint32, error) {
// return diffBTC(r, height, startheight, p, false)
// },
FeePerByte: 80,
PowLimit: regressionPowLimit,
PowLimitBits: 0x207fffff,
CoinbaseMaturity: 100,
SubsidyReductionInterval: 150,
TargetTimespan: time.Hour * 24 * 14, // 14 days
TargetTimePerBlock: time.Minute * 10, // 10 minutes
RetargetAdjustmentFactor: 4, // 25% less, 400% more
ReduceMinDifficulty: true,
MinDiffReductionTime: time.Minute * 20, // TargetTimePerBlock * 2
GenerateSupported: true,

// Checkpoints ordered from oldest to newest.
Checkpoints: nil,

// Enforce current block version once majority of the network has
// upgraded.
// 75% (750 / 1000)
// Reject previous block versions once a majority of the network has
// upgraded.
// 95% (950 / 1000)
BlockEnforceNumRequired: 750,
BlockRejectNumRequired: 950,
BlockUpgradeNumToCheck: 1000,

// Mempool parameters
RelayNonStdTxs: true,

// Address encoding magics
PubKeyHashAddrID: 0x1e, // starts with D
ScriptHashAddrID: 0x5a, // starts with d
PrivateKeyID: 0x83, // starts with u
Bech32Prefix: "dusd",

// BIP32 hierarchical deterministic extended key magics
HDPrivateKeyID: [4]byte{0x04, 0xA5, 0xB3, 0xF4}, // starts with tprv
HDPublicKeyID: [4]byte{0x04, 0xA5, 0xB7, 0x8F}, // starts with tpub

// BIP44 coin type used in the hierarchical deterministic path for
// address generation.
HDCoinType: 262,
TestCoin: true,
}

var DummyUsdGenesisHash = chainhash.Hash([chainhash.HashSize]byte{ // Make go vet happy.
0xd8, 0x69, 0x52, 0xad, 0x56, 0xac, 0xda, 0xe2,
0x32, 0x33, 0xa9, 0xb3, 0x24, 0x66, 0x27, 0x89,
0xf7, 0x39, 0x60, 0xa3, 0x7a, 0x17, 0xae, 0xf7,
0x69, 0x2e, 0xf0, 0x1b, 0x6d, 0x33, 0x4d, 0x19,
})

var DummyUsdGenesisMerkleRoot = chainhash.Hash([chainhash.HashSize]byte{ // Make go vet happy.
0x7e, 0xb6, 0x28, 0xda, 0xa0, 0xd2, 0xef, 0x48,
0x1f, 0x45, 0x9f, 0x5b, 0x35, 0x47, 0x18, 0x41,
0xb6, 0x69, 0x20, 0xdc, 0x12, 0xa3, 0xbf, 0x94,
0x92, 0xca, 0xfe, 0xfc, 0x4e, 0xab, 0xb0, 0x72,
})

var DummyUsdGenesisCoinbaseTx = wire.MsgTx{
Version: 1,
TxIn: []*wire.TxIn{
{
PreviousOutPoint: wire.OutPoint{
Hash: chainhash.Hash{},
Index: 0xffffffff,
},
SignatureScript: []byte{
0x04, 0xff, 0xff, 0x00, 0x1d, 0x01, 0x04, 0x41,
0x49, 0x20, 0x77, 0x6f, 0x6e, 0x64, 0x65, 0x72,
0x20, 0x69, 0x66, 0x20, 0x70, 0x65, 0x6f, 0x70,
0x6c, 0x65, 0x20, 0x77, 0x69, 0x6c, 0x6c, 0x20,
0x6e, 0x6f, 0x74, 0x69, 0x63, 0x65, 0x20, 0x74,
0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x6a,
0x75, 0x73, 0x74, 0x20, 0x62, 0x69, 0x74, 0x63,
0x6f, 0x69, 0x6e, 0x20, 0x77, 0x69, 0x74, 0x68,
0x20, 0x61, 0x20, 0x66, 0x6c, 0x61, 0x76, 0x6f,
0x72,
},
Sequence: 0xffffffff,
},
},
TxOut: []*wire.TxOut{
{
Value: 0x12a05f200,
PkScript: []byte{
0x41, 0x04, 0x67, 0x8a, 0xfd, 0xb0, 0xfe, 0x55, /* |A.g....U| */
0x48, 0x27, 0x19, 0x67, 0xf1, 0xa6, 0x71, 0x30, /* |H'.g..q0| */
0xb7, 0x10, 0x5c, 0xd6, 0xa8, 0x28, 0xe0, 0x39, /* |..\..(.9| */
0x09, 0xa6, 0x79, 0x62, 0xe0, 0xea, 0x1f, 0x61, /* |..yb...a| */
0xde, 0xb6, 0x49, 0xf6, 0xbc, 0x3f, 0x4c, 0xef, /* |..I..?L.| */
0x38, 0xc4, 0xf3, 0x55, 0x04, 0xe5, 0x1e, 0xc1, /* |8..U....| */
0x12, 0xde, 0x5c, 0x38, 0x4d, 0xf7, 0xba, 0x0b, /* |..\8M...| */
0x8d, 0x57, 0x8a, 0x4c, 0x70, 0x2b, 0x6b, 0xf1, /* |.W.Lp+k.| */
0x1d, 0x5f, 0xac, /* |._.| */
},
},
},
LockTime: 0,
}

// regTestGenesisBlock defines the genesis block of the block chain which serves
// as the public transaction ledger for the regression test network.
var DummyUsdGenesisBlock = wire.MsgBlock{
Header: wire.BlockHeader{
Version: 1,
PrevBlock: chainhash.Hash{}, // 0000000000000000000000000000000000000000000000000000000000000000
MerkleRoot: DummyUsdGenesisMerkleRoot,
Timestamp: time.Unix(1537252543, 0),
Bits: 0x207fffff,
Nonce: 0,
},
Transactions: []*wire.MsgTx{&DummyUsdGenesisCoinbaseTx},
}
2 changes: 2 additions & 0 deletions coinparam/register.go
Expand Up @@ -193,8 +193,10 @@ func init() {
mustRegister(&BC2NetParams)
mustRegister(&LiteCoinTestNet4Params)
mustRegister(&LiteRegNetParams)
mustRegister(&VertcoinRegTestParams)
mustRegister(&VertcoinTestNetParams)
mustRegister(&VertcoinParams)
mustRegister(&DummyUsdNetParams)
}

// mustRegister performs the same function as Register except it panics if there
Expand Down
91 changes: 91 additions & 0 deletions coinparam/vertcoin.go
Expand Up @@ -67,6 +67,69 @@ var VertcoinTestNetParams = Params{
TestCoin: true,
}

var VertcoinRegTestParams = Params{
Name: "vtcreg",
NetMagicBytes: 0xdab5bffa,
DefaultPort: "18444",
DNSSeeds: []string{},

// Chain parameters
DiffCalcFunction: diffVTCregtest,
MinHeaders: 4032,
FeePerByte: 100,
GenesisBlock: &VertcoinRegTestnetGenesisBlock,
GenesisHash: &VertcoinRegTestnetGenesisHash,
PowLimit: regressionPowLimit,
PoWFunction: func(b []byte, height int32) chainhash.Hash {
var hashBytes []byte

if height >= 347000 {
hashBytes, _ = lyra2rev2.Sum(b)
} else if height >= 208301 {
hashBytes, _ = lyra2re.Sum(b)
} else {
hashBytes, _ = scrypt.Key(b, b, 2048, 1, 1, 32)
}

asChainHash, _ := chainhash.NewHash(hashBytes)
return *asChainHash
},
PowLimitBits: 0x207fffff,
CoinbaseMaturity: 120,
SubsidyReductionInterval: 150,
TargetTimespan: time.Second * 302400, // 3.5 weeks
TargetTimePerBlock: time.Second * 150, // 150 seconds
RetargetAdjustmentFactor: 4, // 25% less, 400% more
ReduceMinDifficulty: true,
MinDiffReductionTime: time.Second * 150 * 2, // ?? unknown
GenerateSupported: false,

// Checkpoints ordered from oldest to newest.
Checkpoints: []Checkpoint{},

BlockEnforceNumRequired: 26,
BlockRejectNumRequired: 49,
BlockUpgradeNumToCheck: 50,

// Mempool parameters
RelayNonStdTxs: true,

// Address encoding magics
PubKeyHashAddrID: 0x6f,
ScriptHashAddrID: 0xc4,
Bech32Prefix: "rvtc",
PrivateKeyID: 0xef,

// BIP32 hierarchical deterministic extended key magics
HDPrivateKeyID: [4]byte{0x04, 0x35, 0x83, 0x94}, // starts with tprv
HDPublicKeyID: [4]byte{0x04, 0x35, 0x87, 0xcf}, // starts with tpub

// BIP44 coin type used in the hierarchical deterministic path for
// address generation.
HDCoinType: 261,
TestCoin: true,
}

var VertcoinParams = Params{
Name: "vtc",
NetMagicBytes: 0xdab5bffa,
Expand Down Expand Up @@ -213,3 +276,31 @@ var VertcoinGenesisBlock = wire.MsgBlock{
Nonce: 5749262,
},
}

// ==================== VertcoinRegTestnet

// VertcoinRegTestnetGenesisHash
var VertcoinRegTestnetGenesisHash = chainhash.Hash([chainhash.HashSize]byte{
0xce, 0x85, 0x4a, 0xdc, 0x33, 0xe8, 0x7c, 0xc1, 0x6f,
0xbc, 0x32, 0x19, 0x1a, 0x7b, 0x02, 0x17, 0x73, 0xc9,
0x06, 0x72, 0x86, 0x66, 0x0d, 0x65, 0xd1, 0xbb, 0xeb,
0x47, 0xb0, 0xc0, 0x99, 0x23,
})

var VertcoinRegTestnetMerkleRoot = chainhash.Hash([chainhash.HashSize]byte{
0xe7, 0x23, 0x01, 0xfc, 0x49, 0x32, 0x3e, 0xe1, 0x51,
0xcf, 0x10, 0x48, 0x23, 0x0f, 0x03, 0x2c, 0xa5, 0x89,
0x75, 0x3b, 0xa7, 0x08, 0x62, 0x22, 0xa5, 0xc0, 0x23,
0xe3, 0xa0, 0x8c, 0xf3, 0x4a,
})

var VertcoinRegTestnetGenesisBlock = wire.MsgBlock{
Header: wire.BlockHeader{
Version: 1,
PrevBlock: chainhash.Hash{}, // empty
MerkleRoot: VertcoinRegTestnetMerkleRoot,
Timestamp: time.Unix(1296688602, 0), // later
Bits: 0x207fffff,
Nonce: 2,
},
}
53 changes: 46 additions & 7 deletions lit.go
Expand Up @@ -20,13 +20,15 @@ import (

type litConfig struct { // define a struct for usage with go-flags
// networks lit can try connecting to
Tn3host string `long:"tn3" description:"Connect to bitcoin testnet3."`
Bc2host string `long:"bc2" description:"bc2 full node."`
Lt4host string `long:"lt4" description:"Connect to litecoin testnet4."`
Reghost string `long:"reg" description:"Connect to bitcoin regtest."`
Litereghost string `long:"litereg" description:"Connect to litecoin regtest."`
Tvtchost string `long:"tvtc" description:"Connect to Vertcoin test node."`
Vtchost string `long:"vtc" description:"Connect to Vertcoin."`
Tn3host string `long:"tn3" description:"Connect to bitcoin testnet3."`
Bc2host string `long:"bc2" description:"bc2 full node."`
Lt4host string `long:"lt4" description:"Connect to litecoin testnet4."`
Reghost string `long:"reg" description:"Connect to bitcoin regtest."`
Litereghost string `long:"litereg" description:"Connect to litecoin regtest."`
Dummyusdhost string `long:"dusd" description:"Connect to Dummy USD node."`
Rtvtchost string `long:"rtvtc" description:"Connect to Vertcoin regtest node."`
Tvtchost string `long:"tvtc" description:"Connect to Vertcoin test node."`
Vtchost string `long:"vtc" description:"Connect to Vertcoin."`
// system specific configs
LitHomeDir string `long:"dir" description:"Specify Home Directory of lit as an absolute path."`
TrackerURL string `long:"tracker" description:"LN address tracker URL http|https://host:port"`
Expand Down Expand Up @@ -199,7 +201,44 @@ func linkWallets(node *qln.LitNode, key *[32]byte, conf *litConfig) error {
return err
}
}
// try dummyusd
if !lnutil.NopeString(conf.Dummyusdhost) {
p := &coinparam.DummyUsdNetParams
logging.Infof("Dummyusd: %s\n", conf.Dummyusdhost)
resync := false
conf.Tip = p.StartHeight
if conf.Resync == "dusd" {
if conf.Tip < 1 {
conf.Tip = 1
}
resync = true
}
err = node.LinkBaseWallet(key, consts.BitcoinRegtestBHeight, resync,
conf.Tower, conf.Dummyusdhost, conf.ChainProxyURL, p)
if err != nil {
return err
}
}

// try vertcoin regtest
if !lnutil.NopeString(conf.Rtvtchost) {
p := &coinparam.VertcoinRegTestParams
resync := false
conf.Tip = p.StartHeight
if conf.Resync == "rtvtc" {
if conf.Tip < 1 {
conf.Tip = 1
}
resync = true
}

err = node.LinkBaseWallet(
key, consts.BitcoinRegtestBHeight, resync, conf.Tower,
conf.Rtvtchost, conf.ChainProxyURL, p)
if err != nil {
return err
}
}
return nil
}

Expand Down

0 comments on commit 08677e4

Please sign in to comment.