From 562d4a0387e90f2f5c5ff90c3cef827e3395eba3 Mon Sep 17 00:00:00 2001 From: Miguel Montes <miguel.montes@gmail.com> Date: Fri, 12 Jul 2024 17:56:14 -0300 Subject: [PATCH] =?UTF-8?q?Cambio=20en=20la=20l=C3=B3gica=20de=20proposals?= =?UTF-8?q?=20y=20autovote?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/bfa_client/bfa_client.go | 11 +++++------ internal/bfa/node.go | 19 ++++++++----------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/cmd/bfa_client/bfa_client.go b/cmd/bfa_client/bfa_client.go index 9c152e5..ad2feaa 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 c499c6f..aba08ab 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 { -- GitLab