Skip to content

Commit

Permalink
[Functions] Add extra expiration check in storage plugin (#10805)
Browse files Browse the repository at this point in the history
  • Loading branch information
bolekk committed Sep 27, 2023
1 parent 34bbbff commit e2cf3ec
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
10 changes: 10 additions & 0 deletions core/services/ocr2/plugins/s4/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,16 @@ func (c *plugin) ShouldAcceptFinalizedReport(ctx context.Context, ts types.Repor
Confirmed: true,
Signature: row.Signature,
}

now := time.Now().UnixMilli()
if now > ormRow.Expiration {
c.logger.Error("Received an expired entry in a report, not saving", commontypes.LogFields{
"expirationTs": ormRow.Expiration,
"nowTs": now,
})
continue
}

err = c.orm.Update(ormRow, pg.WithParentCtx(ctx))
if err != nil && !errors.Is(err, s4.ErrVersionTooLow) {
c.logger.Error("Failed to Update a row in ShouldAcceptFinalizedReport()", commontypes.LogFields{"err": err})
Expand Down
15 changes: 15 additions & 0 deletions core/services/ocr2/plugins/s4/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,21 @@ func TestPlugin_ShouldAcceptFinalizedReport(t *testing.T) {
assert.NoError(t, err) // errors just logged
assert.False(t, should)
})

t.Run("don't save expired", func(t *testing.T) {
ormRows := make([]*s4_svc.Row, 0)
rows := generateTestRows(t, 2, -time.Minute)

report, err := proto.Marshal(&s4.Rows{
Rows: rows,
})
assert.NoError(t, err)

should, err := plugin.ShouldAcceptFinalizedReport(testutils.Context(t), types.ReportTimestamp{}, report)
assert.NoError(t, err)
assert.False(t, should)
assert.Equal(t, 0, len(ormRows))
})
}

func TestPlugin_Query(t *testing.T) {
Expand Down

0 comments on commit e2cf3ec

Please sign in to comment.