diff --git a/cmd/bfa_client/bfa_client.go b/cmd/bfa_client/bfa_client.go index 9c152e51c1fb4f6ab2580eeef2a5078b2205260d..ad2feaa7a85309c2fb09b97d43d1f1f51c327f3d 100644 --- a/cmd/bfa_client/bfa_client.go +++ b/cmd/bfa_client/bfa_client.go @@ -150,12 +150,10 @@ func proposals() { for _, proposal := range votes.Proposals { fmt.Printf("Propuesta: %v\n", proposal.Hex()) for _, signer := range votes.Signers { - b := votes.Votes[proposal][signer] + b, ok := votes.Votes[proposal][signer] var v string - if b == nil { - v = "" - } else { - v = strconv.FormatBool(*b) + if ok { + v = strconv.FormatBool(b) } fmt.Printf("\t%v: %v\n", signer.Hex(), v) } @@ -372,8 +370,9 @@ func autovote() { cond.Ensure(len(votes.Signers)-removedSealers >= minSigners, "No se puede emitir un voto automático que reduzca la cantidad de selladores por debajo de %v.", minSigners) for _, proposal := range votes.Proposals { isSealer := proposal.In(votes.Signers) + _, alreadyVoted := votes.Votes[proposal][self] switch { - case votes.Votes[proposal][self] != nil: + case alreadyVoted: continue // Already voted case isSealer && votes.Tally[proposal].False < threshold: continue // There aren't enough votes to enable autovote diff --git a/internal/bfa/node.go b/internal/bfa/node.go index c499c6fa26f609ae4a3391efed0311cb21bc0eb1..aba08abf1e8fe1e19c7430b02749ba5bd8e2185a 100644 --- a/internal/bfa/node.go +++ b/internal/bfa/node.go @@ -40,11 +40,11 @@ type Tally struct { } type Proposals struct { - BlockNumber int64 `json:"number"` // Block number where the snapshot was created - Proposals []Address `json:"proposals"` // List of proposals being voted - Signers []Address `json:"signers"` // List of authorized signers at this moment - Tally map[Address]*Tally `json:"tally"` // Count of positive, negative and empty votes for a proposal - Votes map[Address]map[Address]*bool `json:"votes"` // List of votes for each proposal + BlockNumber int64 `json:"number"` // Block number where the snapshot was created + Proposals []Address `json:"proposals"` // List of proposals being voted + Signers []Address `json:"signers"` // List of authorized signers at this moment + Tally map[Address]*Tally `json:"tally"` // Count of positive, negative and empty votes for a proposal + Votes map[Address]map[Address]bool `json:"votes"` // List of votes for each proposal } type SealerStatus struct { @@ -261,19 +261,16 @@ func (node *Node) Votes(blockNumber int64) (votes Proposals) { votes.Proposals = append(votes.Proposals, proposal) } SortAddresses(votes.Proposals) - votes.Votes = make(map[Address]map[Address]*bool) + votes.Votes = make(map[Address]map[Address]bool) votes.Tally = make(map[Address]*Tally) for _, v := range snapshot.Votes { proposal := v.Address signer := v.Signer if votes.Votes[proposal] == nil { - votes.Votes[proposal] = make(map[Address]*bool) - for _, signer := range votes.Signers { - votes.Votes[proposal][signer] = nil - } + votes.Votes[proposal] = make(map[Address]bool) votes.Tally[proposal] = &Tally{0, 0, len(votes.Signers)} } - votes.Votes[proposal][signer] = &v.Authorize + votes.Votes[proposal][signer] = v.Authorize if v.Authorize { votes.Tally[proposal].True += 1 } else {