diff --git a/consensus/ethash/consensus.go b/consensus/ethash/consensus.go index 5a0efda8bfff..1d857e1f9ff3 100644 --- a/consensus/ethash/consensus.go +++ b/consensus/ethash/consensus.go @@ -319,6 +319,10 @@ func (ethash *Ethash) verifyHeader(chain consensus.ChainHeaderReader, header, pa if err := misc.VerifyForkHashes(chain.Config(), header, uncle); err != nil { return err } + // Wemix: Verify SPoA block + if chain.Config().IsMontBlanc(header.Number) { + return fmt.Errorf("go-wemix does not support blocks after MontBlanc hard fork") + } // Wemix: Check if it's generated and signed by a registered node if !wemixminer.IsPoW() && !wemixminer.VerifyBlockSig(header.Number, header.Coinbase, header.MinerNodeId, header.Root, header.MinerNodeSig, chain.Config().IsPangyo(header.Number)) { return consensus.ErrUnauthorized diff --git a/miner/worker.go b/miner/worker.go index 364bf034970f..bd49dd676304 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -1595,9 +1595,14 @@ func (w *worker) commitWork(interrupt *int32, noempty bool, timestamp int64) { } else { return } + parent := w.chain.CurrentBlock() + height := new(big.Int).Add(parent.Number(), common.Big1) + // Wemix: Skip blocks after MontBlanc hard fork + if w.chain.Config().IsMontBlanc(height) { + log.Warn("go-wemix skips mining due to MontBlanc hard fork", "height", height, "parent-hash", parent.Hash()) + return + } if !wemixminer.IsPoW() { - parent := w.chain.CurrentBlock() - height := new(big.Int).Add(parent.Number(), common.Big1) ok, err := wemixminer.AcquireMiningToken(height, parent.Hash()) if ok { log.Debug("Mining Token, successful", "height", height, "parent-hash", parent.Hash()) diff --git a/params/config.go b/params/config.go index c86356c663ad..c7dfdb78617b 100644 --- a/params/config.go +++ b/params/config.go @@ -321,16 +321,16 @@ var ( // // This configuration is intentionally not using keyed fields to force anyone // adding flags to the config to also have to set these fields. - 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} + 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} // AllCliqueProtocolChanges contains every protocol change (EIPs) introduced // and accepted by the Ethereum core developers into the Clique consensus. // // This configuration is intentionally not using keyed fields to force anyone // adding flags to the config to also have to set these fields. - 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} + 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} - 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} + 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} TestRules = TestChainConfig.Rules(new(big.Int), false) ) @@ -414,6 +414,7 @@ type ChainConfig struct { PangyoBlock *big.Int `json:"pangyoBlock,omitempty"` // Pangyo switch block (nil = no fork, 0 = already on pangyo) ApplepieBlock *big.Int `json:"applepieBlock,omitempty"` // Applepie switch block (nil = no fork, 0 = already on applepie) BriocheBlock *big.Int `json:"briocheBlock,omitempty"` // Brioche switch block (nil = no fork, 0 = already on brioche) + MontBlancBlock *big.Int `json:"montBlancBlock,omitempty"` // MontBlanc switch block (nil = no fork, 0 = already on MontBlanc) // TerminalTotalDifficulty is the amount of total difficulty reached by // the network that triggers the consensus upgrade. @@ -509,7 +510,7 @@ func (c *ChainConfig) String() string { default: engine = "unknown" } - 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}", + 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}", c.ChainID, c.HomesteadBlock, c.DAOForkBlock, @@ -529,6 +530,7 @@ func (c *ChainConfig) String() string { c.PangyoBlock, c.ApplepieBlock, c.BriocheBlock, + c.MontBlancBlock, c.TerminalTotalDifficulty, c.Brioche, engine, @@ -617,6 +619,10 @@ func (c *ChainConfig) IsBrioche(num *big.Int) bool { return isForked(c.BriocheBlock, num) } +func (c *ChainConfig) IsMontBlanc(num *big.Int) bool { + return isForked(c.MontBlancBlock, num) +} + // IsTerminalPoWBlock returns whether the given block is the last block of PoW stage. func (c *ChainConfig) IsTerminalPoWBlock(parentTotalDiff *big.Int, totalDiff *big.Int) bool { if c.TerminalTotalDifficulty == nil { @@ -675,6 +681,7 @@ func (c *ChainConfig) CheckConfigForkOrder() error { {name: "pangyoBlock", block: c.PangyoBlock, optional: true}, {name: "applepieBlock", block: c.ApplepieBlock, optional: true}, {name: "briocheBlock", block: c.BriocheBlock, optional: true}, + {name: "montBlancBlock", block: c.MontBlancBlock, optional: true}, } { if lastFork.name != "" { // Next one must be higher number @@ -759,6 +766,9 @@ func (c *ChainConfig) checkCompatible(newcfg *ChainConfig, head *big.Int) *Confi if isForkIncompatible(c.BriocheBlock, newcfg.BriocheBlock, head) { return newCompatError("Brioche fork block", c.BriocheBlock, newcfg.BriocheBlock) } + if isForkIncompatible(c.MontBlancBlock, newcfg.MontBlancBlock, head) { + return newCompatError("Mont Blanc fork block", c.MontBlancBlock, newcfg.MontBlancBlock) + } return nil } @@ -828,7 +838,7 @@ type Rules struct { IsByzantium, IsConstantinople, IsPetersburg, IsIstanbul bool IsBerlin, IsLondon bool IsMerge bool - IsPangyo, IsApplepie, IsBrioche bool + IsPangyo, IsApplepie, IsBrioche, IsMontBlanc bool } // Rules ensures c's ChainID is not nil. @@ -853,5 +863,6 @@ func (c *ChainConfig) Rules(num *big.Int, isMerge bool) Rules { IsPangyo: c.IsPangyo(num), IsApplepie: c.IsApplepie(num), IsBrioche: c.IsBrioche(num), + IsMontBlanc: c.IsMontBlanc(num), } }