From d625f2f165c31151d8df23167592ba5ae1c8fb81 Mon Sep 17 00:00:00 2001 From: Sergey Date: Wed, 12 Jun 2024 04:37:10 +0300 Subject: [PATCH] chore: removed .Active from metrics --- pkg/metrics/metrics.go | 67 ++++++++++++------------ pkg/reporters/discord/missing.go | 6 +-- pkg/reporters/discord/validators.go | 6 +-- pkg/reporters/telegram/missing.go | 6 +-- pkg/reporters/telegram/validators.go | 6 +-- pkg/snapshot/manager.go | 2 +- pkg/snapshot/manager_test.go | 6 +-- pkg/snapshot/snapshot.go | 12 ++--- pkg/snapshot/snapshot_test.go | 78 ++++++++++++++-------------- pkg/state/manager.go | 4 +- pkg/types/entry.go | 7 +++ 11 files changed, 100 insertions(+), 100 deletions(-) create mode 100644 pkg/types/entry.go diff --git a/pkg/metrics/metrics.go b/pkg/metrics/metrics.go index 941c122..4bab6db 100644 --- a/pkg/metrics/metrics.go +++ b/pkg/metrics/metrics.go @@ -374,93 +374,92 @@ func (m *Manager) LogNodeReconnect(chain string, node string) { func (m *Manager) LogValidatorStats( chain *configPkg.ChainConfig, - validator *types.Validator, - signatureInfo types.SignatureInto, + entry types.Entry, ) { m.missingBlocksGauge. With(prometheus.Labels{ "chain": chain.Name, - "moniker": validator.Moniker, - "address": validator.OperatorAddress, + "moniker": entry.Validator.Moniker, + "address": entry.Validator.OperatorAddress, }). - Set(float64(signatureInfo.GetNotSigned())) + Set(float64(entry.SignatureInfo.GetNotSigned())) m.activeBlocksGauge. With(prometheus.Labels{ "chain": chain.Name, - "moniker": validator.Moniker, - "address": validator.OperatorAddress, + "moniker": entry.Validator.Moniker, + "address": entry.Validator.OperatorAddress, }). - Set(float64(signatureInfo.Active)) + Set(float64(entry.SignatureInfo.Active)) m.isActiveGauge. With(prometheus.Labels{ "chain": chain.Name, - "moniker": validator.Moniker, - "address": validator.OperatorAddress, + "moniker": entry.Validator.Moniker, + "address": entry.Validator.OperatorAddress, }). - Set(utils.BoolToFloat64(validator.Active())) + Set(utils.BoolToFloat64(entry.IsActive)) m.isJailedGauge. With(prometheus.Labels{ "chain": chain.Name, - "moniker": validator.Moniker, - "address": validator.OperatorAddress, + "moniker": entry.Validator.Moniker, + "address": entry.Validator.OperatorAddress, }). - Set(utils.BoolToFloat64(validator.Jailed)) + Set(utils.BoolToFloat64(entry.Validator.Jailed)) m.missingBlocksGauge. With(prometheus.Labels{ "chain": chain.Name, - "moniker": validator.Moniker, - "address": validator.OperatorAddress, + "moniker": entry.Validator.Moniker, + "address": entry.Validator.OperatorAddress, }). - Set(float64(signatureInfo.GetNotSigned())) + Set(float64(entry.SignatureInfo.GetNotSigned())) - if validator.SigningInfo != nil { + if entry.Validator.SigningInfo != nil { m.isTombstonedGauge. With(prometheus.Labels{ "chain": chain.Name, - "moniker": validator.Moniker, - "address": validator.OperatorAddress, + "moniker": entry.Validator.Moniker, + "address": entry.Validator.OperatorAddress, }). - Set(utils.BoolToFloat64(validator.SigningInfo.Tombstoned)) + Set(utils.BoolToFloat64(entry.Validator.SigningInfo.Tombstoned)) } - if validator.Active() { + if entry.IsActive { if chain.IsConsumer.Bool { m.needsToSignGauge. With(prometheus.Labels{ "chain": chain.Name, - "moniker": validator.Moniker, - "address": validator.OperatorAddress, + "moniker": entry.Validator.Moniker, + "address": entry.Validator.OperatorAddress, }). - Set(utils.BoolToFloat64(validator.NeedsToSign)) + Set(utils.BoolToFloat64(entry.Validator.NeedsToSign)) } m.votingPowerGauge. With(prometheus.Labels{ "chain": chain.Name, - "moniker": validator.Moniker, - "address": validator.OperatorAddress, + "moniker": entry.Validator.Moniker, + "address": entry.Validator.OperatorAddress, }). - Set(validator.VotingPowerPercent) + Set(entry.Validator.VotingPowerPercent) m.cumulativeVotingPowerGauge. With(prometheus.Labels{ "chain": chain.Name, - "moniker": validator.Moniker, - "address": validator.OperatorAddress, + "moniker": entry.Validator.Moniker, + "address": entry.Validator.OperatorAddress, }). - Set(validator.CumulativeVotingPowerPercent) + Set(entry.Validator.CumulativeVotingPowerPercent) m.validatorRankGauge. With(prometheus.Labels{ "chain": chain.Name, - "moniker": validator.Moniker, - "address": validator.OperatorAddress, + "moniker": entry.Validator.Moniker, + "address": entry.Validator.OperatorAddress, }). - Set(float64(validator.Rank)) + Set(float64(entry.Validator.Rank)) } } diff --git a/pkg/reporters/discord/missing.go b/pkg/reporters/discord/missing.go index b7e1a3e..a226b60 100644 --- a/pkg/reporters/discord/missing.go +++ b/pkg/reporters/discord/missing.go @@ -3,7 +3,7 @@ package discord import ( "fmt" "main/pkg/constants" - snapshotPkg "main/pkg/snapshot" + "main/pkg/types" "main/pkg/utils" "sort" @@ -28,7 +28,7 @@ func (reporter *Reporter) GetMissingCommand() *Command { } validatorEntries := snapshot.Entries.ToSlice() - activeValidatorsEntries := utils.Filter(validatorEntries, func(v snapshotPkg.Entry) bool { + activeValidatorsEntries := utils.Filter(validatorEntries, func(v types.Entry) bool { if !v.IsActive { return false } @@ -46,7 +46,7 @@ func (reporter *Reporter) GetMissingCommand() *Command { render := missingValidatorsRender{ Config: reporter.Config, - Validators: utils.Map(activeValidatorsEntries, func(v snapshotPkg.Entry) missingValidatorsEntry { + Validators: utils.Map(activeValidatorsEntries, func(v types.Entry) missingValidatorsEntry { link := reporter.Config.ExplorerConfig.GetValidatorLink(v.Validator) group, _, _ := reporter.Config.MissedBlocksGroups.GetGroup(v.SignatureInfo.GetNotSigned()) link.Text = fmt.Sprintf("%s %s", group.EmojiEnd, v.Validator.Moniker) diff --git a/pkg/reporters/discord/validators.go b/pkg/reporters/discord/validators.go index 97af338..1048028 100644 --- a/pkg/reporters/discord/validators.go +++ b/pkg/reporters/discord/validators.go @@ -3,7 +3,7 @@ package discord import ( "fmt" "main/pkg/constants" - snapshotPkg "main/pkg/snapshot" + "main/pkg/types" "main/pkg/utils" "sort" @@ -28,7 +28,7 @@ func (reporter *Reporter) GetValidatorsCommand() *Command { } validatorEntries := snapshot.Entries.ToSlice() - activeValidatorsEntries := utils.Filter(validatorEntries, func(v snapshotPkg.Entry) bool { + activeValidatorsEntries := utils.Filter(validatorEntries, func(v types.Entry) bool { return v.IsActive }) @@ -41,7 +41,7 @@ func (reporter *Reporter) GetValidatorsCommand() *Command { render := missingValidatorsRender{ Config: reporter.Config, - Validators: utils.Map(activeValidatorsEntries, func(v snapshotPkg.Entry) missingValidatorsEntry { + Validators: utils.Map(activeValidatorsEntries, func(v types.Entry) missingValidatorsEntry { link := reporter.Config.ExplorerConfig.GetValidatorLink(v.Validator) group, _, _ := reporter.Config.MissedBlocksGroups.GetGroup(v.SignatureInfo.GetNotSigned()) link.Text = fmt.Sprintf("%s %s", group.EmojiEnd, v.Validator.Moniker) diff --git a/pkg/reporters/telegram/missing.go b/pkg/reporters/telegram/missing.go index 6df1b00..d9ad18d 100644 --- a/pkg/reporters/telegram/missing.go +++ b/pkg/reporters/telegram/missing.go @@ -3,7 +3,7 @@ package telegram import ( "fmt" "main/pkg/constants" - snapshotPkg "main/pkg/snapshot" + "main/pkg/types" "main/pkg/utils" "sort" @@ -28,7 +28,7 @@ func (reporter *Reporter) HandleMissingValidators(c tele.Context) error { } validatorEntries := snapshot.Entries.ToSlice() - activeValidatorsEntries := utils.Filter(validatorEntries, func(v snapshotPkg.Entry) bool { + activeValidatorsEntries := utils.Filter(validatorEntries, func(v types.Entry) bool { if !v.IsActive { return false } @@ -46,7 +46,7 @@ func (reporter *Reporter) HandleMissingValidators(c tele.Context) error { render := missingValidatorsRender{ Config: reporter.Config, - Validators: utils.Map(activeValidatorsEntries, func(v snapshotPkg.Entry) missingValidatorsEntry { + Validators: utils.Map(activeValidatorsEntries, func(v types.Entry) missingValidatorsEntry { link := reporter.Config.ExplorerConfig.GetValidatorLink(v.Validator) group, _, _ := reporter.Config.MissedBlocksGroups.GetGroup(v.SignatureInfo.GetNotSigned()) link.Text = fmt.Sprintf("%s %s", group.EmojiEnd, v.Validator.Moniker) diff --git a/pkg/reporters/telegram/validators.go b/pkg/reporters/telegram/validators.go index 397087c..a943af8 100644 --- a/pkg/reporters/telegram/validators.go +++ b/pkg/reporters/telegram/validators.go @@ -3,7 +3,7 @@ package telegram import ( "fmt" "main/pkg/constants" - snapshotPkg "main/pkg/snapshot" + "main/pkg/types" "main/pkg/utils" "sort" @@ -28,7 +28,7 @@ func (reporter *Reporter) HandleListValidators(c tele.Context) error { } validatorEntries := snapshot.Entries.ToSlice() - activeValidatorsEntries := utils.Filter(validatorEntries, func(v snapshotPkg.Entry) bool { + activeValidatorsEntries := utils.Filter(validatorEntries, func(v types.Entry) bool { return v.IsActive }) @@ -41,7 +41,7 @@ func (reporter *Reporter) HandleListValidators(c tele.Context) error { render := missingValidatorsRender{ Config: reporter.Config, - Validators: utils.Map(activeValidatorsEntries, func(v snapshotPkg.Entry) missingValidatorsEntry { + Validators: utils.Map(activeValidatorsEntries, func(v types.Entry) missingValidatorsEntry { link := reporter.Config.ExplorerConfig.GetValidatorLink(v.Validator) group, _, _ := reporter.Config.MissedBlocksGroups.GetGroup(v.SignatureInfo.GetNotSigned()) link.Text = fmt.Sprintf("%s %s", group.EmojiEnd, v.Validator.Moniker) diff --git a/pkg/snapshot/manager.go b/pkg/snapshot/manager.go index b657188..0823dc6 100644 --- a/pkg/snapshot/manager.go +++ b/pkg/snapshot/manager.go @@ -38,7 +38,7 @@ func (m *Manager) CommitNewSnapshot(height int64, snapshot Snapshot) { } for _, entry := range snapshot.Entries { - m.metricsManager.LogValidatorStats(m.config, entry.Validator, entry.SignatureInfo) + m.metricsManager.LogValidatorStats(m.config, entry) } } diff --git a/pkg/snapshot/manager_test.go b/pkg/snapshot/manager_test.go index c1bc376..b995f20 100644 --- a/pkg/snapshot/manager_test.go +++ b/pkg/snapshot/manager_test.go @@ -38,12 +38,12 @@ func TestManagerCommitNewSnapshot(t *testing.T) { manager := NewManager(*log, config, metricsManager) manager.CommitNewSnapshot(10, Snapshot{ - Entries: map[string]Entry{ + Entries: map[string]types.Entry{ "validator": {Validator: &types.Validator{}}, }, }) manager.CommitNewSnapshot(20, Snapshot{ - Entries: map[string]Entry{ + Entries: map[string]types.Entry{ "validator": {Validator: &types.Validator{}}, }, }) @@ -77,7 +77,7 @@ func TestManagerGetNewerSnapshot(t *testing.T) { assert.Nil(t, firstSnapshot, "Snapshot should not be presented!") manager.CommitNewSnapshot(20, Snapshot{ - Entries: map[string]Entry{ + Entries: map[string]types.Entry{ "validator": {Validator: &types.Validator{}}, }, }) diff --git a/pkg/snapshot/snapshot.go b/pkg/snapshot/snapshot.go index 3633ccf..fff7ab8 100644 --- a/pkg/snapshot/snapshot.go +++ b/pkg/snapshot/snapshot.go @@ -12,16 +12,10 @@ import ( "golang.org/x/exp/slices" ) -type Entry struct { - IsActive bool - Validator *types.Validator - SignatureInfo types.SignatureInto -} - -type Entries map[string]Entry +type Entries map[string]types.Entry -func (e Entries) ToSlice() []Entry { - entries := make([]Entry, len(e)) +func (e Entries) ToSlice() []types.Entry { + entries := make([]types.Entry, len(e)) index := 0 for _, entry := range e { diff --git a/pkg/snapshot/snapshot_test.go b/pkg/snapshot/snapshot_test.go index aad7f8d..e500ff0 100644 --- a/pkg/snapshot/snapshot_test.go +++ b/pkg/snapshot/snapshot_test.go @@ -15,8 +15,8 @@ import ( func TestValidatorCreated(t *testing.T) { t.Parallel() - olderSnapshot := Snapshot{Entries: map[string]Entry{}} - newerSnapshot := Snapshot{Entries: map[string]Entry{ + olderSnapshot := Snapshot{Entries: map[string]types.Entry{}} + newerSnapshot := Snapshot{Entries: map[string]types.Entry{ "validator": {Validator: &types.Validator{}}, }} @@ -36,14 +36,14 @@ func TestValidatorGroupChanged(t *testing.T) { }, } - olderSnapshot := Snapshot{Entries: map[string]Entry{ + olderSnapshot := Snapshot{Entries: map[string]types.Entry{ "validator": { IsActive: true, Validator: &types.Validator{Jailed: false, Status: 3}, SignatureInfo: types.SignatureInto{NotSigned: 0}, }, }} - newerSnapshot := Snapshot{Entries: map[string]Entry{ + newerSnapshot := Snapshot{Entries: map[string]types.Entry{ "validator": { IsActive: true, Validator: &types.Validator{Jailed: false, Status: 3}, @@ -69,14 +69,14 @@ func TestValidatorGroupChangedAnomaly(t *testing.T) { }, } - olderSnapshot := Snapshot{Entries: map[string]Entry{ + olderSnapshot := Snapshot{Entries: map[string]types.Entry{ "validator": { IsActive: true, Validator: &types.Validator{Jailed: false, Status: 3}, SignatureInfo: types.SignatureInto{NotSigned: 0}, }, }} - newerSnapshot := Snapshot{Entries: map[string]Entry{ + newerSnapshot := Snapshot{Entries: map[string]types.Entry{ "validator": { IsActive: true, Validator: &types.Validator{Jailed: false, Status: 3}, @@ -99,13 +99,13 @@ func TestValidatorTombstoned(t *testing.T) { }, } - olderSnapshot := Snapshot{Entries: map[string]Entry{ + olderSnapshot := Snapshot{Entries: map[string]types.Entry{ "validator": { Validator: &types.Validator{SigningInfo: &types.SigningInfo{Tombstoned: false}}, SignatureInfo: types.SignatureInto{NotSigned: 0}, }, }} - newerSnapshot := Snapshot{Entries: map[string]Entry{ + newerSnapshot := Snapshot{Entries: map[string]types.Entry{ "validator": { Validator: &types.Validator{SigningInfo: &types.SigningInfo{Tombstoned: true}}, SignatureInfo: types.SignatureInto{NotSigned: 0}, @@ -130,14 +130,14 @@ func TestValidatorJailed(t *testing.T) { }, } - olderSnapshot := Snapshot{Entries: map[string]Entry{ + olderSnapshot := Snapshot{Entries: map[string]types.Entry{ "validator": { IsActive: true, Validator: &types.Validator{Jailed: false, Status: 3}, SignatureInfo: types.SignatureInto{NotSigned: 0}, }, }} - newerSnapshot := Snapshot{Entries: map[string]Entry{ + newerSnapshot := Snapshot{Entries: map[string]types.Entry{ "validator": { IsActive: false, Validator: &types.Validator{Jailed: true, Status: 1}, @@ -170,13 +170,13 @@ func TestValidatorUnjailed(t *testing.T) { }, } - olderSnapshot := Snapshot{Entries: map[string]Entry{ + olderSnapshot := Snapshot{Entries: map[string]types.Entry{ "validator": { Validator: &types.Validator{Jailed: true}, SignatureInfo: types.SignatureInto{NotSigned: 0}, }, }} - newerSnapshot := Snapshot{Entries: map[string]Entry{ + newerSnapshot := Snapshot{Entries: map[string]types.Entry{ "validator": { Validator: &types.Validator{Jailed: false}, SignatureInfo: types.SignatureInto{NotSigned: 0}, @@ -201,14 +201,14 @@ func TestValidatorJoinedSignatory(t *testing.T) { }, } - olderSnapshot := Snapshot{Entries: map[string]Entry{ + olderSnapshot := Snapshot{Entries: map[string]types.Entry{ "validator": { IsActive: true, Validator: &types.Validator{NeedsToSign: false, Status: 3}, SignatureInfo: types.SignatureInto{NotSigned: 0}, }, }} - newerSnapshot := Snapshot{Entries: map[string]Entry{ + newerSnapshot := Snapshot{Entries: map[string]types.Entry{ "validator": { IsActive: true, Validator: &types.Validator{NeedsToSign: true, Status: 3}, @@ -234,14 +234,14 @@ func TestValidatorLeftSignatory(t *testing.T) { }, } - olderSnapshot := Snapshot{Entries: map[string]Entry{ + olderSnapshot := Snapshot{Entries: map[string]types.Entry{ "validator": { IsActive: true, Validator: &types.Validator{NeedsToSign: true, Status: 3}, SignatureInfo: types.SignatureInto{NotSigned: 0}, }, }} - newerSnapshot := Snapshot{Entries: map[string]Entry{ + newerSnapshot := Snapshot{Entries: map[string]types.Entry{ "validator": { IsActive: true, Validator: &types.Validator{NeedsToSign: false, Status: 3}, @@ -267,14 +267,14 @@ func TestValidatorInactive(t *testing.T) { }, } - olderSnapshot := Snapshot{Entries: map[string]Entry{ + olderSnapshot := Snapshot{Entries: map[string]types.Entry{ "validator": { IsActive: true, Validator: &types.Validator{Jailed: false, Status: 3}, SignatureInfo: types.SignatureInto{NotSigned: 0}, }, }} - newerSnapshot := Snapshot{Entries: map[string]Entry{ + newerSnapshot := Snapshot{Entries: map[string]types.Entry{ "validator": { IsActive: false, Validator: &types.Validator{Jailed: false, Status: 1}, @@ -292,10 +292,10 @@ func TestValidatorInactive(t *testing.T) { func TestValidatorChangedKey(t *testing.T) { t.Parallel() - olderSnapshot := Snapshot{Entries: map[string]Entry{ + olderSnapshot := Snapshot{Entries: map[string]types.Entry{ "validator": {Validator: &types.Validator{ConsensusAddressValcons: "key1"}}, }} - newerSnapshot := Snapshot{Entries: map[string]Entry{ + newerSnapshot := Snapshot{Entries: map[string]types.Entry{ "validator": {Validator: &types.Validator{ConsensusAddressValcons: "key2"}}, }} @@ -308,10 +308,10 @@ func TestValidatorChangedKey(t *testing.T) { func TestValidatorChangedMoniker(t *testing.T) { t.Parallel() - olderSnapshot := Snapshot{Entries: map[string]Entry{ + olderSnapshot := Snapshot{Entries: map[string]types.Entry{ "validator": {Validator: &types.Validator{Moniker: "moniker1"}}, }} - newerSnapshot := Snapshot{Entries: map[string]Entry{ + newerSnapshot := Snapshot{Entries: map[string]types.Entry{ "validator": {Validator: &types.Validator{Moniker: "moniker2"}}, }} @@ -324,10 +324,10 @@ func TestValidatorChangedMoniker(t *testing.T) { func TestValidatorChangedCommission(t *testing.T) { t.Parallel() - olderSnapshot := Snapshot{Entries: map[string]Entry{ + olderSnapshot := Snapshot{Entries: map[string]types.Entry{ "validator": {Validator: &types.Validator{Commission: 0.01}}, }} - newerSnapshot := Snapshot{Entries: map[string]Entry{ + newerSnapshot := Snapshot{Entries: map[string]types.Entry{ "validator": {Validator: &types.Validator{Commission: 0.02}}, }} @@ -347,14 +347,14 @@ func TestValidatorActive(t *testing.T) { }, } - olderSnapshot := Snapshot{Entries: map[string]Entry{ + olderSnapshot := Snapshot{Entries: map[string]types.Entry{ "validator": { IsActive: false, Validator: &types.Validator{Jailed: false, Status: 1}, SignatureInfo: types.SignatureInto{NotSigned: 0}, }, }} - newerSnapshot := Snapshot{Entries: map[string]Entry{ + newerSnapshot := Snapshot{Entries: map[string]types.Entry{ "validator": { IsActive: true, Validator: &types.Validator{Jailed: false, Status: 3}, @@ -379,13 +379,13 @@ func TestValidatorJailedAndChangedGroup(t *testing.T) { }, } - olderSnapshot := Snapshot{Entries: map[string]Entry{ + olderSnapshot := Snapshot{Entries: map[string]types.Entry{ "validator": { Validator: &types.Validator{Jailed: true, Status: 3}, SignatureInfo: types.SignatureInto{NotSigned: 0}, }, }} - newerSnapshot := Snapshot{Entries: map[string]Entry{ + newerSnapshot := Snapshot{Entries: map[string]types.Entry{ "validator": { Validator: &types.Validator{Jailed: true, Status: 3}, SignatureInfo: types.SignatureInto{NotSigned: 50}, @@ -407,13 +407,13 @@ func TestTombstonedAndNoPreviousSigningInfo(t *testing.T) { }, } - olderSnapshot := Snapshot{Entries: map[string]Entry{ + olderSnapshot := Snapshot{Entries: map[string]types.Entry{ "validator": { Validator: &types.Validator{Jailed: true, Status: 3}, SignatureInfo: types.SignatureInto{NotSigned: 0}, }, }} - newerSnapshot := Snapshot{Entries: map[string]Entry{ + newerSnapshot := Snapshot{Entries: map[string]types.Entry{ "validator": { Validator: &types.Validator{ Jailed: true, @@ -433,7 +433,7 @@ func TestToSlice(t *testing.T) { t.Parallel() entries := Entries{ - "validator": { + "validator": types.Entry{ Validator: &types.Validator{Moniker: "test", Jailed: false, Status: 1}, SignatureInfo: types.SignatureInto{NotSigned: 0}, }, @@ -455,14 +455,14 @@ func TestNewMissedBlocksGroupNotPresent(t *testing.T) { }, } - olderSnapshot := Snapshot{Entries: map[string]Entry{ + olderSnapshot := Snapshot{Entries: map[string]types.Entry{ "validator": { IsActive: true, Validator: &types.Validator{Jailed: false, Status: 3}, SignatureInfo: types.SignatureInto{NotSigned: 0}, }, }} - newerSnapshot := Snapshot{Entries: map[string]Entry{ + newerSnapshot := Snapshot{Entries: map[string]types.Entry{ "validator": { IsActive: true, Validator: &types.Validator{Jailed: false, Status: 3}, @@ -485,14 +485,14 @@ func TestOldMissedBlocksGroupNotPresent(t *testing.T) { }, } - olderSnapshot := Snapshot{Entries: map[string]Entry{ + olderSnapshot := Snapshot{Entries: map[string]types.Entry{ "validator": { IsActive: true, Validator: &types.Validator{Jailed: false, Status: 3}, SignatureInfo: types.SignatureInto{NotSigned: 150}, }, }} - newerSnapshot := Snapshot{Entries: map[string]Entry{ + newerSnapshot := Snapshot{Entries: map[string]types.Entry{ "validator": { IsActive: true, Validator: &types.Validator{Jailed: false, Status: 3}, @@ -515,7 +515,7 @@ func TestSorting(t *testing.T) { }, } - olderSnapshot := Snapshot{Entries: map[string]Entry{ + olderSnapshot := Snapshot{Entries: map[string]types.Entry{ "validator1": { IsActive: true, Validator: &types.Validator{Jailed: false, Status: 3}, @@ -532,7 +532,7 @@ func TestSorting(t *testing.T) { SignatureInfo: types.SignatureInto{NotSigned: 25}, }, }} - newerSnapshot := Snapshot{Entries: map[string]Entry{ + newerSnapshot := Snapshot{Entries: map[string]types.Entry{ "validator1": { IsActive: true, Validator: &types.Validator{Jailed: true, Status: 3}, @@ -570,7 +570,7 @@ func TestSortingMissedBlocksGroups(t *testing.T) { }, } - olderSnapshot := Snapshot{Entries: map[string]Entry{ + olderSnapshot := Snapshot{Entries: map[string]types.Entry{ "validator1": { IsActive: true, Validator: &types.Validator{OperatorAddress: "validator1", Status: 3}, @@ -592,7 +592,7 @@ func TestSortingMissedBlocksGroups(t *testing.T) { SignatureInfo: types.SignatureInto{NotSigned: 75}, }, }} - newerSnapshot := Snapshot{Entries: map[string]Entry{ + newerSnapshot := Snapshot{Entries: map[string]types.Entry{ // skipping blocks: 25 -> 75 "validator1": { IsActive: true, diff --git a/pkg/state/manager.go b/pkg/state/manager.go index adb5ccb..e9aa109 100644 --- a/pkg/state/manager.go +++ b/pkg/state/manager.go @@ -138,7 +138,7 @@ func (m *Manager) GetSnapshot() (snapshotPkg.Snapshot, error) { lastBlock := m.state.GetLastActiveSet() validators := m.state.GetValidators() - entries := make(map[string]snapshotPkg.Entry, len(validators)) + entries := make(map[string]types.Entry, len(validators)) neededBlocks := utils.MinInt64(m.config.BlocksWindow, m.GetLastBlockHeight()) @@ -156,7 +156,7 @@ func (m *Manager) GetSnapshot() (snapshotPkg.Snapshot, error) { return snapshotPkg.Snapshot{}, err } - entries[validator.OperatorAddress] = snapshotPkg.Entry{ + entries[validator.OperatorAddress] = types.Entry{ IsActive: isActiveAtLastBlock, Validator: validator, SignatureInfo: signatureInfo, diff --git a/pkg/types/entry.go b/pkg/types/entry.go new file mode 100644 index 0000000..11ad975 --- /dev/null +++ b/pkg/types/entry.go @@ -0,0 +1,7 @@ +package types + +type Entry struct { + IsActive bool + Validator *Validator + SignatureInfo SignatureInto +}