From d28a2d45a2d9f6f958b605fc9e7e13434a585ed0 Mon Sep 17 00:00:00 2001 From: harsh-98 Date: Sat, 17 Feb 2024 16:05:56 +0400 Subject: [PATCH] fix: mergedPFVersion for chainlink/composite pf --- ds/mergedPFVersion.go | 6 +++--- models/chainlink_price_feed/model.go | 2 +- models/chainlink_price_feed/on_log.go | 4 ++-- models/chainlink_price_feed/on_logs_test.go | 3 ++- models/composite_chainlink/model.go | 2 +- models/composite_chainlink/on_log.go | 4 ++-- 6 files changed, 11 insertions(+), 10 deletions(-) diff --git a/ds/mergedPFVersion.go b/ds/mergedPFVersion.go index 34aa72d6..1ba69ddc 100644 --- a/ds/mergedPFVersion.go +++ b/ds/mergedPFVersion.go @@ -61,16 +61,16 @@ func (mdl *MergedPFManager) Load(details core.Json, discoveredAt int64) { func (mdl MergedPFManager) Save(details *core.Json) { (*details)["mergedPFVersion"] = mdl - log.Info((*details)["mergedPFVersion"]) + // log.Info(utils.ToJson((*details)["mergedPFVersion"])) } -func (mdl MergedPFManager) GetMergedPFVersion(blockNum int64) schemas.MergedPFVersion { +func (mdl MergedPFManager) GetMergedPFVersion(blockNum int64, syncAdapterAddr string) schemas.MergedPFVersion { for _, entry := range mdl { if entry.BlockNumber <= blockNum { return entry.MergedPFVersion } } - log.Fatal("Can't get mergedPFVersion", mdl) + log.Fatal("Can't get mergedPFVersion", mdl, blockNum, syncAdapterAddr) return schemas.MergedPFVersion(0) } func (mdl *MergedPFManager) AddToken(token string, blockNum int64, pfVersion schemas.PFVersion) { diff --git a/models/chainlink_price_feed/model.go b/models/chainlink_price_feed/model.go index 46fafcc2..05cea955 100644 --- a/models/chainlink_price_feed/model.go +++ b/models/chainlink_price_feed/model.go @@ -95,7 +95,7 @@ func NewChainlinkPriceFeedFromAdapter(adapter *ds.SyncAdapter, includeLastLogBef } obj.DataProcessType = ds.ViaMultipleLogs obj.mergedPFManager = &ds.MergedPFManager{} - obj.mergedPFManager.Load(obj.Details, obj.DiscoveredAt) + obj.mergedPFManager.Load(obj.Details, obj.FirstLogAt) return obj } diff --git a/models/chainlink_price_feed/on_log.go b/models/chainlink_price_feed/on_log.go index e290c271..213e3a29 100644 --- a/models/chainlink_price_feed/on_log.go +++ b/models/chainlink_price_feed/on_log.go @@ -58,7 +58,7 @@ func (mdl *ChainlinkPriceFeed) OnLogs(txLogs []types.Log) { RoundId: roundId, PriceBI: (*core.BigInt)(answerBI), Price: utils.GetFloat64Decimal(answerBI, pfVersion.Decimals()), - MergedPFVersion: mdl.mergedPFManager.GetMergedPFVersion(blockNum), + MergedPFVersion: mdl.mergedPFManager.GetMergedPFVersion(blockNum, mdl.Address), } mdl.Repo.AddPriceFeed(priceFeed) blockNums = append(blockNums, blockNum) @@ -77,7 +77,7 @@ func (mdl *ChainlinkPriceFeed) AddToken(token string, blockNum int64, pfVersion func (mdl ChainlinkPriceFeed) DisableToken(token string, blockNum int64, pfVersion schemas.PFVersion) { mdl.mergedPFManager.DisableToken(token, blockNum, pfVersion) - final := mdl.mergedPFManager.GetMergedPFVersion(blockNum) + final := mdl.mergedPFManager.GetMergedPFVersion(blockNum, mdl.Address) if final == 0 { mdl.SetBlockToDisableOn(blockNum) } diff --git a/models/chainlink_price_feed/on_logs_test.go b/models/chainlink_price_feed/on_logs_test.go index d5c9b638..82091de9 100644 --- a/models/chainlink_price_feed/on_logs_test.go +++ b/models/chainlink_price_feed/on_logs_test.go @@ -36,12 +36,13 @@ func TestOnLogs(t *testing.T) { Contract: &schemas.Contract{ Address: validPf.Feed, DiscoveredAt: 1, + FirstLogAt: 1, }, V: core.NewVersion(1), Details: core.Json{"token": validPf.Token, "mergedPFVersion": validPf.MergedPFVersion}, }, }, mergedPFManager: &ds.MergedPFManager{}} - obj.mergedPFManager.Load(obj.Details, obj.DiscoveredAt) + obj.mergedPFManager.Load(obj.Details, obj.FirstLogAt) txLogs := []types.Log{ { BlockNumber: 1, diff --git a/models/composite_chainlink/model.go b/models/composite_chainlink/model.go index ad732399..5806e5e5 100644 --- a/models/composite_chainlink/model.go +++ b/models/composite_chainlink/model.go @@ -100,7 +100,7 @@ func NewCompositeChainlinkPFFromAdapter(adapter *ds.SyncAdapter) *CompositeChain compositeMdl.setPrices(adapter.LastSync) // compositeMdl.mergedPFManager = &ds.MergedPFManager{} - compositeMdl.mergedPFManager.Load(compositeMdl.Details, compositeMdl.DiscoveredAt) + compositeMdl.mergedPFManager.Load(compositeMdl.Details, compositeMdl.FirstLogAt) return compositeMdl } diff --git a/models/composite_chainlink/on_log.go b/models/composite_chainlink/on_log.go index 4752a316..61bedd60 100644 --- a/models/composite_chainlink/on_log.go +++ b/models/composite_chainlink/on_log.go @@ -113,7 +113,7 @@ func (mdl *CompositeChainlinkPF) addPriceToDB(blockNum int64) { RoundId: 0, PriceBI: (*core.BigInt)(answerBI), Price: utils.GetFloat64Decimal(answerBI, 8), - MergedPFVersion: mdl.mergedPFManager.GetMergedPFVersion(blockNum), + MergedPFVersion: mdl.mergedPFManager.GetMergedPFVersion(blockNum, mdl.Address), } mdl.Repo.AddPriceFeed(priceFeed) } @@ -128,7 +128,7 @@ func (mdl *CompositeChainlinkPF) AddToken(token string, blockNum int64, pfVersio func (mdl CompositeChainlinkPF) DisableToken(token string, blockNum int64, pfVersion schemas.PFVersion) { mdl.mergedPFManager.DisableToken(token, blockNum, pfVersion) - final := mdl.mergedPFManager.GetMergedPFVersion(blockNum) + final := mdl.mergedPFManager.GetMergedPFVersion(blockNum, mdl.Address) if final == 0 { mdl.SetBlockToDisableOn(blockNum) }