Skip to content

Commit 521f0e6

Browse files
authored
feat: implement montblanc hard fork (#136)
* feat: disable starting mining after mont blanc fork * feat: disable mining after mont blanc fork * feat: remove dead code * feat: commit/verify block generated at fork time considering as SPoA * Revert "feat: commit/verify block generated at fork time considering as SPoA" This reverts commit 3dc94fd. * chore: change err msgs
1 parent 255a595 commit 521f0e6

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

consensus/ethash/consensus.go

+4
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,10 @@ func (ethash *Ethash) verifyHeader(chain consensus.ChainHeaderReader, header, pa
319319
if err := misc.VerifyForkHashes(chain.Config(), header, uncle); err != nil {
320320
return err
321321
}
322+
// Wemix: Verify SPoA block
323+
if chain.Config().IsMontBlanc(header.Number) {
324+
return fmt.Errorf("go-wemix does not support blocks after MontBlanc hard fork")
325+
}
322326
// Wemix: Check if it's generated and signed by a registered node
323327
if !wemixminer.IsPoW() && !wemixminer.VerifyBlockSig(header.Number, header.Coinbase, header.MinerNodeId, header.Root, header.MinerNodeSig, chain.Config().IsPangyo(header.Number)) {
324328
return consensus.ErrUnauthorized

miner/worker.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -1595,9 +1595,14 @@ func (w *worker) commitWork(interrupt *int32, noempty bool, timestamp int64) {
15951595
} else {
15961596
return
15971597
}
1598+
parent := w.chain.CurrentBlock()
1599+
height := new(big.Int).Add(parent.Number(), common.Big1)
1600+
// Wemix: Skip blocks after MontBlanc hard fork
1601+
if w.chain.Config().IsMontBlanc(height) {
1602+
log.Warn("go-wemix skips mining due to MontBlanc hard fork", "height", height, "parent-hash", parent.Hash())
1603+
return
1604+
}
15981605
if !wemixminer.IsPoW() {
1599-
parent := w.chain.CurrentBlock()
1600-
height := new(big.Int).Add(parent.Number(), common.Big1)
16011606
ok, err := wemixminer.AcquireMiningToken(height, parent.Hash())
16021607
if ok {
16031608
log.Debug("Mining Token, successful", "height", height, "parent-hash", parent.Hash())

params/config.go

+16-5
Original file line numberDiff line numberDiff line change
@@ -321,16 +321,16 @@ var (
321321
//
322322
// This configuration is intentionally not using keyed fields to force anyone
323323
// adding flags to the config to also have to set these fields.
324-
AllEthashProtocolChanges = &ChainConfig{big.NewInt(1337), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, nil, nil, nil, new(EthashConfig), nil, nil}
324+
AllEthashProtocolChanges = &ChainConfig{big.NewInt(1337), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, nil, nil, nil, nil, new(EthashConfig), nil, nil}
325325

326326
// AllCliqueProtocolChanges contains every protocol change (EIPs) introduced
327327
// and accepted by the Ethereum core developers into the Clique consensus.
328328
//
329329
// This configuration is intentionally not using keyed fields to force anyone
330330
// adding flags to the config to also have to set these fields.
331-
AllCliqueProtocolChanges = &ChainConfig{big.NewInt(1337), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, nil, nil, nil, nil, nil, &CliqueConfig{Period: 0, Epoch: 30000}, nil}
331+
AllCliqueProtocolChanges = &ChainConfig{big.NewInt(1337), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, nil, nil, nil, nil, nil, nil, &CliqueConfig{Period: 0, Epoch: 30000}, nil}
332332

333-
TestChainConfig = &ChainConfig{big.NewInt(1), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, nil, nil, nil, new(EthashConfig), nil, nil}
333+
TestChainConfig = &ChainConfig{big.NewInt(1), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, nil, nil, nil, nil, new(EthashConfig), nil, nil}
334334
TestRules = TestChainConfig.Rules(new(big.Int), false)
335335
)
336336

@@ -414,6 +414,7 @@ type ChainConfig struct {
414414
PangyoBlock *big.Int `json:"pangyoBlock,omitempty"` // Pangyo switch block (nil = no fork, 0 = already on pangyo)
415415
ApplepieBlock *big.Int `json:"applepieBlock,omitempty"` // Applepie switch block (nil = no fork, 0 = already on applepie)
416416
BriocheBlock *big.Int `json:"briocheBlock,omitempty"` // Brioche switch block (nil = no fork, 0 = already on brioche)
417+
MontBlancBlock *big.Int `json:"montBlancBlock,omitempty"` // MontBlanc switch block (nil = no fork, 0 = already on MontBlanc)
417418

418419
// TerminalTotalDifficulty is the amount of total difficulty reached by
419420
// the network that triggers the consensus upgrade.
@@ -509,7 +510,7 @@ func (c *ChainConfig) String() string {
509510
default:
510511
engine = "unknown"
511512
}
512-
return fmt.Sprintf("{ChainID: %v Homestead: %v DAO: %v DAOSupport: %v EIP150: %v EIP155: %v EIP158: %v Byzantium: %v Constantinople: %v Petersburg: %v Istanbul: %v, Muir Glacier: %v, Berlin: %v, London: %v, Arrow Glacier: %v, MergeFork: %v, PangyoFork: %v, ApplepieFork: %v, BriocheFork: %v, Terminal TD: %v, BriocheConfig: %v, Engine: %v}",
513+
return fmt.Sprintf("{ChainID: %v Homestead: %v DAO: %v DAOSupport: %v EIP150: %v EIP155: %v EIP158: %v Byzantium: %v Constantinople: %v Petersburg: %v Istanbul: %v, Muir Glacier: %v, Berlin: %v, London: %v, Arrow Glacier: %v, MergeFork: %v, PangyoFork: %v, ApplepieFork: %v, BriocheFork: %v, MontBlancFork: %v, Terminal TD: %v, BriocheConfig: %v, Engine: %v}",
513514
c.ChainID,
514515
c.HomesteadBlock,
515516
c.DAOForkBlock,
@@ -529,6 +530,7 @@ func (c *ChainConfig) String() string {
529530
c.PangyoBlock,
530531
c.ApplepieBlock,
531532
c.BriocheBlock,
533+
c.MontBlancBlock,
532534
c.TerminalTotalDifficulty,
533535
c.Brioche,
534536
engine,
@@ -617,6 +619,10 @@ func (c *ChainConfig) IsBrioche(num *big.Int) bool {
617619
return isForked(c.BriocheBlock, num)
618620
}
619621

622+
func (c *ChainConfig) IsMontBlanc(num *big.Int) bool {
623+
return isForked(c.MontBlancBlock, num)
624+
}
625+
620626
// IsTerminalPoWBlock returns whether the given block is the last block of PoW stage.
621627
func (c *ChainConfig) IsTerminalPoWBlock(parentTotalDiff *big.Int, totalDiff *big.Int) bool {
622628
if c.TerminalTotalDifficulty == nil {
@@ -675,6 +681,7 @@ func (c *ChainConfig) CheckConfigForkOrder() error {
675681
{name: "pangyoBlock", block: c.PangyoBlock, optional: true},
676682
{name: "applepieBlock", block: c.ApplepieBlock, optional: true},
677683
{name: "briocheBlock", block: c.BriocheBlock, optional: true},
684+
{name: "montBlancBlock", block: c.MontBlancBlock, optional: true},
678685
} {
679686
if lastFork.name != "" {
680687
// Next one must be higher number
@@ -759,6 +766,9 @@ func (c *ChainConfig) checkCompatible(newcfg *ChainConfig, head *big.Int) *Confi
759766
if isForkIncompatible(c.BriocheBlock, newcfg.BriocheBlock, head) {
760767
return newCompatError("Brioche fork block", c.BriocheBlock, newcfg.BriocheBlock)
761768
}
769+
if isForkIncompatible(c.MontBlancBlock, newcfg.MontBlancBlock, head) {
770+
return newCompatError("Mont Blanc fork block", c.MontBlancBlock, newcfg.MontBlancBlock)
771+
}
762772
return nil
763773
}
764774

@@ -828,7 +838,7 @@ type Rules struct {
828838
IsByzantium, IsConstantinople, IsPetersburg, IsIstanbul bool
829839
IsBerlin, IsLondon bool
830840
IsMerge bool
831-
IsPangyo, IsApplepie, IsBrioche bool
841+
IsPangyo, IsApplepie, IsBrioche, IsMontBlanc bool
832842
}
833843

834844
// Rules ensures c's ChainID is not nil.
@@ -853,5 +863,6 @@ func (c *ChainConfig) Rules(num *big.Int, isMerge bool) Rules {
853863
IsPangyo: c.IsPangyo(num),
854864
IsApplepie: c.IsApplepie(num),
855865
IsBrioche: c.IsBrioche(num),
866+
IsMontBlanc: c.IsMontBlanc(num),
856867
}
857868
}

0 commit comments

Comments
 (0)