mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
Fixed minor warning of go lint and rename checkpoint config parameter.
This commit is contained in:
parent
0d59fa3408
commit
7b74ed6bf5
3 changed files with 14 additions and 14 deletions
|
|
@ -105,7 +105,7 @@ func (w *wizard) makeGenesis() {
|
||||||
|
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
fmt.Println("How many blocks per checkpoint? (default = 990)")
|
fmt.Println("How many blocks per checkpoint? (default = 990)")
|
||||||
genesis.Config.Clique.Checkpoint = uint64(w.readDefaultInt(990))
|
genesis.Config.Clique.RewardCheckpoint = uint64(w.readDefaultInt(990))
|
||||||
|
|
||||||
default:
|
default:
|
||||||
log.Crit("Invalid consensus engine choice", "choice", choice)
|
log.Crit("Invalid consensus engine choice", "choice", choice)
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"encoding/json"
|
||||||
"github.com/ethereum/go-ethereum/accounts"
|
"github.com/ethereum/go-ethereum/accounts"
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||||
|
|
@ -40,7 +41,6 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/rlp"
|
"github.com/ethereum/go-ethereum/rlp"
|
||||||
"github.com/ethereum/go-ethereum/rpc"
|
"github.com/ethereum/go-ethereum/rpc"
|
||||||
"github.com/hashicorp/golang-lru"
|
"github.com/hashicorp/golang-lru"
|
||||||
"encoding/json"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
@ -386,7 +386,7 @@ func position(list []common.Address, x common.Address) int {
|
||||||
}
|
}
|
||||||
|
|
||||||
func YourTurn(snap *Snapshot, header *types.Header, cur common.Address) (bool, error) {
|
func YourTurn(snap *Snapshot, header *types.Header, cur common.Address) (bool, error) {
|
||||||
if (header.Number.Uint64() == 0) {
|
if header.Number.Uint64() == 0 {
|
||||||
// Not check signer for genesis block.
|
// Not check signer for genesis block.
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
@ -724,19 +724,19 @@ func (c *Clique) APIs(chain consensus.ChainReader) []rpc.API {
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Clique) accumulateRewards(chain consensus.ChainReader, state *state.StateDB, header *types.Header) (error) {
|
func (c *Clique) accumulateRewards(chain consensus.ChainReader, state *state.StateDB, header *types.Header) error {
|
||||||
type rewardLog struct {
|
type rewardLog struct {
|
||||||
Sign uint64 `json:"sign"`
|
Sign uint64 `json:"sign"`
|
||||||
Reward float64 `json:"reward"`
|
Reward float64 `json:"reward"`
|
||||||
}
|
}
|
||||||
|
|
||||||
number := header.Number.Uint64()
|
number := header.Number.Uint64()
|
||||||
checkpoint := chain.Config().Clique.Checkpoint
|
rCheckpoint := chain.Config().Clique.RewardCheckpoint
|
||||||
|
|
||||||
if number > 0 && number%checkpoint == 0 {
|
if number > 0 && rCheckpoint > 0 && number%rCheckpoint == 0 {
|
||||||
// Not reward for singer of genesis block and only calculate reward at checkpoint block.
|
// Not reward for singer of genesis block and only calculate reward at checkpoint block.
|
||||||
parentHeader := chain.GetHeaderByHash(header.ParentHash)
|
parentHeader := chain.GetHeaderByHash(header.ParentHash)
|
||||||
startBlockNumber := number - checkpoint + 1
|
startBlockNumber := number - rCheckpoint + 1
|
||||||
endBlockNumber := parentHeader.Number.Uint64()
|
endBlockNumber := parentHeader.Number.Uint64()
|
||||||
signers := make(map[common.Address]*rewardLog)
|
signers := make(map[common.Address]*rewardLog)
|
||||||
totalSigner := uint64(0)
|
totalSigner := uint64(0)
|
||||||
|
|
@ -759,10 +759,10 @@ func (c *Clique) accumulateRewards(chain consensus.ChainReader, state *state.Sta
|
||||||
chainReward := new(big.Int).SetUint64(chain.Config().Clique.Reward * params.Ether)
|
chainReward := new(big.Int).SetUint64(chain.Config().Clique.Reward * params.Ether)
|
||||||
// Update balance reward.
|
// Update balance reward.
|
||||||
calcReward := new(big.Int)
|
calcReward := new(big.Int)
|
||||||
for signer, log := range signers {
|
for signer, rLog := range signers {
|
||||||
calcReward.Mul(chainReward, new(big.Int).SetUint64(log.Sign))
|
calcReward.Mul(chainReward, new(big.Int).SetUint64(rLog.Sign))
|
||||||
calcReward.Div(calcReward, new(big.Int).SetUint64(totalSigner))
|
calcReward.Div(calcReward, new(big.Int).SetUint64(totalSigner))
|
||||||
log.Reward = float64(calcReward.Int64())
|
rLog.Reward = float64(calcReward.Int64())
|
||||||
|
|
||||||
state.AddBalance(signer, calcReward)
|
state.AddBalance(signer, calcReward)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -136,7 +136,7 @@ type CliqueConfig struct {
|
||||||
Period uint64 `json:"period"` // Number of seconds between blocks to enforce
|
Period uint64 `json:"period"` // Number of seconds between blocks to enforce
|
||||||
Epoch uint64 `json:"epoch"` // Epoch length to reset votes and checkpoint
|
Epoch uint64 `json:"epoch"` // Epoch length to reset votes and checkpoint
|
||||||
Reward uint64 `json:"reward"` // Block reward - unit Ether
|
Reward uint64 `json:"reward"` // Block reward - unit Ether
|
||||||
Checkpoint uint64 `json:"checkpoint"` // Checkpoint block for calculate rewards.
|
RewardCheckpoint uint64 `json:"rewardCheckpoint"` // Checkpoint block for calculate rewards.
|
||||||
}
|
}
|
||||||
|
|
||||||
// String implements the stringer interface, returning the consensus engine details.
|
// String implements the stringer interface, returning the consensus engine details.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue