@@ -38,23 +38,11 @@ import (
3838
3939// Ethash proof-of-work protocol constants.
4040var (
41- FrontierBlockReward = big .NewInt (5e+18 ) // Block reward in wei for successfully mining a block
42- EIP649FBlockReward = big .NewInt (3e+18 ) // Block reward in wei for successfully mining a block upward from Byzantium
43- EIP1234FBlockReward = big .NewInt (2e+18 ) // Block reward in wei for successfully mining a block upward from Constantinople
44- SocialBlockReward = new (big.Int ).Mul (big .NewInt (50 ), big .NewInt (1e+18 )) // Block reward in wei for successfully mining a block upward for Ethereum Social
45- EthersocialBlockReward = big .NewInt (5e+18 ) // Block reward in wei for successfully mining a block upward for Ethersocial Network
46- maxUncles = 2 // Maximum number of uncles allowed in a single block
47- allowedFutureBlockTime = 15 * time .Second // Max time from current time allowed for blocks, before they're considered future blocks
48- DisinflationRateQuotient = big .NewInt (4 ) // Disinflation rate quotient for ECIP1017
49- DisinflationRateDivisor = big .NewInt (5 ) // Disinflation rate divisor for ECIP1017
50- ExpDiffPeriod = big .NewInt (100000 ) // Exponential diff period for diff bomb & ECIP1010
51-
52- // Musicoin
53- Mcip0BlockReward = new (big.Int ).Mul (big .NewInt (314 ), big .NewInt (1e+18 )) // In musicoin code as 'FrontierBlockReward'
54- Mcip3BlockReward = new (big.Int ).Mul (big .NewInt (250 ), big .NewInt (1e+18 ))
55- Mcip8BlockReward = new (big.Int ).Mul (big .NewInt (50 ), big .NewInt (1e+18 ))
56- MusicoinUbiBlockReward = new (big.Int ).Mul (big .NewInt (50 ), big .NewInt (1e+18 ))
57- MusicoinDevBlockReward = new (big.Int ).Mul (big .NewInt (14 ), big .NewInt (1e+18 ))
41+ FrontierBlockReward = big .NewInt (5e+18 ) // Block reward in wei for successfully mining a block
42+ EIP649FBlockReward = big .NewInt (3e+18 ) // Block reward in wei for successfully mining a block upward from Byzantium
43+ EIP1234FBlockReward = big .NewInt (2e+18 ) // Block reward in wei for successfully mining a block upward from Constantinople
44+ maxUncles = 2 // Maximum number of uncles allowed in a single block
45+ allowedFutureBlockTime = 15 * time .Second // Max time from current time allowed for blocks, before they're considered future blocks
5846)
5947
6048// Various error messages to mark blocks invalid. These should be private to
@@ -407,15 +395,7 @@ func CalcDifficulty(config *params.ChainConfig, time uint64, parent *types.Heade
407395 exPeriodRef .Set (fakeBlockNumber )
408396
409397 } else if config .IsECIP1010 (next ) {
410- // https://github.com/ethereumproject/ECIPs/blob/master/ECIPs/ECIP-1010.md
411-
412- explosionBlock := new (big.Int ).Add (config .ECIP1010PauseBlock , config .ECIP1010Length )
413- if next .Cmp (explosionBlock ) < 0 {
414- exPeriodRef .Set (config .ECIP1010PauseBlock )
415- } else {
416- exPeriodRef .Sub (exPeriodRef , config .ECIP1010Length )
417- }
418-
398+ ecip1010Explosion (config , next , exPeriodRef )
419399 }
420400
421401 // EXPLOSION
@@ -426,8 +406,8 @@ func CalcDifficulty(config *params.ChainConfig, time uint64, parent *types.Heade
426406 // 2^(( periodRef // EDP) - 2)
427407 //
428408 x := new (big.Int )
429- x .Div (exPeriodRef , ExpDiffPeriod ) // (periodRef // EDP)
430- if x .Cmp (big1 ) > 0 { // if result large enough (not in algo explicitly)
409+ x .Div (exPeriodRef , params . ExpDiffPeriod ) // (periodRef // EDP)
410+ if x .Cmp (big1 ) > 0 { // if result large enough (not in algo explicitly)
431411 x .Sub (x , big2 ) // - 2
432412 x .Exp (big2 , x , nil ) // 2^
433413 } else {
@@ -590,65 +570,17 @@ func accumulateRewards(config *params.ChainConfig, state *state.StateDB, header
590570 blockReward = EIP1234FBlockReward
591571 }
592572 if config .IsSocial (header .Number ) {
593- blockReward = SocialBlockReward
573+ blockReward = params . SocialBlockReward
594574 }
595575 if config .IsEthersocial (header .Number ) {
596- blockReward = EthersocialBlockReward
576+ blockReward = params . EthersocialBlockReward
597577 }
598578 if config .IsMCIP0 (header .Number ) {
599- // Select the correct block reward based on chain progression
600- blockReward := Mcip0BlockReward
601- mcip3Reward := Mcip3BlockReward
602- mcip8Reward := Mcip8BlockReward
603- ubiReservoir := MusicoinUbiBlockReward
604- devReservoir := MusicoinDevBlockReward
605-
606- reward := new (big.Int ).Set (blockReward )
607-
608- if config .IsMCIP8 (header .Number ) {
609- state .AddBalance (header .Coinbase , mcip8Reward )
610- state .AddBalance (common .HexToAddress ("0x00eFdd5883eC628983E9063c7d969fE268BBf310" ), ubiReservoir )
611- state .AddBalance (common .HexToAddress ("0x00756cF8159095948496617F5FB17ED95059f536" ), devReservoir )
612- blockReward := mcip8Reward
613- reward := new (big.Int ).Set (blockReward )
614- _ = reward
615- } else if config .IsMCIP3 (header .Number ) {
616- state .AddBalance (header .Coinbase , mcip3Reward )
617- state .AddBalance (common .HexToAddress ("0x00eFdd5883eC628983E9063c7d969fE268BBf310" ), ubiReservoir )
618- state .AddBalance (common .HexToAddress ("0x00756cF8159095948496617F5FB17ED95059f536" ), devReservoir )
619- // no change to uncle reward during UBI fork, a mistake but now a legacy
620- } else {
621- state .AddBalance (header .Coinbase , reward )
622- }
623-
624- // Accumulate the rewards for the miner and any included uncles
625- r := new (big.Int )
626- for _ , uncle := range uncles {
627- r .Add (uncle .Number , big8 )
628- r .Sub (r , header .Number )
629- r .Mul (r , blockReward )
630- r .Div (r , big8 )
631- state .AddBalance (uncle .Coinbase , r )
632-
633- r .Div (blockReward , big32 )
634- reward .Add (reward , r )
635- }
579+ musicoinBlockReward (config , state , header , uncles )
636580 return
637581 }
638582 if config .HasECIP1017 () {
639- // Ensure value 'era' is configured.
640- eraLen := config .ECIP1017EraRounds
641- era := GetBlockEra (header .Number , eraLen )
642- wr := GetBlockWinnerRewardByEra (era , blockReward ) // wr "winner reward". 5, 4, 3.2, 2.56, ...
643- wurs := GetBlockWinnerRewardForUnclesByEra (era , uncles , blockReward ) // wurs "winner uncle rewards"
644- wr .Add (wr , wurs )
645- state .AddBalance (header .Coinbase , wr ) // $$
646-
647- // Reward uncle miners.
648- for _ , uncle := range uncles {
649- ur := GetBlockUncleRewardByEra (era , header , uncle , blockReward )
650- state .AddBalance (uncle .Coinbase , ur ) // $$
651- }
583+ ecip1017BlockReward (config , state , header , uncles )
652584 } else {
653585 // Accumulate the rewards for the miner and any included uncles
654586 reward := new (big.Int ).Set (blockReward )
@@ -712,28 +644,11 @@ func GetBlockWinnerRewardByEra(era *big.Int, blockReward *big.Int) *big.Int {
712644 // qed
713645 var q , d , r * big.Int = new (big.Int ), new (big.Int ), new (big.Int )
714646
715- q .Exp (DisinflationRateQuotient , era , nil )
716- d .Exp (DisinflationRateDivisor , era , nil )
647+ q .Exp (params . DisinflationRateQuotient , era , nil )
648+ d .Exp (params . DisinflationRateDivisor , era , nil )
717649
718650 r .Mul (blockReward , q )
719651 r .Div (r , d )
720652
721653 return r
722654}
723-
724- // GetBlockEra gets which "Era" a given block is within, given an era length (ecip-1017 has era=5,000,000 blocks)
725- // Returns a zero-index era number, so "Era 1": 0, "Era 2": 1, "Era 3": 2 ...
726- func GetBlockEra (blockNum , eraLength * big.Int ) * big.Int {
727- // If genesis block or impossible negative-numbered block, return zero-val.
728- if blockNum .Sign () < 1 {
729- return new (big.Int )
730- }
731-
732- remainder := big .NewInt (0 ).Mod (big .NewInt (0 ).Sub (blockNum , big .NewInt (1 )), eraLength )
733- base := big .NewInt (0 ).Sub (blockNum , remainder )
734-
735- d := big .NewInt (0 ).Div (base , eraLength )
736- dremainder := big .NewInt (0 ).Mod (d , big .NewInt (1 ))
737-
738- return new (big.Int ).Sub (d , dremainder )
739- }
0 commit comments