Skip to content
Snippets Groups Projects
Commit 562d4a03 authored by Miguel Montes's avatar Miguel Montes
Browse files

Cambio en la lógica de proposals y autovote

parent e0ca8e1d
No related branches found
No related tags found
No related merge requests found
...@@ -150,12 +150,10 @@ func proposals() { ...@@ -150,12 +150,10 @@ func proposals() {
for _, proposal := range votes.Proposals { for _, proposal := range votes.Proposals {
fmt.Printf("Propuesta: %v\n", proposal.Hex()) fmt.Printf("Propuesta: %v\n", proposal.Hex())
for _, signer := range votes.Signers { for _, signer := range votes.Signers {
b := votes.Votes[proposal][signer] b, ok := votes.Votes[proposal][signer]
var v string var v string
if b == nil { if ok {
v = "" v = strconv.FormatBool(b)
} else {
v = strconv.FormatBool(*b)
} }
fmt.Printf("\t%v: %v\n", signer.Hex(), v) fmt.Printf("\t%v: %v\n", signer.Hex(), v)
} }
...@@ -372,8 +370,9 @@ func autovote() { ...@@ -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) 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 { for _, proposal := range votes.Proposals {
isSealer := proposal.In(votes.Signers) isSealer := proposal.In(votes.Signers)
_, alreadyVoted := votes.Votes[proposal][self]
switch { switch {
case votes.Votes[proposal][self] != nil: case alreadyVoted:
continue // Already voted continue // Already voted
case isSealer && votes.Tally[proposal].False < threshold: case isSealer && votes.Tally[proposal].False < threshold:
continue // There aren't enough votes to enable autovote continue // There aren't enough votes to enable autovote
......
...@@ -40,11 +40,11 @@ type Tally struct { ...@@ -40,11 +40,11 @@ type Tally struct {
} }
type Proposals struct { type Proposals struct {
BlockNumber int64 `json:"number"` // Block number where the snapshot was created BlockNumber int64 `json:"number"` // Block number where the snapshot was created
Proposals []Address `json:"proposals"` // List of proposals being voted Proposals []Address `json:"proposals"` // List of proposals being voted
Signers []Address `json:"signers"` // List of authorized signers at this moment 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 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 Votes map[Address]map[Address]bool `json:"votes"` // List of votes for each proposal
} }
type SealerStatus struct { type SealerStatus struct {
...@@ -261,19 +261,16 @@ func (node *Node) Votes(blockNumber int64) (votes Proposals) { ...@@ -261,19 +261,16 @@ func (node *Node) Votes(blockNumber int64) (votes Proposals) {
votes.Proposals = append(votes.Proposals, proposal) votes.Proposals = append(votes.Proposals, proposal)
} }
SortAddresses(votes.Proposals) 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) votes.Tally = make(map[Address]*Tally)
for _, v := range snapshot.Votes { for _, v := range snapshot.Votes {
proposal := v.Address proposal := v.Address
signer := v.Signer signer := v.Signer
if votes.Votes[proposal] == nil { if votes.Votes[proposal] == nil {
votes.Votes[proposal] = make(map[Address]*bool) votes.Votes[proposal] = make(map[Address]bool)
for _, signer := range votes.Signers {
votes.Votes[proposal][signer] = nil
}
votes.Tally[proposal] = &Tally{0, 0, len(votes.Signers)} votes.Tally[proposal] = &Tally{0, 0, len(votes.Signers)}
} }
votes.Votes[proposal][signer] = &v.Authorize votes.Votes[proposal][signer] = v.Authorize
if v.Authorize { if v.Authorize {
votes.Tally[proposal].True += 1 votes.Tally[proposal].True += 1
} else { } else {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment