Skip to content

Commit e5c8348

Browse files
authored
Merge pull request #430 from gcash/hardforkcleanup
Update chain params for post hardfork activation
2 parents 54d604d + 5d01556 commit e5c8348

File tree

3 files changed

+103
-90
lines changed

3 files changed

+103
-90
lines changed

blockchain/difficulty.go

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@ var (
2020
// oneLsh256 is 1 shifted left 256 bits. It is defined here to avoid
2121
// the overhead of creating it multiple times.
2222
oneLsh256 = new(big.Int).Lsh(bigOne, 256)
23-
24-
// anchorNode is the node used for the asert difficult algorithm. This is the
25-
// block just prior to the fork. After the fork this will be hardcoded, but for
26-
// now it will be set at runtime.
27-
anchorNode *blockNode
2823
)
2924

3025
const (
@@ -74,12 +69,12 @@ const (
7469
// should be used when validating a block at the given height.
7570
func (b *BlockChain) SelectDifficultyAdjustmentAlgorithm(prevNode *blockNode) DifficultyAlgorithm {
7671
height := prevNode.height + 1
77-
if uint64(prevNode.CalcPastMedianTime().Unix()) >= b.chainParams.AxionActivationTime {
78-
return DifficultyAsert
79-
} else if height > b.chainParams.UahfForkHeight && height <= b.chainParams.DaaForkHeight {
72+
if height > b.chainParams.UahfForkHeight && height <= b.chainParams.DaaForkHeight {
8073
return DifficultyEDA
81-
} else if height > b.chainParams.DaaForkHeight {
74+
} else if height > b.chainParams.DaaForkHeight && height <= b.chainParams.AxionActivationHeight {
8275
return DifficultyDAA
76+
} else if height > b.chainParams.AxionActivationHeight {
77+
return DifficultyAsert
8378
}
8479
return DifficultyLegacy
8580
}
@@ -284,21 +279,7 @@ func (b *BlockChain) calcNextRequiredDifficulty(lastNode *blockNode, newBlockTim
284279
case DifficultyDAA:
285280
return b.calcDAARequiredDifficulty(lastNode, newBlockTime)
286281
case DifficultyAsert:
287-
if anchorNode == nil {
288-
// If block 1 has a median timestamp less than the activation time and..
289-
// block 2 has a median timestamp greater than or equal to the activation time,
290-
// then block 3 is the first block to contain the new rules and block 2 is the
291-
// "reference block".
292-
node := b.bestChain.Tip()
293-
for {
294-
if uint64(node.CalcPastMedianTime().Unix()) < b.chainParams.AxionActivationTime {
295-
anchorNode = b.bestChain.next(node)
296-
break
297-
}
298-
node = node.parent
299-
}
300-
}
301-
return b.calcAsertRequiredDifficulty(lastNode, anchorNode.height, anchorNode.parent.timestamp, anchorNode.bits, newBlockTime)
282+
return b.calcAsertRequiredDifficulty(lastNode, b.chainParams.AsertDifficultyAnchorHeight, b.chainParams.AsertDifficultyAnchorParentTimestamp, b.chainParams.AsertDifficultyAnchorBits, newBlockTime)
302283
}
303284
return 0, errors.New("unknown difficulty algorithm")
304285
}

chaincfg/params.go

Lines changed: 95 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,7 @@ type Params struct {
146146
GreatWallForkHeight int32 // May 15, 2019 hardfork
147147
GravitonForkHeight int32 // Nov 15, 2019 hardfork
148148
PhononForkHeight int32 // May 15, 2020 hardfork
149-
150-
// Planned hardforks
151-
AxionActivationTime uint64 // Nov 15, 2020 hardfork
149+
AxionActivationHeight int32 // Nov 15, 2020 hardfork
152150

153151
// CoinbaseMaturity is the number of blocks required before newly mined
154152
// coins (coinbase transactions) can be spent.
@@ -189,10 +187,22 @@ type Params struct {
189187
// NOTE: This only applies if ReduceMinDifficulty is true.
190188
MinDiffReductionTime time.Duration
191189

192-
// AsertDifficultyHalflife the halflife parameter used by the asert
190+
// AsertDifficultyHalflife is the halflife parameter used by the asert
193191
// difficulty adjustment algorithm for the given network.
194192
AsertDifficultyHalflife int64
195193

194+
// AsertDifficultyAnchorHeight is the height of the asert difficulty
195+
// anchor block.
196+
AsertDifficultyAnchorHeight int32
197+
198+
// AsertDifficultyAnchorParentTimestamp is the timestamp of the asert difficulty
199+
// anchor block's parent.
200+
AsertDifficultyAnchorParentTimestamp int64
201+
202+
// AsertDifficultyAnchorBits is the bits of the asert difficulty
203+
// anchor block.
204+
AsertDifficultyAnchorBits uint32
205+
196206
// GenerateSupported specifies whether or not CPU mining is allowed.
197207
GenerateSupported bool
198208

@@ -264,19 +274,21 @@ var MainNetParams = Params{
264274
GreatWallForkHeight: 582679, // 0000000000000000018596bdfd350a9fbc7297a62a3f510b74565d992d63d2ef
265275
GravitonForkHeight: 609135, // 0000000000000000026f7ec9e79be2f5bb839f29ebcf734066d4bb9a13f6ea83
266276
PhononForkHeight: 635258, // 000000000000000003302c47d01e78f1c86aa3b0e96b066761a5059bc8f5781a
267-
268-
AxionActivationTime: 1605441600,
269-
270-
CoinbaseMaturity: 100,
271-
SubsidyReductionInterval: 210000,
272-
TargetTimespan: time.Hour * 24 * 14, // 14 days
273-
TargetTimePerBlock: time.Minute * 10, // 10 minutes
274-
RetargetAdjustmentFactor: 4, // 25% less, 400% more
275-
ReduceMinDifficulty: false,
276-
NoDifficultyAdjustment: false,
277-
MinDiffReductionTime: 0,
278-
AsertDifficultyHalflife: 2 * 24 * 3600, // 2 days in seconds
279-
GenerateSupported: false,
277+
AxionActivationHeight: 661647, // 00000000000000000083ed4b7a780d59e3983513215518ad75654bb02deee62f
278+
279+
CoinbaseMaturity: 100,
280+
SubsidyReductionInterval: 210000,
281+
TargetTimespan: time.Hour * 24 * 14, // 14 days
282+
TargetTimePerBlock: time.Minute * 10, // 10 minutes
283+
RetargetAdjustmentFactor: 4, // 25% less, 400% more
284+
ReduceMinDifficulty: false,
285+
NoDifficultyAdjustment: false,
286+
MinDiffReductionTime: 0,
287+
AsertDifficultyHalflife: 2 * 24 * 3600, // 2 days in seconds
288+
AsertDifficultyAnchorHeight: 661647,
289+
AsertDifficultyAnchorParentTimestamp: 1605447844,
290+
AsertDifficultyAnchorBits: 402971390,
291+
GenerateSupported: false,
280292

281293
// Checkpoints ordered from oldest to newest.
282294
Checkpoints: []Checkpoint{
@@ -347,6 +359,17 @@ var MainNetParams = Params{
347359
"https://ipfs.io/ipfs/QmYhcrsLgGfRTuxoZUCPCEj5xzZx5sAgV32Z7p1qPerJBr",
348360
},
349361
},
362+
{
363+
Height: 661648,
364+
Hash: newHashFromStr("0000000000000000029e471c41818d24b8b74c911071c4ef0b4a0509f9b5a8ce"),
365+
UtxoSetHash: newHashFromStr("fff228b2f788d2be35868fc2517d2557f856cbb9d6e2dad7310ab6054a29ef67"),
366+
UtxoSetSize: 2931107971,
367+
UtxoSetSources: []string{
368+
"http://localhost:8080/ipfs/QmY9Anst9NB42RVSGZehNCF52B2DxAzAYXEPrLrar75VMT",
369+
"https://ipfs.greyh.at/ipfs/QmY9Anst9NB42RVSGZehNCF52B2DxAzAYXEPrLrar75VMT",
370+
"https://ipfs.io/ipfs/QmY9Anst9NB42RVSGZehNCF52B2DxAzAYXEPrLrar75VMT",
371+
},
372+
},
350373
},
351374

352375
// Consensus rule change deployments.
@@ -411,18 +434,20 @@ var RegressionNetParams = Params{
411434
DaaForkHeight: 0, // Always active on regtest
412435
MagneticAnonomalyForkHeight: 1000,
413436
PhononForkHeight: 1000,
414-
415-
AxionActivationTime: 1605441600,
416-
417-
SubsidyReductionInterval: 150,
418-
TargetTimespan: time.Hour * 24 * 14, // 14 days
419-
TargetTimePerBlock: time.Minute * 10, // 10 minutes
420-
RetargetAdjustmentFactor: 4, // 25% less, 400% more
421-
ReduceMinDifficulty: true,
422-
NoDifficultyAdjustment: true,
423-
MinDiffReductionTime: time.Minute * 20, // TargetTimePerBlock * 2
424-
AsertDifficultyHalflife: 3600, // 1 hour
425-
GenerateSupported: true,
437+
AxionActivationHeight: 0, // Always active on regtest
438+
439+
SubsidyReductionInterval: 150,
440+
TargetTimespan: time.Hour * 24 * 14, // 14 days
441+
TargetTimePerBlock: time.Minute * 10, // 10 minutes
442+
RetargetAdjustmentFactor: 4, // 25% less, 400% more
443+
ReduceMinDifficulty: true,
444+
NoDifficultyAdjustment: true,
445+
MinDiffReductionTime: time.Minute * 20, // TargetTimePerBlock * 2
446+
AsertDifficultyHalflife: 3600, // 1 hour
447+
AsertDifficultyAnchorHeight: 0,
448+
AsertDifficultyAnchorParentTimestamp: regTestGenesisBlock.Header.Timestamp.Unix(),
449+
AsertDifficultyAnchorBits: regTestGenesisBlock.Header.Bits,
450+
GenerateSupported: true,
426451

427452
// Checkpoints ordered from oldest to newest.
428453
Checkpoints: nil,
@@ -494,19 +519,21 @@ var TestNet3Params = Params{
494519
GreatWallForkHeight: 1303884, // 00000000000001a749d7aa418c582a0e234ebc15643bf23a4f3107fa55120388
495520
GravitonForkHeight: 1341711, // 00000000c678f67ea16d5bf803f68ce42991839d13849f77332d6f586f62d421
496521
PhononForkHeight: 1378460, // 0000000070f33c64cb94629680fbc57d17bea354a73e693affcb366d023db324
497-
498-
AxionActivationTime: 1605441600,
499-
500-
CoinbaseMaturity: 100,
501-
SubsidyReductionInterval: 210000,
502-
TargetTimespan: time.Hour * 24 * 14, // 14 days
503-
TargetTimePerBlock: time.Minute * 10, // 10 minutes
504-
RetargetAdjustmentFactor: 4, // 25% less, 400% more
505-
ReduceMinDifficulty: true,
506-
NoDifficultyAdjustment: false,
507-
MinDiffReductionTime: time.Minute * 20, // TargetTimePerBlock * 2
508-
AsertDifficultyHalflife: 3600, // 1 hour
509-
GenerateSupported: false,
522+
AxionActivationHeight: 1421481, // 00000000062c7f32591d883c99fc89ebe74a83287c0f2b7ffeef72e62217d40b
523+
524+
CoinbaseMaturity: 100,
525+
SubsidyReductionInterval: 210000,
526+
TargetTimespan: time.Hour * 24 * 14, // 14 days
527+
TargetTimePerBlock: time.Minute * 10, // 10 minutes
528+
RetargetAdjustmentFactor: 4, // 25% less, 400% more
529+
ReduceMinDifficulty: true,
530+
NoDifficultyAdjustment: false,
531+
MinDiffReductionTime: time.Minute * 20, // TargetTimePerBlock * 2
532+
AsertDifficultyHalflife: 3600, // 1 hour
533+
AsertDifficultyAnchorHeight: 1421481,
534+
AsertDifficultyAnchorParentTimestamp: 1605445400,
535+
AsertDifficultyAnchorBits: 486604799,
536+
GenerateSupported: false,
510537

511538
// Checkpoints ordered from oldest to newest.
512539
Checkpoints: []Checkpoint{
@@ -523,6 +550,7 @@ var TestNet3Params = Params{
523550
{Height: 1000007, Hash: newHashFromStr("00000000001ccb893d8a1f25b70ad173ce955e5f50124261bbbc50379a612ddf")},
524551
{Height: 1341712, Hash: newHashFromStr("00000000fffc44ea2e202bd905a9fbbb9491ef9e9d5a9eed4039079229afa35b")},
525552
{Height: 1378461, Hash: newHashFromStr("0000000099f5509b5f36b1926bcf82b21d936ebeadee811030dfbbb7fae915d7")},
553+
{Height: 1421482, Hash: newHashFromStr("0000000023e0680a8a062b3cc289a4a341124ce7fcb6340ede207e194d73b60a")},
526554
},
527555

528556
// Consensus rule change deployments.
@@ -578,27 +606,31 @@ var SimNetParams = Params{
578606
DNSSeeds: []DNSSeed{}, // NOTE: There must NOT be any seeds.
579607

580608
// Chain parameters
581-
GenesisBlock: &simNetGenesisBlock,
582-
GenesisHash: &simNetGenesisHash,
583-
PowLimit: simNetPowLimit,
584-
PowLimitBits: 0x207fffff,
585-
BIP0034Height: 0, // Always active on simnet
586-
BIP0065Height: 0, // Always active on simnet
587-
BIP0066Height: 0, // Always active on simnet
588-
UahfForkHeight: 0, // Always active on simnet
589-
DaaForkHeight: 2000,
590-
MagneticAnonomalyForkHeight: 3000,
591-
GreatWallForkHeight: 0,
592-
CoinbaseMaturity: 100,
593-
SubsidyReductionInterval: 210000,
594-
TargetTimespan: time.Hour * 24 * 14, // 14 days
595-
TargetTimePerBlock: time.Minute * 10, // 10 minutes
596-
RetargetAdjustmentFactor: 4, // 25% less, 400% more
597-
ReduceMinDifficulty: true,
598-
NoDifficultyAdjustment: true,
599-
MinDiffReductionTime: time.Minute * 20, // TargetTimePerBlock * 2
600-
AsertDifficultyHalflife: 3600, // 1 hour
601-
GenerateSupported: true,
609+
GenesisBlock: &simNetGenesisBlock,
610+
GenesisHash: &simNetGenesisHash,
611+
PowLimit: simNetPowLimit,
612+
PowLimitBits: 0x207fffff,
613+
BIP0034Height: 0, // Always active on simnet
614+
BIP0065Height: 0, // Always active on simnet
615+
BIP0066Height: 0, // Always active on simnet
616+
UahfForkHeight: 0, // Always active on simnet
617+
DaaForkHeight: 2000,
618+
MagneticAnonomalyForkHeight: 3000,
619+
GreatWallForkHeight: 0,
620+
AxionActivationHeight: 4000,
621+
CoinbaseMaturity: 100,
622+
SubsidyReductionInterval: 210000,
623+
TargetTimespan: time.Hour * 24 * 14, // 14 days
624+
TargetTimePerBlock: time.Minute * 10, // 10 minutes
625+
RetargetAdjustmentFactor: 4, // 25% less, 400% more
626+
ReduceMinDifficulty: true,
627+
NoDifficultyAdjustment: true,
628+
MinDiffReductionTime: time.Minute * 20, // TargetTimePerBlock * 2
629+
AsertDifficultyHalflife: 3600, // 1 hour
630+
AsertDifficultyAnchorHeight: 0,
631+
AsertDifficultyAnchorParentTimestamp: simNetGenesisBlock.Header.Timestamp.Unix(),
632+
AsertDifficultyAnchorBits: simNetGenesisBlock.Header.Bits,
633+
GenerateSupported: true,
602634

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

server.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2274,12 +2274,12 @@ func (s *server) handleRelayInvMsg(state *peerState, msg relayMsg) {
22742274
// handleRelayCmpctBlock deals with direct relaying a compact block to
22752275
// peers which both want a compact block and accept direct relay.
22762276
func (s *server) handleRelayCmpctBlock(state *peerState, msg *wire.MsgCmpctBlock) {
2277+
blockHash := msg.BlockHash()
2278+
iv := wire.NewInvVect(wire.InvTypeBlock, &blockHash)
22772279
state.forAllPeers(func(sp *serverPeer) {
22782280
if sp.WantsCompactBlocks() && sp.WantsDirectBlockRelay() &&
2279-
sp.ProtocolVersion() >= wire.NoValidationRelayVersion {
2281+
sp.ProtocolVersion() >= wire.NoValidationRelayVersion && !sp.HasKnownInventory(iv) {
22802282

2281-
blockHash := msg.BlockHash()
2282-
iv := wire.NewInvVect(wire.InvTypeBlock, &blockHash)
22832283
sp.AddKnownInventory(iv)
22842284
sp.QueueMessage(msg, nil)
22852285
}

0 commit comments

Comments
 (0)