Skip to content

Commit 75e3b9c

Browse files
committed
feat(protocol): Added constants part for mainnet & added genesis part as well
Signed-off-by: Akhil Repala <[email protected]>
1 parent 6c1ef72 commit 75e3b9c

File tree

3 files changed

+248
-7
lines changed

3 files changed

+248
-7
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"main": {
3+
"version": 0,
4+
"hash": "5b6ef2d3c1f3cdcadfd9a030ba1811efdd17740f14e166489760741d075992e0",
5+
"prev_block": "0000000000000000000000000000000000000000000000000000000000000000",
6+
"merkle_root": "8e4c9756fef2ad10375f360e0560fcc7587eb5223ddf8cd7c7e06e60a1140b15",
7+
"witness_root": "1a2c60b9439206938f8d7823782abdb8b211a57431e9c9b6a6365d8d42893351",
8+
"tree_root": "0000000000000000000000000000000000000000000000000000000000000000",
9+
"reserved_root": "0000000000000000000000000000000000000000000000000000000000000000",
10+
"time": 1580745078,
11+
"bits": "0x1c00ffff",
12+
"nonce": 0,
13+
"mask": "0000000000000000000000000000000000000000000000000000000000000000",
14+
"extra_nonce": "000000000000000000000000000000000000000000000000",
15+
"height": 0,
16+
"magic": 1533997779,
17+
"data_b64": "AAAAAHZBOF4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGixguUOSBpOPjXgjeCq9uLIRpXQx6cm2pjZdjUKJM1GOTJdW/vKtEDdfNg4FYPzHWH61Ij3fjNfH4G5goRQLFQAAAAD//wAcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP//////////AdBMV3cAAAAAABTwI3ri6Phg99eRJPxRPwEuWqqNIwAAAAAAAAQgULiTf8Xe8I+fPL2n5fCMcG7bgKuliAwAAAAAAAAAAAAgLV3lhgnUlw+1SPha0HqH20DgVONMyByVHKmVpY9nTbcgENdI7aG5xnuU0yROAhFndhiptLMp6JatkEMfn0gDS60g4sApmh5GZ3NRZlXwmmSx4WsleVMN5sSlnOVlTepFGA8="
18+
}
19+
}
20+
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package genesis
2+
3+
import (
4+
"encoding/json"
5+
"strconv"
6+
"strings"
7+
)
8+
9+
var raw []byte
10+
11+
type netDisk struct {
12+
Version uint32 `json:"version"`
13+
Hash string `json:"hash"`
14+
PrevBlock string `json:"prev_block"`
15+
MerkleRoot string `json:"merkle_root"`
16+
WitnessRoot string `json:"witness_root"`
17+
TreeRoot string `json:"tree_root"`
18+
ReservedRoot string `json:"reserved_root"`
19+
Time uint32 `json:"time"`
20+
Bits string `json:"bits"`
21+
Nonce uint32 `json:"nonce"`
22+
Mask string `json:"mask"`
23+
ExtraNonce string `json:"extra_nonce"`
24+
Height uint32 `json:"height"`
25+
Magic uint32 `json:"magic"`
26+
DataB64 string `json:"data_b64"`
27+
}
28+
29+
type disk struct {
30+
Main netDisk `json:"main"`
31+
}
32+
33+
// Net holds the parsed genesis info for a network.
34+
type Net struct {
35+
Version uint32
36+
Hash string
37+
PrevBlock string
38+
MerkleRoot string
39+
WitnessRoot string
40+
TreeRoot string
41+
ReservedRoot string
42+
Time uint32
43+
Bits uint32
44+
Nonce uint32
45+
Mask string
46+
ExtraNonce string
47+
Height uint32
48+
Magic uint32
49+
DataB64 string
50+
}
51+
52+
var Main Net
53+
var Maindata string
54+
55+
func mustParseBits(s string) uint32 {
56+
if strings.HasPrefix(s, "0x") || strings.HasPrefix(s, "0X") {
57+
v, err := strconv.ParseUint(s[2:], 16, 32)
58+
if err != nil {
59+
panic("genesis: invalid hex bits: " + s)
60+
}
61+
return uint32(v)
62+
}
63+
v, err := strconv.ParseUint(s, 10, 32)
64+
if err != nil {
65+
panic("genesis: invalid decimal bits: " + s)
66+
}
67+
return uint32(v)
68+
}
69+
70+
func init() {
71+
var d disk
72+
if err := json.Unmarshal(raw, &d); err != nil {
73+
panic("genesis: invalid embedded JSON: " + err.Error())
74+
}
75+
Main = Net{
76+
Version: d.Main.Version,
77+
Hash: strings.ToLower(d.Main.Hash),
78+
PrevBlock: strings.ToLower(d.Main.PrevBlock),
79+
MerkleRoot: strings.ToLower(d.Main.MerkleRoot),
80+
WitnessRoot: strings.ToLower(d.Main.WitnessRoot),
81+
TreeRoot: strings.ToLower(d.Main.TreeRoot),
82+
ReservedRoot: strings.ToLower(d.Main.ReservedRoot),
83+
Time: d.Main.Time,
84+
Bits: mustParseBits(d.Main.Bits),
85+
Nonce: d.Main.Nonce,
86+
Mask: strings.ToLower(d.Main.Mask),
87+
ExtraNonce: strings.ToLower(d.Main.ExtraNonce),
88+
Height: d.Main.Height,
89+
Magic: d.Main.Magic,
90+
}
91+
Maindata = d.Main.DataB64
92+
}

