Skip to content

Commit 0860f98

Browse files
committed
fix: db error duplicate rows with not unique constrained value
1 parent a22cbf3 commit 0860f98

File tree

5 files changed

+17
-1
lines changed

5 files changed

+17
-1
lines changed

cmd/main.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ package main
88

99
import (
1010
"context"
11+
_ "net/http/pprof"
12+
"time"
13+
1114
"github.com/Gearbox-protocol/sdk-go/log"
1215
"github.com/Gearbox-protocol/third-eye/config"
1316
"github.com/Gearbox-protocol/third-eye/debts"
@@ -18,9 +21,14 @@ import (
1821
"github.com/Gearbox-protocol/third-eye/services"
1922
_ "github.com/heroku/x/hmetrics/onload"
2023
"go.uber.org/fx"
21-
"time"
2224
)
2325

26+
// func init() {
27+
// go func() {
28+
// http.ListenAndServe(":8080", nil)
29+
// }()
30+
// }
31+
2432
func StartServer(lc fx.Lifecycle, engine ds.EngineI, config *config.Config) {
2533
log.NewAMQPService(config.ChainId, config.AMPQEnable, config.AMPQUrl, "Third-eye")
2634
// Starting server

models/credit_manager/credit_session_state.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ func (mdl *CreditManager) closeSession(sessionId string, blockNum int64, closeDe
4949
amountToPool = data.LiquidationAmount
5050
}
5151
// pool repay
52+
// check for avoiding db errors
5253
mdl.PoolRepay(blockNum,
5354
closeDetails.LogId,
5455
closeDetails.TxHash,

models/credit_manager/v1operation.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ func (mdl *CreditManager) onCloseCreditAccount(txLog *types.Log, owner, to strin
8989
}
9090
mdl.AddAccountOperation(accountOperation)
9191
mdl.ClosedSessions[sessionId] = &SessionCloseDetails{
92+
LogId: txLog.Index,
9293
RemainingFunds: remainingFunds,
9394
Status: schemas.Closed,
9495
TxHash: txLog.TxHash.Hex(),
@@ -122,6 +123,7 @@ func (mdl *CreditManager) onLiquidateCreditAccount(txLog *types.Log, owner, liqu
122123
}
123124
mdl.AddAccountOperation(accountOperation)
124125
mdl.ClosedSessions[sessionId] = &SessionCloseDetails{
126+
LogId: txLog.Index,
125127
RemainingFunds: remainingFunds,
126128
Status: schemas.Liquidated,
127129
TxHash: txLog.TxHash.Hex(),

models/credit_manager/v2operation.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ func (mdl *CreditManager) onCloseCreditAccountV2(txLog *types.Log, owner, to str
199199
mdl.GetUnderlyingToken(), mdl.GetUnderlyingDecimal(), prices))
200200
session.RemainingFunds = (*core.BigInt)(remainingFunds)
201201
mdl.ClosedSessions[sessionId] = &SessionCloseDetails{
202+
LogId: txLog.Index,
202203
RemainingFunds: remainingFunds,
203204
Status: schemas.Closed,
204205
TxHash: txLog.TxHash.Hex(),
@@ -251,6 +252,7 @@ func (mdl *CreditManager) onLiquidateCreditAccountV2(txLog *types.Log, owner, li
251252
// process multicalls
252253
mdl.multiCallHandler(accountOperation)
253254
mdl.ClosedSessions[sessionId] = &SessionCloseDetails{
255+
LogId: txLog.Index,
254256
RemainingFunds: remainingFunds,
255257
Status: schemas.Liquidated,
256258
TxHash: txLog.TxHash.Hex(),

repository/handlers/blocks.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ func (repo *BlocksRepo) Save(tx *gorm.DB) {
5353
defer utils.Elapsed("blocks sql statements")()
5454
blocksToSync := make([]*schemas.Block, 0, len(repo.GetBlocks()))
5555
for _, block := range repo.GetBlocks() {
56+
if len(block.PoolLedgers) > 0 {
57+
log.Info(utils.ToJson(block.PoolLedgers))
58+
}
5659
blocksToSync = append(blocksToSync, block)
5760
}
5861
// clauses not needed here

0 commit comments

Comments
 (0)