Skip to content

Commit

Permalink
fix: do not mark validator as tombstoned if no previous signing info
Browse files Browse the repository at this point in the history
  • Loading branch information
freak12techno committed Aug 1, 2023
1 parent db5f4fb commit 218313a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
13 changes: 9 additions & 4 deletions pkg/snapshot/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
Expand Down Expand Up @@ -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
}

Expand Down
32 changes: 32 additions & 0 deletions pkg/snapshot/snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 218313a

Please sign in to comment.