internal/handshake/protocol/network.go

Lines changed: 136 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
"strings"
99
"sync"
1010
"time"
11+
12+
gen "github.com/blinklabs-io/cdnsd/internal/handshake/protocol/genesis"
1113
)
1214

1315
type NetworkType string
@@ -111,8 +113,8 @@ type Network struct {
111113

112114
HalvingInterval uint32
113115
CoinbaseMaturity uint32
114-
GenesisHash string
115-
GenesisBlockHex string
116+
Genesis gen.Net
117+
GenesisBlock string
116118
UnknownBitsMask uint32
117119

118120
POW POWParams
@@ -237,9 +239,12 @@ func testNet() *Network {
237239
targetTimespan := targetWindow * targetSpacing
238240

239241
n := &Network{
240-
Type: "testnet",
241-
Seeds: []string{"hs-testnet.bcoin.ninja"},
242-
Magic: 0, // Need to modify from genesis.testnet.magic
242+
Type: "testnet",
243+
Seeds: []string{"hs-testnet.bcoin.ninja"},
244+
Magic: 2974944722, // Need to modify from genesis.testnet.magic
245+
246+
// TODO: Need to implement Genesis & GenesisBlock in genesis.go & import here.
247+
// Genesis: "b1520dd24372f82ec94ebf8cf9d9b037d419c4aa3575d05dec70aedd1b427901",
243248
Port: 13038,
244249
BrontidePort: 45806,
245250

@@ -340,8 +345,132 @@ func testNet() *Network {
340345
}
341346

342347
func mainNet() *Network {
343-
// Need to implement
344-
return &Network{}
348+
const (
349+
targetSpacing = uint32(10 * 60) // 10 minutes
350+
targetWindow = uint32(144)
351+
)
352+
blocksPerDay := uint32((24 * 60 * 60) / targetSpacing)
353+
targetTimespan := targetWindow * targetSpacing
354+
355+
n := &Network{
356+
Type: "main",
357+
Seeds: []string{"hs-mainnet.bcoin.ninja", "seed.htools.work"},
358+
Magic: gen.Main.Magic,
359+
Genesis: gen.Main,
360+
GenesisBlock: gen.Maindata,
361+
Port: 12038,
362+
BrontidePort: 44806,
363+
364+
CheckpointMap: map[uint32]string{
365+
1008: "0000000000001013c28fa079b545fb805f04c496687799b98e35e83cbbb8953e",
366+
2016: "0000000000000424ee6c2a5d6e0da5edfc47a4a10328c1792056ee48303c3e40",
367+
10000: "00000000000001a86811a6f520bf67cefa03207dc84fd315f58153b28694ec51",
368+
20000: "0000000000000162c7ac70a582256f59c189b5c90d8e9861b3f374ed714c58de",
369+
30000: "0000000000000004f790862846b23c3a81585aea0fa79a7d851b409e027bcaa7",
370+
40000: "0000000000000002966206a40b10a575cb46531253b08dae8e1b356cfa277248",
371+
50000: "00000000000000020c7447e7139feeb90549bfc77a7f18d4ff28f327c04f8d6e",
372+
56880: "0000000000000001d4ef9ea6908bb4eb970d556bd07cbd7d06a634e1cd5bbf4e",
373+
61043: "00000000000000015b84385e0307370f8323420eaa27ef6e407f2d3162f1fd05",
374+
100000: "000000000000000136d7d3efa688072f40d9fdd71bd47bb961694c0f38950246",
375+
130000: "0000000000000005ee5106df9e48bcd232a1917684ac344b35ddd9b9e4101096",
376+
160000: "00000000000000021e723ce5aedc021ab4f85d46a6914e40148f01986baa46c9",
377+
200000: "000000000000000181ebc18d6c34442ffef3eedca90c57ca8ecc29016a1cfe16",
378+
225000: "00000000000000021f0be013ebad018a9ef97c8501766632f017a778781320d5",
379+
258026: "0000000000000004963d20732c58e5a91cb7e1b61ec6709d031f1a5ca8c55b95",
380+
},
381+
LastCheckpoint: 258026,
382+
383+
HalvingInterval: 170000,
384+
CoinbaseMaturity: 100,
385+
386+
POW: POWParams{
387+
Limit: bi("0000000000ffff00000000000000000000000000000000000000000000000000"),
388+
Bits: 0x1c00ffff,
389+
Chainwork: bi("00000000000000000000000000000000000000000000000075b5a2b7bf522d45"),
390+
TargetWindow: targetWindow,
391+
TargetSpacing: targetSpacing,
392+
BlocksPerDay: blocksPerDay,
393+
TargetTimespan: targetTimespan,
394+
MinActual: targetTimespan / 4,
395+
MaxActual: targetTimespan * 4,
396+
TargetReset: false,
397+
NoRetargeting: false,
398+
},
399+
400+
Names: NamesParams{
401+
AuctionStart: 14 * blocksPerDay,
402+
RolloutInterval: 7 * blocksPerDay,
403+
LockupPeriod: 30 * blocksPerDay,
404+
RenewalWindow: (2 * 365) * blocksPerDay,
405+
RenewalPeriod: 182 * blocksPerDay,
406+
RenewalMaturity: 30 * blocksPerDay,
407+
ClaimPeriod: (4 * 365) * blocksPerDay,
408+
AlexaLockupPeriod: (8 * 365) * blocksPerDay,
409+
ClaimFrequency: 2 * blocksPerDay,
410+
BiddingPeriod: 5 * blocksPerDay,
411+
RevealPeriod: 10 * blocksPerDay,
412+
TreeInterval: blocksPerDay >> 2,
413+
TransferLockup: 2 * blocksPerDay,
414+
AuctionMaturity: (5 + 10 + 14) * blocksPerDay,
415+
NoRollout: false,
416+
NoReserved: false,
417+
},
418+
419+
Block: BlockLimits{
420+
PruneAfterHeight: 1000,
421+
KeepBlocks: 288,
422+
MaxTipAge: 12 * 60 * 60,
423+
SlowHeight: 0,
424+
},
425+
426+
GoosigStop: (365 + 30) * blocksPerDay,
427+
ActivationThreshold: 1916,
428+
MinerWindow: 2016,
429+
430+
Deployments: map[string]Deployment{
431+
"hardening": {Name: "hardening", Bit: 0, StartTime: 1581638400, Timeout: 1707868800, Threshold: -1, Window: -1, Required: false, Force: false},
432+
"icannlockup": {Name: "icannlockup", Bit: 1, StartTime: 1691625600, Timeout: 1703980800, Threshold: -1, Window: -1, Required: false, Force: false},
433+
"airstop": {Name: "airstop", Bit: 2, StartTime: 1751328000, Timeout: 1759881600, Threshold: -1, Window: -1, Required: false, Force: false},
434+
"testdummy": {Name: "testdummy", Bit: 28, StartTime: 1199145601, Timeout: 1230767999, Threshold: -1, Window: -1, Required: false, Force: true},
435+
},
436+
Deploys: []Deployment{
437+
{Name: "hardening", Bit: 0, StartTime: 1581638400, Timeout: 1707868800, Threshold: -1, Window: -1, Required: false, Force: false},
438+
{Name: "icannlockup", Bit: 1, StartTime: 1691625600, Timeout: 1703980800, Threshold: -1, Window: -1, Required: false, Force: false},
439+
{Name: "airstop", Bit: 2, StartTime: 1751328000, Timeout: 1759881600, Threshold: -1, Window: -1, Required: false, Force: false},
440+
{Name: "testdummy", Bit: 28, StartTime: 1199145601, Timeout: 1230767999, Threshold: -1, Window: -1, Required: false, Force: true},
441+
},
442+
443+
KeyPrefix: KeyPrefix{
444+
Privkey: 0x80,
445+
XPubKey: 0x0488b21e,
446+
XPrivKey: 0x0488ade4,
447+
XPubKey58: "xpub",
448+
XPrivKey58: "xprv",
449+
CoinType: 5353,
450+
},
451+
AddressPrefix: "hs",
452+
ClaimPrefix: "hns-claim:",
453+
RequireStandard: true,
454+
455+
RPCPort: 12037,
456+
WalletPort: 12039,
457+
NSPort: 5349,
458+
RSPort: 5350,
459+
460+
MinRelay: 1000,
461+
FeeRate: 100000,
462+
MaxFeeRate: 400000,
463+
464+
IdentityKeyHex: "",
465+
SelfConnect: false,
466+
RequestMempool: true,
467+
468+
DeflationHeight: 61043,
469+
TxStartHeight: 14 * blocksPerDay,
470+
}
471+
n.ensureTime()
472+
n.init()
473+
return n
345474
}
346475

347476
func regTest() *Network {

0 commit comments

Comments
 (0)