mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
ubqhash/consensus: refactor CalcDifficulty and accumilateRewards
This commit is contained in:
parent
ae9861e56a
commit
fd3a68bd34
1 changed files with 7 additions and 6 deletions
|
|
@ -257,7 +257,7 @@ func (ubqhash *Ubqhash) verifyHeader(chain consensus.ChainReader, header, parent
|
||||||
return errZeroBlockTime
|
return errZeroBlockTime
|
||||||
}
|
}
|
||||||
// Verify the block's difficulty based in it's timestamp and parent's difficulty
|
// Verify the block's difficulty based in it's timestamp and parent's difficulty
|
||||||
expected := CalcDifficulty(chain, header.Time, parent)
|
expected := ubqhash.CalcDifficulty(chain, header.Time, parent)
|
||||||
|
|
||||||
if expected.Cmp(header.Difficulty) != 0 {
|
if expected.Cmp(header.Difficulty) != 0 {
|
||||||
return fmt.Errorf("invalid difficulty: have %v, want %v", header.Difficulty, expected)
|
return fmt.Errorf("invalid difficulty: have %v, want %v", header.Difficulty, expected)
|
||||||
|
|
@ -385,8 +385,10 @@ func maxActualTimespanFlux(dampen bool) *big.Int {
|
||||||
// CalcDifficulty is the difficulty adjustment algorithm. It returns the difficulty
|
// CalcDifficulty is the difficulty adjustment algorithm. It returns the difficulty
|
||||||
// that a new block should have when created at time given the parent block's time
|
// that a new block should have when created at time given the parent block's time
|
||||||
// and difficulty.
|
// and difficulty.
|
||||||
//
|
func (ubqhash *Ubqhash) CalcDifficulty(chain consensus.ChainReader, time uint64, parent *types.Header) *big.Int {
|
||||||
// TODO (karalabe): Move the chain maker into this package and make this private!
|
return CalcDifficulty(chain, time, parent)
|
||||||
|
}
|
||||||
|
|
||||||
func CalcDifficulty(chain consensus.ChainReader, time uint64, parent *types.Header) *big.Int {
|
func CalcDifficulty(chain consensus.ChainReader, time uint64, parent *types.Header) *big.Int {
|
||||||
parentTime := parent.Time
|
parentTime := parent.Time
|
||||||
parentNumber := parent.Number
|
parentNumber := parent.Number
|
||||||
|
|
@ -664,7 +666,7 @@ func (ubqhash *Ubqhash) Prepare(chain consensus.ChainReader, header *types.Heade
|
||||||
// setting the final state and assembling the block.
|
// setting the final state and assembling the block.
|
||||||
func (ubqhash *Ubqhash) Finalize(chain consensus.ChainReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header, receipts []*types.Receipt) (*types.Block, error) {
|
func (ubqhash *Ubqhash) Finalize(chain consensus.ChainReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header, receipts []*types.Receipt) (*types.Block, error) {
|
||||||
// Accumulate any block and uncle rewards and commit the final state root
|
// Accumulate any block and uncle rewards and commit the final state root
|
||||||
AccumulateRewards(state, header, uncles)
|
accumulateRewards(state, header, uncles)
|
||||||
header.Root = state.IntermediateRoot(chain.Config().IsEIP158(header.Number))
|
header.Root = state.IntermediateRoot(chain.Config().IsEIP158(header.Number))
|
||||||
|
|
||||||
// Header seems complete, assemble into a block and return
|
// Header seems complete, assemble into a block and return
|
||||||
|
|
@ -704,8 +706,7 @@ func (ubqhash *Ubqhash) SealHash(header *types.Header) (hash common.Hash) {
|
||||||
// AccumulateRewards credits the coinbase of the given block with the mining
|
// AccumulateRewards credits the coinbase of the given block with the mining
|
||||||
// reward. The total reward consists of the static block reward and rewards for
|
// reward. The total reward consists of the static block reward and rewards for
|
||||||
// included uncles. The coinbase of each uncle block is also rewarded.
|
// included uncles. The coinbase of each uncle block is also rewarded.
|
||||||
// TODO (karalabe): Move the chain maker into this package and make this private!
|
func accumulateRewards(state *state.StateDB, header *types.Header, uncles []*types.Header) {
|
||||||
func AccumulateRewards(state *state.StateDB, header *types.Header, uncles []*types.Header) {
|
|
||||||
reward := new(big.Int).Set(blockReward)
|
reward := new(big.Int).Set(blockReward)
|
||||||
|
|
||||||
if header.Number.Cmp(big.NewInt(358363)) > 0 {
|
if header.Number.Cmp(big.NewInt(358363)) > 0 {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue