Skip to content

Commit

Permalink
Merge pull request ethereum#53 from etclabscore/feat/eip2124-forkid-c…
Browse files Browse the repository at this point in the history
…ompatibility-etclabscore

Feat/eip2124 forkid compatibility
  • Loading branch information
meowsbits authored Nov 15, 2019
2 parents 60add52 + b1f9561 commit 60fc05b
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 16 deletions.
2 changes: 1 addition & 1 deletion consensus/ethash/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ func accumulateRewards(config *params.ChainConfig, state *state.StateDB, header
musicoinBlockReward(config, state, header, uncles)
return
}
if config.HasECIP1017() {
if config.IsECIP1017F(header.Number) {
ecip1017BlockReward(config, state, header, uncles)
} else {
// Accumulate the rewards for the miner and any included uncles
Expand Down
35 changes: 35 additions & 0 deletions core/forkid/forkid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,38 @@ func TestEncoding(t *testing.T) {
}
}
}

func TestGatherForks(t *testing.T) {
cases := []struct {
config *params.ChainConfig
wantNs []uint64
}{
{
params.ClassicChainConfig,
[]uint64{1150000, 1920000, 2500000, 3000000, 5000000, 5900000, 8772000},
},
}
sliceContains := func (sl []uint64, u uint64) bool {
for _, s := range sl {
if s == u {
return true
}
}
return false
}
for ci, c := range cases {
gotForkNs := gatherForks(c.config)
if len(gotForkNs) != len(c.wantNs) {
for _, n := range c.wantNs {
if !sliceContains(gotForkNs, n) {
t.Errorf("config.i=%d missing wanted fork at block number: %d", ci, n)
}
}
for _, n := range gotForkNs {
if !sliceContains(c.wantNs, n) {
t.Errorf("config.i=%d gathered unwanted fork at block number: %d", ci, n)
}
}
}
}
}
31 changes: 16 additions & 15 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ var (

nil, // ECIP1010PauseBlock
nil, // ECIP1010Length
nil, // ECIP1017FBlock
nil, // ECIP1017EraRounds
nil, // DisposalBlock
nil, // SocialBlock
Expand Down Expand Up @@ -292,6 +293,7 @@ var (

nil, // ECIP1010PauseBlock
nil, // ECIP1010Length
nil, // ECIP1017FBlock
nil, // ECIP1017EraRounds
nil, // DisposalBlock
nil, // SocialBlock
Expand Down Expand Up @@ -353,6 +355,7 @@ var (

nil, // ECIP1010PauseBlock
nil, // ECIP1010Length
nil, // ECIP1017FBlock
nil, // ECIP1017EraRounds
nil, // DisposalBlock
nil, // SocialBlock
Expand Down Expand Up @@ -521,10 +524,11 @@ type ChainConfig struct {

ECIP1010PauseBlock *big.Int `json:"ecip1010PauseBlock,omitempty"` // ECIP1010 pause HF block
ECIP1010Length *big.Int `json:"ecip1010Length,omitempty"` // ECIP1010 length
ECIP1017EraRounds *big.Int `json:"ecip1017EraRounds,omitempty"` // ECIP1017 era rounds
DisposalBlock *big.Int `json:"disposalBlock,omitempty"` // Bomb disposal HF block
SocialBlock *big.Int `json:"socialBlock,omitempty"` // Ethereum Social Reward block
EthersocialBlock *big.Int `json:"ethersocialBlock,omitempty"` // Ethersocial Reward block
ECIP1017FBlock *big.Int `json:"ecip1017FBlock,omitempty"`
ECIP1017EraRounds *big.Int `json:"ecip1017EraRounds,omitempty"` // ECIP1017 era rounds
DisposalBlock *big.Int `json:"disposalBlock,omitempty"` // Bomb disposal HF block
SocialBlock *big.Int `json:"socialBlock,omitempty"` // Ethereum Social Reward block
EthersocialBlock *big.Int `json:"ethersocialBlock,omitempty"` // Ethersocial Reward block

MCIP0Block *big.Int `json:"mcip0Block,omitempty"` // Musicoin default block; no MCIP, just denotes chain pref
MCIP3Block *big.Int `json:"mcip3Block,omitempty"` // Musicoin 'UBI Fork' block
Expand Down Expand Up @@ -591,13 +595,9 @@ func (c *ChainConfig) String() string {
)
}

// HasECIP1017 returns whether the chain is configured with ECIP1017.
func (c *ChainConfig) HasECIP1017() bool {
if c.ECIP1017EraRounds == nil {
return false
} else {
return true
}
// IsECIP1017F returns whether the chain is configured with ECIP1017.
func (c *ChainConfig) IsECIP1017F(num *big.Int) bool {
return isForked(c.ECIP1017FBlock, num)
}

// IsEIP2F returns whether num is equal to or greater than the Homestead or EIP2 block.
Expand Down Expand Up @@ -899,10 +899,10 @@ type Rules struct {
// Byzantium
IsEIP100F, IsEIP140F, IsEIP198F, IsEIP211F, IsEIP212F, IsEIP213F, IsEIP214F, IsEIP649F, IsEIP658F bool
// Constantinople
IsEIP145F, IsEIP1014F, IsEIP1052F, IsEIP1283F, IsEIP1234F bool
IsPetersburg, IsIstanbul bool
IsBombDisposal, IsSocial, IsEthersocial, IsECIP1010 bool
IsMCIP0, IsMCIP3, IsMCIP8 bool
IsEIP145F, IsEIP1014F, IsEIP1052F, IsEIP1283F, IsEIP1234F bool
IsPetersburg, IsIstanbul bool
IsBombDisposal, IsSocial, IsEthersocial, IsECIP1010, IsECIP1017F bool
IsMCIP0, IsMCIP3, IsMCIP8 bool
}

// Rules ensures c's ChainID is not nil.
Expand Down Expand Up @@ -946,6 +946,7 @@ func (c *ChainConfig) Rules(num *big.Int) Rules {
IsSocial: c.IsSocial(num),
IsEthersocial: c.IsEthersocial(num),
IsECIP1010: c.IsECIP1010(num),
IsECIP1017F: c.IsECIP1017F(num),

IsMCIP0: c.IsMCIP0(num),
IsMCIP3: c.IsMCIP3(num),
Expand Down
1 change: 1 addition & 0 deletions params/config_classic.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var (
SocialBlock: nil,
EthersocialBlock: nil,
ConstantinopleBlock: nil,
ECIP1017FBlock: big.NewInt(5000000),
ECIP1017EraRounds: big.NewInt(5000000),
EIP160FBlock: big.NewInt(3000000),
ECIP1010PauseBlock: big.NewInt(3000000),
Expand Down
1 change: 1 addition & 0 deletions params/config_kotti.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ var (
DisposalBlock: big.NewInt(0),
SocialBlock: nil,
EthersocialBlock: nil,
ECIP1017FBlock: big.NewInt(5000000),
ECIP1017EraRounds: big.NewInt(5000000),
EIP160FBlock: big.NewInt(0),
ECIP1010PauseBlock: big.NewInt(0),
Expand Down
1 change: 1 addition & 0 deletions params/config_mordor.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var (
ConstantinopleBlock: big.NewInt(301243),
PetersburgBlock: big.NewInt(301243),
DisposalBlock: big.NewInt(0),
ECIP1017FBlock: big.NewInt(2000000),
ECIP1017EraRounds: big.NewInt(2000000),
EIP160FBlock: big.NewInt(0),
ECIP1010PauseBlock: big.NewInt(0),
Expand Down
1 change: 1 addition & 0 deletions params/config_social.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ var (
SocialBlock: big.NewInt(0),
EthersocialBlock: nil,
ConstantinopleBlock: nil,
ECIP1017FBlock: big.NewInt(5000000),
ECIP1017EraRounds: big.NewInt(5000000),
EIP160FBlock: big.NewInt(0),
Ethash: new(EthashConfig),
Expand Down

0 comments on commit 60fc05b

Please sign in to comment.