diff --git a/pkg/snapshot/pg/publisher.go b/pkg/snapshot/pg/publisher.go index b928934..e58cc29 100644 --- a/pkg/snapshot/pg/publisher.go +++ b/pkg/snapshot/pg/publisher.go @@ -110,6 +110,7 @@ func (p *publisher) PublishHeader(header *types.Header) (err error) { return err } tx := pubTx{snapTx, nil} + // we must avoid overshadowing the `err` defer func() { err = snapt.CommitOrRollback(tx, err) if err != nil { @@ -117,7 +118,7 @@ func (p *publisher) PublishHeader(header *types.Header) (err error) { } }() - if err := tx.publishIPLD(headerNode.Cid(), headerNode.RawData(), header.Number); err != nil { + if err = tx.publishIPLD(headerNode.Cid(), headerNode.RawData(), header.Number); err != nil { return err } diff --git a/pkg/snapshot/service.go b/pkg/snapshot/service.go index 0517af0..a8da899 100644 --- a/pkg/snapshot/service.go +++ b/pkg/snapshot/service.go @@ -200,8 +200,12 @@ func (s *Service) createSnapshot(ctx context.Context, it trie.NodeIterator, head if err != nil { return err } + // we must avoid overshadowing the `err` defer func() { err = CommitOrRollback(tx, err) + if err != nil { + log.Errorf("CommitOrRollback failed: %s", err) + } }() // path (from recovery dump) to be seeked on recovery