diff --git a/core/services/ocr2/plugins/s4/plugin.go b/core/services/ocr2/plugins/s4/plugin.go index 7e4b91be97e..68bd9fd2142 100644 --- a/core/services/ocr2/plugins/s4/plugin.go +++ b/core/services/ocr2/plugins/s4/plugin.go @@ -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}) diff --git a/core/services/ocr2/plugins/s4/plugin_test.go b/core/services/ocr2/plugins/s4/plugin_test.go index b85ba053122..94c876a4f7f 100644 --- a/core/services/ocr2/plugins/s4/plugin_test.go +++ b/core/services/ocr2/plugins/s4/plugin_test.go @@ -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) {