From d458de58196547d9055b6aeab98dc4529117ffff Mon Sep 17 00:00:00 2001 From: CoderZhi Date: Mon, 4 Mar 2019 17:25:45 -0800 Subject: [PATCH] update Gopkg.toml and update dependencies (#662) --- Gopkg.lock | 4 +- Gopkg.toml | 2 +- .../iotex-election/carrier/carrier.go | 7 +- .../iotex-election/committee/committee.go | 4 +- .../iotex-election/pb/election/election.pb.go | 76 +++++++++---------- .../iotex-election/pb/election/election.proto | 2 +- .../iotex-election/types/candidate.go | 24 +++--- .../iotex-election/types/resultcalculator.go | 19 +++-- 8 files changed, 70 insertions(+), 68 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index bba40b6d2b..30164d48f0 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -291,7 +291,7 @@ revision = "c26edc20f3d7c9ed16b6d996d162548cda979673" [[projects]] - digest = "1:3ee7e5f97219c5339fbce8b99caf1cc2598752da03383c851dd37a921c7ad037" + digest = "1:5238206d7c2d37d30d7f3998967c67fb38d05cf5074432ec150d8140401b878c" name = "github.com/iotexproject/iotex-election" packages = [ "carrier", @@ -304,7 +304,7 @@ "util", ] pruneopts = "UT" - revision = "7a4ae1ee8eadfa5126c3bc0f3215642fa2481e01" + revision = "dd4ecf3f1ea87b252258e4999432b90c4bda9095" [[projects]] digest = "1:9999472bf9c934426d967c507d61f2de84affb8318b8d8c8bc38b3486edbd826" diff --git a/Gopkg.toml b/Gopkg.toml index c0cf38f77f..418ade1fcf 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -60,7 +60,7 @@ [[constraint]] name = "github.com/iotexproject/iotex-election" - revision = "7a4ae1ee8eadfa5126c3bc0f3215642fa2481e01" + revision = "dd4ecf3f1ea87b252258e4999432b90c4bda9095" [prune] go-tests = true diff --git a/vendor/github.com/iotexproject/iotex-election/carrier/carrier.go b/vendor/github.com/iotexproject/iotex-election/carrier/carrier.go index 9216489286..8991f84bbe 100644 --- a/vendor/github.com/iotexproject/iotex-election/carrier/carrier.go +++ b/vendor/github.com/iotexproject/iotex-election/carrier/carrier.go @@ -48,7 +48,7 @@ type ethereumCarrier struct { // NewEthereumVoteCarrier defines a carrier to fetch votes from ethereum contract func NewEthereumVoteCarrier( - clientURLs []string, + clientURLs []string, registerContractAddress common.Address, stakingContractAddress common.Address, ) (Carrier, error) { @@ -177,12 +177,11 @@ func (evc *ethereumCarrier) Votes( return nil, nil, err } votes := []*types.Vote{} - num := len(buckets.Indexes) - if num == 0 { + if buckets.Count.Cmp(big.NewInt(0)) == 0 { return previousIndex, votes, nil } for i, index := range buckets.Indexes { - if big.NewInt(0).Cmp(index) == 0 { // back to start + if big.NewInt(0).Cmp(index) == 0 { // back to start, this is a redundant condition break } v, err := types.NewVote( diff --git a/vendor/github.com/iotexproject/iotex-election/committee/committee.go b/vendor/github.com/iotexproject/iotex-election/committee/committee.go index b0e32b9baa..d411d208c0 100644 --- a/vendor/github.com/iotexproject/iotex-election/committee/committee.go +++ b/vendor/github.com/iotexproject/iotex-election/committee/committee.go @@ -293,7 +293,7 @@ func (ec *committee) calcWeightedVotes(v *types.Vote, now time.Time) *big.Int { remainingTime := v.RemainingTime(now).Seconds() weight := float64(1) if remainingTime > 0 { - weight += math.Log(math.Ceil(remainingTime/86400)) / math.Log(1.2) + weight += math.Log(math.Ceil(remainingTime/86400)) / math.Log(1.2) / 100 } amount := new(big.Float).SetInt(v.Amount()) weightedAmount, _ := amount.Mul(amount, big.NewFloat(weight)).Int(nil) @@ -319,7 +319,7 @@ func (ec *committee) fetchResultByHeight(height uint64) (*types.ElectionResult, }, ec.calcWeightedVotes, func(c *types.Candidate) bool { - return ec.selfStakingThreshold.Cmp(c.SelfStakingScore()) > 0 && + return ec.selfStakingThreshold.Cmp(c.SelfStakingTokens()) > 0 && ec.scoreThreshold.Cmp(c.Score()) > 0 }, ) diff --git a/vendor/github.com/iotexproject/iotex-election/pb/election/election.pb.go b/vendor/github.com/iotexproject/iotex-election/pb/election/election.pb.go index a7e07c9fa1..95c89bfb91 100644 --- a/vendor/github.com/iotexproject/iotex-election/pb/election/election.pb.go +++ b/vendor/github.com/iotexproject/iotex-election/pb/election/election.pb.go @@ -37,7 +37,7 @@ func (m *Vote) Reset() { *m = Vote{} } func (m *Vote) String() string { return proto.CompactTextString(m) } func (*Vote) ProtoMessage() {} func (*Vote) Descriptor() ([]byte, []int) { - return fileDescriptor_election_21f2608efdfaacd8, []int{0} + return fileDescriptor_election_018c69c978718965, []int{0} } func (m *Vote) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Vote.Unmarshal(m, b) @@ -117,7 +117,7 @@ func (m *VoteList) Reset() { *m = VoteList{} } func (m *VoteList) String() string { return proto.CompactTextString(m) } func (*VoteList) ProtoMessage() {} func (*VoteList) Descriptor() ([]byte, []int) { - return fileDescriptor_election_21f2608efdfaacd8, []int{1} + return fileDescriptor_election_018c69c978718965, []int{1} } func (m *VoteList) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_VoteList.Unmarshal(m, b) @@ -151,7 +151,7 @@ type Candidate struct { RewardAddress []byte `protobuf:"bytes,4,opt,name=rewardAddress,proto3" json:"rewardAddress,omitempty"` SelfStakingWeight uint64 `protobuf:"varint,5,opt,name=selfStakingWeight,proto3" json:"selfStakingWeight,omitempty"` Score []byte `protobuf:"bytes,6,opt,name=score,proto3" json:"score,omitempty"` - SelfStakingScore []byte `protobuf:"bytes,7,opt,name=selfStakingScore,proto3" json:"selfStakingScore,omitempty"` + SelfStakingTokens []byte `protobuf:"bytes,7,opt,name=selfStakingTokens,proto3" json:"selfStakingTokens,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -161,7 +161,7 @@ func (m *Candidate) Reset() { *m = Candidate{} } func (m *Candidate) String() string { return proto.CompactTextString(m) } func (*Candidate) ProtoMessage() {} func (*Candidate) Descriptor() ([]byte, []int) { - return fileDescriptor_election_21f2608efdfaacd8, []int{2} + return fileDescriptor_election_018c69c978718965, []int{2} } func (m *Candidate) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Candidate.Unmarshal(m, b) @@ -223,9 +223,9 @@ func (m *Candidate) GetScore() []byte { return nil } -func (m *Candidate) GetSelfStakingScore() []byte { +func (m *Candidate) GetSelfStakingTokens() []byte { if m != nil { - return m.SelfStakingScore + return m.SelfStakingTokens } return nil } @@ -243,7 +243,7 @@ func (m *ElectionResult) Reset() { *m = ElectionResult{} } func (m *ElectionResult) String() string { return proto.CompactTextString(m) } func (*ElectionResult) ProtoMessage() {} func (*ElectionResult) Descriptor() ([]byte, []int) { - return fileDescriptor_election_21f2608efdfaacd8, []int{3} + return fileDescriptor_election_018c69c978718965, []int{3} } func (m *ElectionResult) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_ElectionResult.Unmarshal(m, b) @@ -291,35 +291,35 @@ func init() { proto.RegisterType((*ElectionResult)(nil), "election.ElectionResult") } -func init() { proto.RegisterFile("election.proto", fileDescriptor_election_21f2608efdfaacd8) } - -var fileDescriptor_election_21f2608efdfaacd8 = []byte{ - // 423 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x92, 0x4d, 0x6f, 0xd3, 0x40, - 0x10, 0x86, 0xe5, 0x24, 0xcd, 0xc7, 0xb4, 0x0d, 0x30, 0x20, 0xb4, 0x44, 0x08, 0xa2, 0xa8, 0x42, - 0x16, 0x42, 0x2e, 0x14, 0x21, 0xf5, 0x5a, 0x01, 0x37, 0x4e, 0xdb, 0xaa, 0x9c, 0xb7, 0xd9, 0xa9, - 0xb1, 0xb0, 0xbd, 0xd1, 0xee, 0x9a, 0x88, 0x23, 0xbf, 0x8a, 0xdf, 0xc6, 0x0d, 0x79, 0xd6, 0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x88, 0x96, 0xc3, 0xf8, 0xf8, 0x62, 0x9e, 0x74, 0xea, 0x6b, 0x24, 0x68, - 0x71, 0xab, 0x3f, 0x11, 0xcc, 0x3e, 0x76, 0x1a, 0x10, 0x46, 0xa5, 0x2a, 0xa8, 0x31, 0xc7, 0xdf, - 0x28, 0x60, 0xa2, 0xb4, 0xb6, 0xe4, 0x5c, 0xa3, 0xad, 0x8d, 0x18, 0xc3, 0x03, 0xb3, 0x21, 0xab, - 0xbc, 0xb1, 0x57, 0x0d, 0x11, 0xec, 0xed, 0x97, 0xf1, 0x0c, 0x4e, 0x2d, 0x6d, 0x95, 0xd5, 0x2d, - 0x17, 0x2c, 0xee, 0x16, 0xf1, 0x0d, 0x3c, 0x72, 0x94, 0xdf, 0x5f, 0x7b, 0xf5, 0x3d, 0x2b, 0xd3, - 0xaf, 0x6c, 0x98, 0x65, 0x8e, 0xe4, 0x61, 0xa3, 0x36, 0xe0, 0xd6, 0xc6, 0x12, 0x5b, 0x3b, 0x91, - 0x21, 0xe0, 0x6b, 0x78, 0xf8, 0x0f, 0x7a, 0xcd, 0xc0, 0x84, 0x81, 0x83, 0xfa, 0xea, 0x77, 0x04, - 0xf3, 0xcf, 0x8d, 0x14, 0x49, 0xae, 0xca, 0xf9, 0x8e, 0xdd, 0x7f, 0xc5, 0x16, 0xfe, 0x73, 0xc7, - 0x0e, 0xc6, 0x77, 0x30, 0xd3, 0x94, 0x53, 0xaa, 0x6a, 0xe5, 0x03, 0x56, 0xfe, 0xb8, 0x57, 0xde, - 0x29, 0x96, 0x3d, 0x85, 0x97, 0x70, 0xda, 0x86, 0x5b, 0xbe, 0xd4, 0x90, 0xc7, 0x70, 0xf7, 0x52, - 0xf5, 0x31, 0xe5, 0x2e, 0x78, 0x37, 0xe6, 0x5d, 0xde, 0xff, 0x0d, 0x00, 0x00, 0xff, 0xff, 0x4a, - 0x70, 0x7d, 0x14, 0x4f, 0x03, 0x00, 0x00, +func init() { proto.RegisterFile("election.proto", fileDescriptor_election_018c69c978718965) } + +var fileDescriptor_election_018c69c978718965 = []byte{ + // 424 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x92, 0x4f, 0x6f, 0xd3, 0x40, + 0x10, 0xc5, 0xe5, 0x24, 0x4d, 0x93, 0x69, 0x1a, 0xc4, 0x80, 0xd0, 0x12, 0x21, 0x88, 0xa2, 0x0a, + 0xf9, 0x80, 0x5c, 0x28, 0x42, 0xea, 0xb5, 0x02, 0x6e, 0x9c, 0x96, 0xa8, 0x9c, 0xb7, 0xd9, 0xa9, + 0xb1, 0x6a, 0x7b, 0xa3, 0xdd, 0x0d, 0x11, 0x47, 0x3e, 0x15, 0x1f, 0x8e, 0x0b, 0xf2, 0xac, 0xff, + 0x28, 0xce, 0xa1, 0xb7, 0xbc, 0x79, 0x6f, 0xa2, 0xd9, 0xdf, 0x33, 0xcc, 0x29, 0xa7, 0x8d, 0xcf, + 0x4c, 0x99, 0x6c, 0xad, 0xf1, 0x06, 0x27, 0x8d, 0x5e, 0xbc, 0x4e, 0x8d, 0x49, 0x73, 0xba, 0xe4, + 0xf9, 0xdd, 0xee, 0xfe, 0x52, 0xef, 0xac, 0xea, 0x92, 0x8b, 0x37, 0x7d, 0xdf, 0x67, 0x05, 0x39, + 0xaf, 0x8a, 0x6d, 0x08, 0xac, 0xfe, 0x0c, 0x60, 0x74, 0x6b, 0x3c, 0xe1, 0x73, 0x38, 0xf9, 0x65, + 0x3c, 0x59, 0x11, 0x2d, 0xa3, 0x78, 0x26, 0x83, 0xc0, 0x57, 0x30, 0xdd, 0xa8, 0x52, 0x67, 0x5a, + 0x79, 0x12, 0x03, 0x76, 0xba, 0x01, 0xbe, 0x80, 0xb1, 0x2a, 0xcc, 0xae, 0xf4, 0x62, 0xc8, 0x56, + 0xad, 0xf0, 0x2d, 0xcc, 0xf7, 0x94, 0xa5, 0x3f, 0x3d, 0xe9, 0x9b, 0x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9, 0xd7, 0x1a, 0x8b, 0x24, 0xb7, 0xcb, 0xb9, 0xc9, 0xf6, 0xcb, 0x62, 0x0e, 0x8f, 0x34, + 0xd9, 0x86, 0xf1, 0x03, 0x4c, 0x35, 0xe5, 0x94, 0xaa, 0x0a, 0xfa, 0x80, 0xa1, 0x3f, 0xeb, 0xa0, + 0xb7, 0x90, 0x65, 0x97, 0xc2, 0x6b, 0x38, 0x6f, 0xc4, 0x2d, 0x77, 0x35, 0xe4, 0x35, 0x3c, 0xec, + 0xaa, 0xaa, 0x53, 0x1e, 0x06, 0xef, 0xc6, 0x7c, 0xcb, 0xc7, 0xff, 0x01, 0x00, 0x00, 0xff, 0xff, + 0x19, 0x3c, 0x3f, 0x64, 0x51, 0x03, 0x00, 0x00, } diff --git a/vendor/github.com/iotexproject/iotex-election/pb/election/election.proto b/vendor/github.com/iotexproject/iotex-election/pb/election/election.proto index 2a8d3d7d31..c091f8ff23 100644 --- a/vendor/github.com/iotexproject/iotex-election/pb/election/election.proto +++ b/vendor/github.com/iotexproject/iotex-election/pb/election/election.proto @@ -33,7 +33,7 @@ message Candidate { bytes rewardAddress = 4; uint64 selfStakingWeight = 5; bytes score = 6; - bytes selfStakingScore = 7; + bytes selfStakingTokens = 7; } message ElectionResult { diff --git a/vendor/github.com/iotexproject/iotex-election/types/candidate.go b/vendor/github.com/iotexproject/iotex-election/types/candidate.go index 2b5d09e0f2..9432bbfc0c 100644 --- a/vendor/github.com/iotexproject/iotex-election/types/candidate.go +++ b/vendor/github.com/iotexproject/iotex-election/types/candidate.go @@ -22,7 +22,7 @@ type Candidate struct { operatorAddress []byte rewardAddress []byte score *big.Int - selfStakingScore *big.Int + selfStakingTokens *big.Int selfStakingWeight uint64 } @@ -40,7 +40,7 @@ func NewCandidate( operatorAddress: util.CopyBytes(operatorAddress), rewardAddress: util.CopyBytes(rewardPubKey), score: big.NewInt(0), - selfStakingScore: big.NewInt(0), + selfStakingTokens: big.NewInt(0), selfStakingWeight: selfStakingWeight, } } @@ -53,7 +53,7 @@ func (c *Candidate) Clone() *Candidate { operatorAddress: c.OperatorAddress(), rewardAddress: c.RewardAddress(), score: c.Score(), - selfStakingScore: c.SelfStakingScore(), + selfStakingTokens: c.SelfStakingTokens(), selfStakingWeight: c.SelfStakingWeight(), } } @@ -80,14 +80,14 @@ func (c *Candidate) equal(candidate *Candidate) bool { if c.score.Cmp(candidate.score) != 0 { return false } - if c.selfStakingScore.Cmp(candidate.selfStakingScore) != 0 { + if c.selfStakingTokens.Cmp(candidate.selfStakingTokens) != 0 { return false } return c.selfStakingWeight == candidate.selfStakingWeight } func (c *Candidate) reset() *Candidate { - c.selfStakingScore.SetInt64(0) + c.selfStakingTokens.SetInt64(0) c.score.SetInt64(0) return c } @@ -100,11 +100,11 @@ func (c *Candidate) addScore(s *big.Int) error { return nil } -func (c *Candidate) addSelfStakingScore(s *big.Int) error { +func (c *Candidate) addSelfStakingTokens(s *big.Int) error { if s.Cmp(big.NewInt(0)) < 0 { return errors.New("score cannot be negative") } - c.selfStakingScore.Add(c.selfStakingScore, s) + c.selfStakingTokens.Add(c.selfStakingTokens, s) return nil } @@ -133,9 +133,9 @@ func (c *Candidate) Score() *big.Int { return new(big.Int).Set(c.score) } -// SelfStakingScore returns the total self votes (weighted) -func (c *Candidate) SelfStakingScore() *big.Int { - return new(big.Int).Set(c.selfStakingScore) +// SelfStakingTokens returns the total self votes (weighted) +func (c *Candidate) SelfStakingTokens() *big.Int { + return new(big.Int).Set(c.selfStakingTokens) } // SelfStakingWeight returns the extra weight for self staking @@ -151,7 +151,7 @@ func (c *Candidate) ToProtoMsg() (*pb.Candidate, error) { OperatorAddress: c.OperatorAddress(), RewardAddress: c.RewardAddress(), Score: c.score.Bytes(), - SelfStakingScore: c.selfStakingScore.Bytes(), + SelfStakingTokens: c.selfStakingTokens.Bytes(), SelfStakingWeight: c.selfStakingWeight, }, nil } @@ -163,7 +163,7 @@ func (c *Candidate) FromProtoMsg(msg *pb.Candidate) error { c.operatorAddress = util.CopyBytes(msg.GetOperatorAddress()) c.rewardAddress = util.CopyBytes(msg.GetRewardAddress()) c.score = new(big.Int).SetBytes(msg.GetScore()) - c.selfStakingScore = new(big.Int).SetBytes(msg.GetSelfStakingScore()) + c.selfStakingTokens = new(big.Int).SetBytes(msg.GetSelfStakingTokens()) c.selfStakingWeight = msg.GetSelfStakingWeight() return nil diff --git a/vendor/github.com/iotexproject/iotex-election/types/resultcalculator.go b/vendor/github.com/iotexproject/iotex-election/types/resultcalculator.go index 9f50b998ff..84e42daafc 100644 --- a/vendor/github.com/iotexproject/iotex-election/types/resultcalculator.go +++ b/vendor/github.com/iotexproject/iotex-election/types/resultcalculator.go @@ -34,18 +34,18 @@ func (p itemList) Len() int { return len(p) } func (p itemList) Less(i, j int) bool { switch p[i].Value.Cmp(p[j].Value) { case -1: - return true - case 1: return false + case 1: + return true } switch { - case p[i].Priority > p[j].Priority: - return false case p[i].Priority < p[j].Priority: + return false + case p[i].Priority > p[j].Priority: return true } // This is a corner case, which rarely happens. - return strings.Compare(p[i].Key, p[j].Key) < 0 + return strings.Compare(p[i].Key, p[j].Key) > 0 } // VoteFilterFunc defines the function to filter vote @@ -129,10 +129,13 @@ func (calculator *ResultCalculator) AddVotes(votes []*Vote) error { } score := calculator.calcScore(v, calculator.mintTime) if bytes.Equal(v.Voter(), candidate.address) { - score.Mul(score, big.NewInt(int64(candidate.selfStakingWeight))) - if err := candidate.addSelfStakingScore(score); err != nil { + amount := v.Amount() + selfStakingWeight := new(big.Int).SetUint64(candidate.selfStakingWeight) + amount.Mul(amount, selfStakingWeight) + if err := candidate.addSelfStakingTokens(amount); err != nil { return err } + score.Mul(score, selfStakingWeight) } cVote := v.Clone() if err := cVote.SetWeightedAmount(score); err != nil { @@ -179,7 +182,7 @@ func (calculator *ResultCalculator) filterAndSortCandidates() []string { priority := blake2b.Sum256(append([]byte(name), tsBytes...)) p[num] = item{ Key: name, - Value: candidate.selfStakingScore, + Value: candidate.score, Priority: util.BytesToUint64(priority[:8]), } num++