From c303cca37eeb9d6aac8b8ed98dad78e6ccda1919 Mon Sep 17 00:00:00 2001 From: Gerard Snaauw <33763579+gerardsn@users.noreply.github.com> Date: Tue, 13 Jun 2023 17:43:25 +0200 Subject: [PATCH] backport 5.1 reprocess do not fail on missing payload (#2246) * do not fail on missing payload (#2245) * release notes --- docs/pages/release_notes.rst | 10 ++++++++++ network/network.go | 6 +++--- network/network_test.go | 19 +++++++++++++++++++ 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/docs/pages/release_notes.rst b/docs/pages/release_notes.rst index f576c36d77..58dce990fe 100644 --- a/docs/pages/release_notes.rst +++ b/docs/pages/release_notes.rst @@ -5,6 +5,16 @@ Release notes What has been changed, and how to update between versions. +************************ +Hazelnut update (v5.1.2) +************************ + +Release date: 2023-06-13 + +- Fixed issue where a Reprocess failed due to missing data + +**Full Changelog**: https://github.com/nuts-foundation/nuts-node/compare/v5.1.1...v5.1.2 + ************************ Hazelnut update (v5.1.1) ************************ diff --git a/network/network.go b/network/network.go index f9ceadf20e..aa7063575a 100644 --- a/network/network.go +++ b/network/network.go @@ -760,8 +760,8 @@ func (n *Network) Reprocess(ctx context.Context, contentType string) (*Reprocess // add to Nats subject := fmt.Sprintf("%s.%s", events.ReprocessStream, contentType) payload, err := n.state.ReadPayload(ctx, tx.PayloadHash()) - if err != nil { - return nil, fmt.Errorf("reprocess abort on transaction %#x payload %#x: %w", tx.Ref(), tx.PayloadHash(), err) + if err != nil && !errors.Is(err, dag.ErrPayloadNotFound) { + return nil, fmt.Errorf("reprocess abort on transaction %s payload %s: %w", tx.Ref(), tx.PayloadHash(), err) } twp := events.TransactionWithPayload{ Transaction: tx, @@ -774,7 +774,7 @@ func (n *Network) Reprocess(ctx context.Context, contentType string) (*Reprocess Trace("Publishing transaction") _, err = js.PublishAsync(subject, data) if err != nil { - return nil, fmt.Errorf("reprocess abort on transaction %#x publish: %w", tx.Ref(), err) + return nil, fmt.Errorf("reprocess abort on transaction %s publish: %w", tx.Ref(), err) } } diff --git a/network/network_test.go b/network/network_test.go index 3fdd7a2c98..0745dc2aaa 100644 --- a/network/network_test.go +++ b/network/network_test.go @@ -782,6 +782,25 @@ func TestNetwork_Reprocess(t *testing.T) { assert.Equal(t, 0, counter) }) + t.Run("missing payload", func(t *testing.T) { + ctx, cancel := context.WithTimeout(context.Background(), time.Second) + defer cancel() + + setup, eventManager := newSetup(t) + setup.state.EXPECT().FindBetweenLC(gomock.Any(), uint32(0), uint32(1000)).Return([]dag.Transaction{tx}, nil) + setup.state.EXPECT().ReadPayload(gomock.Any(), tx.PayloadHash()).Return(nil, dag.ErrPayloadNotFound) + var counter int + wg := sync.WaitGroup{} + wg.Add(1) + + subscribe(ctx, t, eventManager, &wg, &counter) + + _, err := setup.network.Reprocess(ctx, "application/did+json") + require.NoError(t, err) + wg.Wait() + assert.Equal(t, 1, counter) + }) + t.Run("error", func(t *testing.T) { t.Run("query", func(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), time.Second)