Skip to content

Commit

Permalink
Merge pull request #1 from calehh/master
Browse files Browse the repository at this point in the history
Add clique consensus block signer reward
  • Loading branch information
xl9211 authored Mar 30, 2023
2 parents bfac726 + bb71c1c commit 65aefd7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
17 changes: 17 additions & 0 deletions consensus/clique/clique.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ var (

diffInTurn = big.NewInt(2) // Block difficulty for in-turn signatures
diffNoTurn = big.NewInt(1) // Block difficulty for out-of-turn signatures

FrontierBlockReward = big.NewInt(5e+18) // Block reward in wei for successfully mining a block
ByzantiumBlockReward = big.NewInt(5e+18) // Block reward in wei for successfully mining a block upward from Byzantium
ConstantinopleBlockReward = big.NewInt(5e+18) // Block reward in wei for successfully mining a block upward from Constantinople
)

// Various error messages to mark blocks invalid. These should be private to
Expand Down Expand Up @@ -565,11 +569,24 @@ func (c *Clique) Prepare(chain consensus.ChainHeaderReader, header *types.Header
// Finalize implements consensus.Engine, ensuring no uncles are set, nor block
// rewards given.
func (c *Clique) Finalize(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header) {
number := header.Number.Uint64()
if number != 0 {
rewardCollector := c.config.RewardCollector
accumulateRewards(chain.Config(), state, header, uncles, rewardCollector)
}

// No block rewards in PoA, so the state remains as is and uncles are dropped
header.Root = state.IntermediateRoot(chain.Config().IsEIP158(header.Number))
header.UncleHash = types.CalcUncleHash(nil)
}

func accumulateRewards(config *params.ChainConfig, state *state.StateDB, header *types.Header, uncles []*types.Header, signer common.Address) {
// Select the correct block reward based on chain progression
blockReward := FrontierBlockReward
reward := new(big.Int).Set(blockReward)
state.AddBalance(signer, reward)
}

// FinalizeAndAssemble implements consensus.Engine, ensuring no uncles are set,
// nor block rewards given, and returns the final block.
func (c *Clique) FinalizeAndAssemble(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header, receipts []*types.Receipt) (*types.Block, error) {
Expand Down
1 change: 1 addition & 0 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ func (c *EthashConfig) String() string {
type CliqueConfig struct {
Period uint64 `json:"period"` // Number of seconds between blocks to enforce
Epoch uint64 `json:"epoch"` // Epoch length to reset votes and checkpoint
RewardCollector common.Address `json:"reward"`
}

// String implements the stringer interface, returning the consensus engine details.
Expand Down

0 comments on commit 65aefd7

Please sign in to comment.