Skip to content

Commit

Permalink
implement montblanc hard fork (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
jed-wemade authored Sep 27, 2024
2 parents 255a595 + 797ee66 commit acc69f6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
4 changes: 4 additions & 0 deletions consensus/ethash/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
21 changes: 16 additions & 5 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand All @@ -529,6 +530,7 @@ func (c *ChainConfig) String() string {
c.PangyoBlock,
c.ApplepieBlock,
c.BriocheBlock,
c.MontBlancBlock,
c.TerminalTotalDifficulty,
c.Brioche,
engine,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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.
Expand All @@ -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),
}
}

0 comments on commit acc69f6

Please sign in to comment.