Skip to content

Commit

Permalink
consensus, params, wemix: pangyo hardfork, enforcing miner limit
Browse files Browse the repository at this point in the history
  • Loading branch information
sadoci committed Oct 25, 2022
1 parent 5767c2e commit 827963f
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion consensus/ethash/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ func (ethash *Ethash) verifyHeader(chain consensus.ChainHeaderReader, header, pa
return err
}
// 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) {
if !wemixminer.IsPoW() && !wemixminer.VerifyBlockSig(header.Number, header.Coinbase, header.MinerNodeId, header.Root, header.MinerNodeSig, chain.Config().IsPangyo(header.Number)) {
return consensus.ErrUnauthorized
}
return nil
Expand Down
16 changes: 13 additions & 3 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ var (
MuirGlacierBlock: big.NewInt(0),
BerlinBlock: big.NewInt(0),
LondonBlock: big.NewInt(0),
PangyoBlock: big.NewInt(0),
Ethash: new(EthashConfig),
}

Expand All @@ -174,6 +175,7 @@ var (
MuirGlacierBlock: big.NewInt(0),
BerlinBlock: big.NewInt(0),
LondonBlock: big.NewInt(0),
PangyoBlock: big.NewInt(1_000_000_000_000),
Ethash: new(EthashConfig),
}

Expand Down Expand Up @@ -297,16 +299,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, new(EthashConfig), 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, new(EthashConfig), 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, &CliqueConfig{Period: 0, Epoch: 30000}}
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, &CliqueConfig{Period: 0, Epoch: 30000}}

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, new(EthashConfig), 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, new(EthashConfig), nil}
TestRules = TestChainConfig.Rules(new(big.Int), false)
)

Expand Down Expand Up @@ -387,6 +389,7 @@ type ChainConfig struct {
LondonBlock *big.Int `json:"londonBlock,omitempty"` // London switch block (nil = no fork, 0 = already on london)
ArrowGlacierBlock *big.Int `json:"arrowGlacierBlock,omitempty"` // Eip-4345 (bomb delay) switch block (nil = no fork, 0 = already activated)
MergeForkBlock *big.Int `json:"mergeForkBlock,omitempty"` // EIP-3675 (TheMerge) switch block (nil = no fork, 0 = already in merge proceedings)
PangyoBlock *big.Int `json:"pangyoBlock,omitempty"` // Pangyo switch block (nil = no fork, 0 = already on pangyo)

// TerminalTotalDifficulty is the amount of total difficulty reached by
// the network that triggers the consensus upgrade.
Expand Down Expand Up @@ -510,6 +513,11 @@ func (c *ChainConfig) IsLondon(num *big.Int) bool {
return isForked(c.LondonBlock, num)
}

// IsPangyo returns whether num is either equal to the Pangyo fork block or greater.
func (c *ChainConfig) IsPangyo(num *big.Int) bool {
return isForked(c.PangyoBlock, num)
}

// IsArrowGlacier returns whether num is either equal to the Arrow Glacier (EIP-4345) fork block or greater.
func (c *ChainConfig) IsArrowGlacier(num *big.Int) bool {
return isForked(c.ArrowGlacierBlock, num)
Expand Down Expand Up @@ -714,6 +722,7 @@ type Rules struct {
IsByzantium, IsConstantinople, IsPetersburg, IsIstanbul bool
IsBerlin, IsLondon bool
IsMerge bool
IsPangyo bool
}

// Rules ensures c's ChainID is not nil.
Expand All @@ -735,5 +744,6 @@ func (c *ChainConfig) Rules(num *big.Int, isMerge bool) Rules {
IsBerlin: c.IsBerlin(num),
IsLondon: c.IsLondon(num),
IsMerge: isMerge,
IsPangyo: c.IsPangyo(num),
}
}
5 changes: 4 additions & 1 deletion wemix/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,7 @@ func signBlock(height *big.Int, hash common.Hash) (coinbase common.Address, sig
return
}

func verifyBlockSig(height *big.Int, coinbase common.Address, nodeId []byte, hash common.Hash, sig []byte) bool {
func verifyBlockSig(height *big.Int, coinbase common.Address, nodeId []byte, hash common.Hash, sig []byte, checkMinerLimit bool) bool {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

Expand Down Expand Up @@ -1178,6 +1178,9 @@ func verifyBlockSig(height *big.Int, coinbase common.Address, nodeId []byte, has
return false
}
// check miner limit
if !checkMinerLimit {
return true
}
ok, err := admin.verifyMinerLimit(ctx, height, gov, &coinbase, nodeId)
return err == nil && ok
}
Expand Down
6 changes: 3 additions & 3 deletions wemix/miner/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var (
CalculateRewardsFunc func(*big.Int, *big.Int, *big.Int, func(common.Address, *big.Int)) (*common.Address, []byte, error)
VerifyRewardsFunc func(*big.Int, string) error
SignBlockFunc func(height *big.Int, hash common.Hash) (coinbase common.Address, sig []byte, err error)
VerifyBlockSigFunc func(height *big.Int, coinbase common.Address, nodeId []byte, hash common.Hash, sig []byte) bool
VerifyBlockSigFunc func(height *big.Int, coinbase common.Address, nodeId []byte, hash common.Hash, sig []byte, checkMinerLimit bool) bool
RequirePendingTxsFunc func() bool
VerifyBlockRewardsFunc func(height *big.Int) interface{}
SuggestGasPriceFunc func() *big.Int
Expand Down Expand Up @@ -103,11 +103,11 @@ func SignBlock(height *big.Int, hash common.Hash) (coinbase common.Address, sig
return
}

func VerifyBlockSig(height *big.Int, coinbase common.Address, nodeId []byte, hash common.Hash, sig []byte) bool {
func VerifyBlockSig(height *big.Int, coinbase common.Address, nodeId []byte, hash common.Hash, sig []byte, checkMinerLimit bool) bool {
if VerifyBlockSigFunc == nil {
return false
} else {
return VerifyBlockSigFunc(height, coinbase, nodeId, hash, sig)
return VerifyBlockSigFunc(height, coinbase, nodeId, hash, sig, checkMinerLimit)
}
}

Expand Down
3 changes: 2 additions & 1 deletion wemix/scripts/genesis-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"constantinopleBlock": 0,
"istanbulBlock": 0,
"londonBlock": 0,
"muirGlacierBlock": 0
"muirGlacierBlock": 0,
"pangyoBlock": 0
}
}

0 comments on commit 827963f

Please sign in to comment.