mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-19 21:31:37 +00:00
Won't grasp txs at checkpoint
This commit is contained in:
parent
95041650e8
commit
4a6e8c7f5d
9 changed files with 109 additions and 15 deletions
|
|
@ -156,6 +156,12 @@ func makeConfigNode(ctx *cli.Context) (*node.Node, XDCConfig) {
|
|||
if ctx.GlobalBool(utils.XDCTestnetFlag.Name) {
|
||||
common.IsTestnet = true
|
||||
}
|
||||
|
||||
// Check rollback hash exist.
|
||||
if rollbackHash := ctx.GlobalString(utils.RollbackFlag.Name); rollbackHash != "" {
|
||||
common.RollbackHash = common.HexToHash(rollbackHash)
|
||||
}
|
||||
|
||||
// read passwords from enviroment
|
||||
passwords := []string{}
|
||||
for _, env := range cfg.Account.Passwords {
|
||||
|
|
|
|||
|
|
@ -123,6 +123,7 @@ var (
|
|||
configFileFlag,
|
||||
utils.AnnounceTxsFlag,
|
||||
utils.StoreRewardFlag,
|
||||
utils.RollbackFlag,
|
||||
}
|
||||
|
||||
rpcFlags = []cli.Flag{
|
||||
|
|
|
|||
|
|
@ -110,6 +110,12 @@ func NewApp(gitCommit, usage string) *cli.App {
|
|||
// are the same for all commands.
|
||||
|
||||
var (
|
||||
// XDC flags.
|
||||
RollbackFlag = cli.StringFlag{
|
||||
Name: "rollback",
|
||||
Usage: "Rollback chain at hash",
|
||||
Value: "",
|
||||
}
|
||||
// General settings
|
||||
AnnounceTxsFlag = cli.BoolFlag{
|
||||
Name: "announce-txs",
|
||||
|
|
|
|||
|
|
@ -22,4 +22,5 @@ const (
|
|||
|
||||
var TIP2019Block = big.NewInt(1050000)
|
||||
var IsTestnet bool = false
|
||||
var StoreRewardFolder string
|
||||
var StoreRewardFolder string
|
||||
var RollbackHash Hash
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
package contracts
|
||||
|
||||
//
|
||||
//import (
|
||||
// "fmt"
|
||||
|
|
|
|||
|
|
@ -2,18 +2,19 @@ package validator
|
|||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"math/big"
|
||||
"math/rand"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
||||
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/contracts"
|
||||
"github.com/ethereum/go-ethereum/contracts/validator/contract"
|
||||
contractValidator "github.com/ethereum/go-ethereum/contracts/validator/contract"
|
||||
"github.com/ethereum/go-ethereum/core"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"math/rand"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
@ -79,7 +80,7 @@ func TestRewardBalance(t *testing.T) {
|
|||
// validatorAddr, _, baseValidator, err := contract.DeployXDCValidator(transactOpts, contractBackend, big.NewInt(50000), big.NewInt(99), big.NewInt(100), big.NewInt(100))
|
||||
validatorCap := new(big.Int)
|
||||
validatorCap.SetString("50000000000000000000000", 10)
|
||||
validatorAddr, _, baseValidator, err := contract.DeployXDCValidator(
|
||||
validatorAddr, _, baseValidator, err := contractValidator.DeployXDCValidator(
|
||||
transactOpts,
|
||||
contractBackend,
|
||||
[]common.Address{addr},
|
||||
|
|
@ -129,7 +130,7 @@ func TestRewardBalance(t *testing.T) {
|
|||
|
||||
foundationAddr := common.HexToAddress(common.FoudationAddr)
|
||||
totalReward := new(big.Int).SetInt64(15 * 1000)
|
||||
rewards, err := contracts.GetRewardBalancesRate(foundationAddr, acc3Addr, totalReward, baseValidator)
|
||||
rewards, err := GetRewardBalancesRate(foundationAddr, acc3Addr, totalReward, baseValidator)
|
||||
if err != nil {
|
||||
t.Error("Fail to get reward balances rate.", err)
|
||||
}
|
||||
|
|
@ -159,4 +160,77 @@ func TestRewardBalance(t *testing.T) {
|
|||
t.Errorf("reward total %v - %v", totalReward, afterReward)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func GetRewardBalancesRate(foudationWalletAddr common.Address, masterAddr common.Address, totalReward *big.Int, validator *contractValidator.XDCValidator) (map[common.Address]*big.Int, error) {
|
||||
owner := GetCandidatesOwnerBySigner(validator, masterAddr)
|
||||
balances := make(map[common.Address]*big.Int)
|
||||
rewardMaster := new(big.Int).Mul(totalReward, new(big.Int).SetInt64(common.RewardMasterPercent))
|
||||
rewardMaster = new(big.Int).Div(rewardMaster, new(big.Int).SetInt64(100))
|
||||
balances[owner] = rewardMaster
|
||||
// Get voters for masternode.
|
||||
opts := new(bind.CallOpts)
|
||||
voters, err := validator.GetVoters(opts, masterAddr)
|
||||
if err != nil {
|
||||
log.Crit("Fail to get voters", "error", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(voters) > 0 {
|
||||
totalVoterReward := new(big.Int).Mul(totalReward, new(big.Int).SetUint64(common.RewardVoterPercent))
|
||||
totalVoterReward = new(big.Int).Div(totalVoterReward, new(big.Int).SetUint64(100))
|
||||
totalCap := new(big.Int)
|
||||
// Get voters capacities.
|
||||
voterCaps := make(map[common.Address]*big.Int)
|
||||
for _, voteAddr := range voters {
|
||||
var voterCap *big.Int
|
||||
|
||||
voterCap, err = validator.GetVoterCap(opts, masterAddr, voteAddr)
|
||||
if err != nil {
|
||||
log.Crit("Fail to get vote capacity", "error", err)
|
||||
}
|
||||
|
||||
totalCap.Add(totalCap, voterCap)
|
||||
voterCaps[voteAddr] = voterCap
|
||||
}
|
||||
if totalCap.Cmp(new(big.Int).SetInt64(0)) > 0 {
|
||||
for addr, voteCap := range voterCaps {
|
||||
// Only valid voter has cap > 0.
|
||||
if voteCap.Cmp(new(big.Int).SetInt64(0)) > 0 {
|
||||
rcap := new(big.Int).Mul(totalVoterReward, voteCap)
|
||||
rcap = new(big.Int).Div(rcap, totalCap)
|
||||
if balances[addr] != nil {
|
||||
balances[addr].Add(balances[addr], rcap)
|
||||
} else {
|
||||
balances[addr] = rcap
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foudationReward := new(big.Int).Mul(totalReward, new(big.Int).SetInt64(common.RewardFoundationPercent))
|
||||
foudationReward = new(big.Int).Div(foudationReward, new(big.Int).SetInt64(100))
|
||||
balances[foudationWalletAddr] = foudationReward
|
||||
|
||||
jsonHolders, err := json.Marshal(balances)
|
||||
if err != nil {
|
||||
log.Error("Fail to parse json holders", "error", err)
|
||||
return nil, err
|
||||
}
|
||||
log.Info("Holders reward", "holders", string(jsonHolders), "master node", masterAddr.String())
|
||||
|
||||
return balances, nil
|
||||
}
|
||||
|
||||
func GetCandidatesOwnerBySigner(validator *contractValidator.XDCValidator, signerAddr common.Address) common.Address {
|
||||
owner := signerAddr
|
||||
opts := new(bind.CallOpts)
|
||||
owner, err := validator.GetCandidateOwner(opts, signerAddr)
|
||||
if err != nil {
|
||||
log.Error("Fail get candidate owner", "error", err)
|
||||
return owner
|
||||
}
|
||||
|
||||
return owner
|
||||
}
|
||||
|
|
@ -10,7 +10,7 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
slotValidatorMapping = map[string]uint64{
|
||||
slotValidatorMapping = map[string]uint64{
|
||||
"withdrawsState": 0,
|
||||
"validatorsState": 1,
|
||||
"voters": 2,
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -583,13 +583,18 @@ func (self *worker) commitNewWork() {
|
|||
if self.config.DAOForkSupport && self.config.DAOForkBlock != nil && self.config.DAOForkBlock.Cmp(header.Number) == 0 {
|
||||
misc.ApplyDAOHardFork(work.state)
|
||||
}
|
||||
pending, err := self.eth.TxPool().Pending()
|
||||
if err != nil {
|
||||
log.Error("Failed to fetch pending transactions", "err", err)
|
||||
return
|
||||
specialTxCount := 0
|
||||
// won't grasp txs at checkpoint
|
||||
if self.config.XDPoS != nil && header.Number.Uint64() % self.config.XDPoS.Epoch != 0 {
|
||||
pending, err := self.eth.TxPool().Pending()
|
||||
if err != nil {
|
||||
log.Error("Failed to fetch pending transactions", "err", err)
|
||||
return
|
||||
}
|
||||
txs, specialTxs := types.NewTransactionsByPriceAndNonce(self.current.signer, pending, signers)
|
||||
specialTxCount = len(specialTxs)
|
||||
work.commitTransactions(self.mux, txs, specialTxs, self.chain, self.coinbase)
|
||||
}
|
||||
txs, specialTxs := types.NewTransactionsByPriceAndNonce(self.current.signer, pending, signers)
|
||||
work.commitTransactions(self.mux, txs, specialTxs, self.chain, self.coinbase)
|
||||
|
||||
// compute uncles for the new block.
|
||||
var (
|
||||
|
|
@ -621,7 +626,7 @@ func (self *worker) commitNewWork() {
|
|||
return
|
||||
}
|
||||
if atomic.LoadInt32(&self.mining) == 1 {
|
||||
log.Info("Committing new block", "number", work.Block.Number(), "txs", work.tcount, "special txs", len(specialTxs), "uncles", len(uncles), "elapsed", common.PrettyDuration(time.Since(tstart)))
|
||||
log.Info("Committing new block", "number", work.Block.Number(), "txs", work.tcount, "special-txs", specialTxCount, "uncles", len(uncles), "elapsed", common.PrettyDuration(time.Since(tstart)))
|
||||
self.unconfirmed.Shift(work.Block.NumberU64() - 1)
|
||||
self.lastParentBlockCommit = parent.Hash().Hex()
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue