Skip to content

Commit 989f1b3

Browse files
authored
fix(database): log pool errors vs throwing an error (#979)
Signed-off-by: Chris Gianelloni <wolf31o2@blinklabs.io>
1 parent a8384e2 commit 989f1b3

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

database/plugin/metadata/sqlite/pool.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,7 @@ func (d *MetadataStoreSqlite) SetPoolRegistration(
149149
}
150150
tmpPool, err := d.GetPool(cert.Operator[:], txn)
151151
if err != nil {
152-
if errors.Is(err, models.ErrPoolNotFound) {
153-
// Do nothing :-)
154-
} else {
152+
if !errors.Is(err, models.ErrPoolNotFound) {
155153
return err
156154
}
157155
}
@@ -202,11 +200,11 @@ func (d *MetadataStoreSqlite) SetPoolRegistration(
202200
}
203201
tmpPool.Registration = append(tmpPool.Registration, tmpReg)
204202
tmpPool.Relays = tmpReg.Relays
205-
onConflict := clause.OnConflict{
203+
// d.logger.Debug("pool registration", "hash", tmpReg.PoolKeyHash)
204+
result := txn.Clauses(clause.OnConflict{
206205
Columns: []clause.Column{{Name: "pool_key_hash"}},
207206
UpdateAll: true,
208-
}
209-
result := txn.Clauses(onConflict).Create(&tmpPool)
207+
}).Create(&tmpPool)
210208
if result.Error != nil {
211209
return result.Error
212210
}
@@ -227,7 +225,9 @@ func (d *MetadataStoreSqlite) SetPoolRetirement(
227225
return err
228226
}
229227
if tmpPool == nil {
230-
return models.ErrPoolNotFound
228+
d.logger.Warn("retiring non-existent pool", "hash", cert.PoolKeyHash)
229+
tmpPool = &models.Pool{PoolKeyHash: cert.PoolKeyHash[:]}
230+
// return models.ErrPoolNotFound
231231
}
232232
tmpItem := models.PoolRetirement{
233233
PoolKeyHash: cert.PoolKeyHash[:],

ledger/view.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
package ledger
1616

1717
import (
18+
"errors"
1819
"time"
1920

2021
"github.com/blinklabs-io/dingo/database"
22+
"github.com/blinklabs-io/dingo/database/models"
2123
"github.com/blinklabs-io/gouroboros/cbor"
2224
lcommon "github.com/blinklabs-io/gouroboros/ledger/common"
2325
)
@@ -82,7 +84,11 @@ func (lv *LedgerView) PoolCurrentState(
8284
) (*lcommon.PoolRegistrationCertificate, *uint64, error) {
8385
pool, err := lv.ls.db.GetPool(pkh, lv.txn)
8486
if err != nil {
85-
return nil, nil, err
87+
if errors.Is(err, models.ErrPoolNotFound) {
88+
pool = &models.Pool{}
89+
} else {
90+
return nil, nil, err
91+
}
8692
}
8793
var currentReg *lcommon.PoolRegistrationCertificate
8894
if len(pool.Registration) > 0 {

0 commit comments

Comments
 (0)