From 218313ac4e3425cd4cb56ae815a865facd925bca Mon Sep 17 00:00:00 2001 From: Techno Freak Date: Tue, 1 Aug 2023 22:10:00 +0300 Subject: [PATCH] fix: do not mark validator as tombstoned if no previous signing info --- pkg/snapshot/snapshot.go | 13 +++++++++---- pkg/snapshot/snapshot_test.go | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/pkg/snapshot/snapshot.go b/pkg/snapshot/snapshot.go index b0fac66..55c567b 100644 --- a/pkg/snapshot/snapshot.go +++ b/pkg/snapshot/snapshot.go @@ -46,9 +46,13 @@ func (snapshot *Snapshot) GetReport( continue } - oldTombstoned := olderEntry.Validator.SigningInfo != nil && olderEntry.Validator.SigningInfo.Tombstoned - newTombstoned := entry.Validator.SigningInfo != nil && entry.Validator.SigningInfo.Tombstoned - if oldTombstoned != newTombstoned { + hasOlderSigningInfo := olderEntry.Validator.SigningInfo != nil + hasNewerSigningInfo := entry.Validator.SigningInfo != nil + + if hasOlderSigningInfo && + hasNewerSigningInfo && + !olderEntry.Validator.SigningInfo.Tombstoned && + entry.Validator.SigningInfo.Tombstoned { entries = append(entries, events.ValidatorTombstoned{ Validator: entry.Validator, }) @@ -79,7 +83,8 @@ func (snapshot *Snapshot) GetReport( }) } - if newTombstoned || entry.Validator.Jailed || !entry.Validator.Active() { + isTombstoned := hasNewerSigningInfo && entry.Validator.SigningInfo.Tombstoned + if isTombstoned || entry.Validator.Jailed || !entry.Validator.Active() { continue } diff --git a/pkg/snapshot/snapshot_test.go b/pkg/snapshot/snapshot_test.go index 0164e1c..49a9ab7 100644 --- a/pkg/snapshot/snapshot_test.go +++ b/pkg/snapshot/snapshot_test.go @@ -242,6 +242,38 @@ func TestValidatorJailedAndChangedGroup(t *testing.T) { assert.Empty(t, report.Entries, "Report should be empty!") } +func TestTombstonedAndNoPreviousSigningInfo(t *testing.T) { + t.Parallel() + + config := &configPkg.ChainConfig{ + MissedBlocksGroups: []*configPkg.MissedBlocksGroup{ + {Start: 0, End: 49}, + {Start: 50, End: 99}, + }, + } + + olderSnapshot := Snapshot{Entries: map[string]Entry{ + "validator": { + Validator: &types.Validator{Jailed: true, Status: 3}, + SignatureInfo: types.SignatureInto{NotSigned: 0}, + }, + }} + newerSnapshot := Snapshot{Entries: map[string]Entry{ + "validator": { + Validator: &types.Validator{ + Jailed: true, + Status: 3, + SigningInfo: &types.SigningInfo{Tombstoned: true}, + }, + SignatureInfo: types.SignatureInto{NotSigned: 50}, + }, + }} + + report, err := newerSnapshot.GetReport(olderSnapshot, config) + assert.Nil(t, err, "Error should not be present!") + assert.Empty(t, report.Entries, "Report should be empty!") +} + func TestToSlice(t *testing.T) { t.Parallel()