code.vegaprotocol.io/vega@v0.79.0/core/validators/validator_performance_snapshot.go (about) 1 // Copyright (C) 2023 Gobalsky Labs Limited 2 // 3 // This program is free software: you can redistribute it and/or modify 4 // it under the terms of the GNU Affero General Public License as 5 // published by the Free Software Foundation, either version 3 of the 6 // License, or (at your option) any later version. 7 // 8 // This program is distributed in the hope that it will be useful, 9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 // GNU Affero General Public License for more details. 12 // 13 // You should have received a copy of the GNU Affero General Public License 14 // along with this program. If not, see <http://www.gnu.org/licenses/>. 15 16 package validators 17 18 import ( 19 "sort" 20 21 v1 "code.vegaprotocol.io/vega/protos/vega/snapshot/v1" 22 ) 23 24 func (vp *validatorPerformance) Deserialize(proto *v1.ValidatorPerformance) { 25 if proto != nil { 26 tot := int64(0) 27 for _, stats := range proto.ValidatorPerfStats { 28 tot += int64(stats.Proposed) 29 vp.proposals[stats.ValidatorAddress] = int64(stats.Proposed) 30 } 31 vp.total = tot 32 } 33 } 34 35 func (vp *validatorPerformance) Serialize() *v1.ValidatorPerformance { 36 keys := make([]string, 0, len(vp.proposals)) 37 for k := range vp.proposals { 38 keys = append(keys, k) 39 } 40 41 sort.Strings(keys) 42 43 stats := make([]*v1.PerformanceStats, 0, len(vp.proposals)) 44 for _, addr := range keys { 45 stat := vp.proposals[addr] 46 stats = append(stats, &v1.PerformanceStats{ 47 ValidatorAddress: addr, 48 Proposed: uint64(stat), 49 }) 50 } 51 52 return &v1.ValidatorPerformance{ 53 ValidatorPerfStats: stats, 54 } 55 }