Merge pull request #1134 from harmony-ek/pie_reward

Pay a fixed total 30 Ones per block, split evenly
pull/1136/head
Eugene Kim 6 years ago committed by GitHub
commit c361c4fe9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 28
      consensus/consensus.go

@ -11,6 +11,7 @@ import (
"github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/harmony-one/bls/ffi/go/bls" "github.com/harmony-one/bls/ffi/go/bls"
"github.com/harmony-one/harmony/common/denominations" "github.com/harmony-one/harmony/common/denominations"
consensus_engine "github.com/harmony-one/harmony/consensus/engine" consensus_engine "github.com/harmony-one/harmony/consensus/engine"
"github.com/harmony-one/harmony/contracts/structs" "github.com/harmony-one/harmony/contracts/structs"
@ -26,11 +27,8 @@ import (
"github.com/harmony-one/harmony/p2p" "github.com/harmony-one/harmony/p2p"
) )
// Block reward per block signature. // BlockReward is the block reward, to be split evenly among block signers.
// TODO ek – per sig per stake var BlockReward = new(big.Int).Mul(big.NewInt(30), big.NewInt(denominations.One))
var (
BlockReward = big.NewInt(denominations.One / 10)
)
// Consensus is the main struct with all states and data related to consensus process. // Consensus is the main struct with all states and data related to consensus process.
type Consensus struct { type Consensus struct {
@ -341,21 +339,27 @@ func accumulateRewards(
return ctxerror.New("cannot set group sig mask bits").WithCause(err) return ctxerror.New("cannot set group sig mask bits").WithCause(err)
} }
totalAmount := big.NewInt(0) totalAmount := big.NewInt(0)
numAccounts := 0 var accounts []common.Address
signers := []string{} signers := []string{}
for idx, member := range parentCommittee.NodeList { for idx, member := range parentCommittee.NodeList {
if signed, err := mask.IndexEnabled(idx); err != nil { if signed, err := mask.IndexEnabled(idx); err != nil {
return ctxerror.New("cannot check for committer bit", return ctxerror.New("cannot check for committer bit",
"committerIndex", idx, "committerIndex", idx,
).WithCause(err) ).WithCause(err)
} else if !signed { } else if signed {
continue accounts = append(accounts, member.EcdsaAddress)
}
} }
numAccounts++ numAccounts := big.NewInt(int64(len(accounts)))
account := member.EcdsaAddress last := new(big.Int)
for i, account := range accounts {
cur := new(big.Int)
cur.Mul(BlockReward, big.NewInt(int64(i+1))).Div(cur, numAccounts)
diff := new(big.Int).Sub(cur, last)
signers = append(signers, common2.MustAddressToBech32(account)) signers = append(signers, common2.MustAddressToBech32(account))
state.AddBalance(account, BlockReward) state.AddBalance(account, diff)
totalAmount = new(big.Int).Add(totalAmount, BlockReward) totalAmount = new(big.Int).Add(totalAmount, diff)
last = cur
} }
getLogger().Debug("【Block Reward] Successfully paid out block reward", getLogger().Debug("【Block Reward] Successfully paid out block reward",
"NumAccounts", numAccounts, "NumAccounts", numAccounts,

Loading…
Cancel
Save