Commit cfa64635 authored by mdj33's avatar mdj33 Committed by vipwzw

update vote addrs by current nodes

parent 88c8c405
......@@ -98,6 +98,7 @@ function base_init() {
sed -i $sedfix 's/^minerdisable=.*/minerdisable=false/g' chain33.toml
sed -i $sedfix 's/^nodeGroupFrozenCoins=.*/nodeGroupFrozenCoins=20/g' chain33.toml
sed -i $sedfix 's/^paraConsensusStopBlocks=.*/paraConsensusStopBlocks=100/g' chain33.toml
# ticket
sed -i $sedfix 's/^ticketPrice =.*/ticketPrice = 10000/g' chain33.toml
......
......@@ -260,6 +260,19 @@ func (a *action) getNodesGroup(title string) (map[string]struct{}, error) {
return nodes, nil
}
//根据nodes过滤掉可能退出了的addrs
func updateCommitAddrs(stat *pt.ParacrossHeightStatus,nodes map[string]struct{}){
details := &pt.ParacrossStatusDetails{}
for i,addr := range stat.Details.Addrs{
if _,ok :=nodes[addr]; ok{
details.Addrs = append(details.Addrs, addr)
details.BlockHash = append(details.BlockHash, stat.Details.BlockHash[i])
}
}
stat.Details = details
}
func (a *action) Commit(commit *pt.ParacrossCommitAction) (*types.Receipt, error) {
err := checkCommitInfo(commit)
if err != nil {
......@@ -364,6 +377,11 @@ func (a *action) Commit(commit *pt.ParacrossCommitAction) (*types.Receipt, error
}
receipt = makeCommitReceipt(a.fromaddr, commit, &copyStat, stat)
}
if types.IsDappFork(commit.Status.MainBlockHeight, pt.ParaX, pt.ForkCommitTx){
updateCommitAddrs(stat,nodes)
}
clog.Info("paracross.Commit commit", "stat.title", stat.Title, "stat.height", stat.Height, "notes", len(nodes))
for i, v := range stat.Details.Addrs {
clog.Info("paracross.Commit commit detail", "addr", v, "hash", hex.EncodeToString(stat.Details.BlockHash[i]))
......
......@@ -395,12 +395,23 @@ func (a *action) superManagerVoteProc(title string) error {
//return err to stop tx pass to para chain
if a.height <= consensMainHeight+confStopBlocks {
return errors.Wrapf(pt.ErrParaConsensStopBlocksNotReach,
"supermanager height not reach,current:%d less consens:%d plus confStopBlocks:%s", a.height, consensMainHeight, confStopBlocks)
"supermanager height not reach,current:%d less consens:%d plus confStopBlocks:%d", a.height, consensMainHeight, confStopBlocks)
}
return nil
}
func updateVotes(stat *pt.ParaNodeIdStatus,nodes map[string]struct{}){
votes := &pt.ParaNodeVoteDetail{}
for i,addr := range stat.Votes.Addrs{
if _,ok :=nodes[addr]; ok{
votes.Addrs = append(votes.Addrs, addr)
votes.Votes = append(votes.Votes, stat.Votes.Votes[i])
}
}
stat.Votes = votes
}
func (a *action) nodeVote(config *pt.ParaNodeAddrConfig) (*types.Receipt, error) {
nodes, _, err := getParacrossNodes(a.db, config.Title)
if err != nil {
......@@ -436,6 +447,10 @@ func (a *action) nodeVote(config *pt.ParaNodeAddrConfig) (*types.Receipt, error)
stat.Votes.Addrs = append(stat.Votes.Addrs, a.fromaddr)
stat.Votes.Votes = append(stat.Votes.Votes, pt.ParaNodeVoteStr[config.Value])
}
//剔除已退出nodegroup的addr的投票
updateVotes(stat, nodes)
most, vote := getMostVote(stat)
if !isCommitDone(stat, nodes, most) {
superManagerPass := false
......
......@@ -352,3 +352,18 @@ func TestGetAddrGroup(t *testing.T) {
assert.Equal(t, 0, len(ret))
}
func TestUpdateVotes(t *testing.T){
stat := &pt.ParaNodeIdStatus{}
votes := &pt.ParaNodeVoteDetail{
Addrs:[]string{"AA","BB","CC"},
Votes:[]string{"yes","no","no"}}
stat.Votes = votes
nodes := make(map[string]struct{})
nodes["BB"]= struct{}{}
nodes["CC"] = struct{}{}
updateVotes(stat,nodes)
assert.Equal(t,[]string{"BB","CC"},stat.Votes.Addrs)
assert.Equal(t,[]string{"no","no"},stat.Votes.Votes)
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment