Skip to content

Commit c614a36

Browse files
committed
Load mutilple datacompressor in order
1 parent a49d037 commit c614a36

File tree

2 files changed

+27
-15
lines changed

2 files changed

+27
-15
lines changed

core/data_compressor_wrapper.go

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/ethereum/go-ethereum/accounts/abi/bind"
1212
"github.com/ethereum/go-ethereum/common"
1313
"sort"
14+
"strconv"
1415
"sync"
1516
)
1617

@@ -50,7 +51,11 @@ func (dcw *DataCompressorWrapper) getDataCompressorIndex(blockNum int64) string
5051
return name
5152
}
5253

54+
// the data compressor are added in increasing order of blockNum
5355
func (dcw *DataCompressorWrapper) AddDataCompressor(blockNum int64, addr string) {
56+
if len(dcw.DCBlockNum) > 0 && dcw.DCBlockNum[len(dcw.DCBlockNum)-1] >= blockNum {
57+
log.Fatal("Current dc added at :%v, new dc:%s added at %d ", dcw.DCBlockNum, addr, blockNum)
58+
}
5459
chainId, err := dcw.client.ChainID(context.TODO())
5560
log.CheckFatal(err)
5661
var key string
@@ -67,9 +72,27 @@ func (dcw *DataCompressorWrapper) AddDataCompressor(blockNum int64, addr string)
6772
dcw.BlockNumToName[blockNum] = key
6873
dcw.NameToAddr[key] = addr
6974
dcw.DCBlockNum = append(dcw.DCBlockNum, blockNum)
70-
arr := dcw.DCBlockNum
71-
sort.Slice(arr, func(i, j int) bool { return arr[i] < arr[j] })
72-
dcw.DCBlockNum = arr
75+
}
76+
77+
func (dcw *DataCompressorWrapper) LoadMultipleDC(multiDCs interface{}) {
78+
dcMap, ok := (multiDCs).(map[string]interface{})
79+
if !ok {
80+
log.Fatalf("Converting address provider() details for dc to map failed %v", multiDCs)
81+
}
82+
var blockNums []int64
83+
for k := range dcMap {
84+
blockNum, err := strconv.ParseInt(k, 10, 64)
85+
if err != nil {
86+
log.Fatal(err)
87+
}
88+
blockNums = append(blockNums, blockNum)
89+
}
90+
sort.Slice(blockNums, func(i, j int) bool { return blockNums[i] < blockNums[j] })
91+
for _, blockNum := range blockNums {
92+
k := fmt.Sprintf("%d", blockNum)
93+
dcAddr := dcMap[k]
94+
dcw.AddDataCompressor(blockNum, dcAddr.(string))
95+
}
7396
}
7497

7598
func (dcw *DataCompressorWrapper) GetCreditAccountDataExtended(opts *bind.CallOpts, creditManager common.Address, borrower common.Address) (mainnet.DataTypesCreditAccountDataExtended, error) {

repository/sync_adapter.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"github.com/Gearbox-protocol/third-eye/models/pool"
1414
"github.com/Gearbox-protocol/third-eye/models/price_oracle"
1515
"github.com/Gearbox-protocol/third-eye/models/yearn_price_feed"
16-
"strconv"
1716
)
1817

1918
func (repo *Repository) loadSyncAdapters() {
@@ -36,17 +35,7 @@ func (repo *Repository) prepareSyncAdapter(adapter *core.SyncAdapter) core.SyncA
3635
case core.AddressProvider:
3736
ap := address_provider.NewAddressProviderFromAdapter(adapter)
3837
if ap.Details["dc"] != nil {
39-
dcMap, ok := (ap.Details["dc"]).(map[string]interface{})
40-
if !ok {
41-
log.Fatalf("Converting address provider() details for dc to map failed %v", ap.Details["dc"])
42-
}
43-
for k, dcAddr := range dcMap {
44-
blockNum, err := strconv.ParseInt(k, 10, 64)
45-
if err != nil {
46-
log.Fatal(err)
47-
}
48-
repo.AddDataCompressor(blockNum, dcAddr.(string))
49-
}
38+
repo.dcWrapper.LoadMultipleDC(ap.Details["dc"])
5039
}
5140
if ap.Details["weth"] != nil {
5241
weth, ok := (ap.Details["weth"]).(string)

0 commit comments

Comments
 (0)