Skip to content

Commit

Permalink
fix: reset blocks in adapters
Browse files Browse the repository at this point in the history
  • Loading branch information
harsh-98 committed Mar 7, 2024
1 parent 73ae1ce commit 2cbc2d9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion db_scripts/local_testing/anvil_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ set -e
PWD=`pwd`
LOCAL_DB="host=localhost user=debian dbname=sample"
cd /home/debian/anvil-third-eye
# go run "scripts/merged_pf_version_reset/main.go" "$LOCAL_DB" $FORK_BLOCK
go run "scripts/merged_pf_version_reset/main.go" "$LOCAL_DB" $FORK_BLOCK
cd $PWD
createdb -O $SUPERUSER -T sample tmp_sample

Expand Down
17 changes: 17 additions & 0 deletions ds/mergedPFVersion.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func (mdl *MergedPFManager) Load(details core.Json, discoveredAt int64) {
}
case map[string]interface{}:
for token, det := range v {
log.Info(token, det)
snaps := det.([]interface{})
for _, snap := range snaps {
snapDetails := snap.(map[string]interface{})
Expand Down Expand Up @@ -137,3 +138,19 @@ func (mdl MergedPFManager) DisableToken(blockNum int64, token string, pfVersion
BlockNumber: blockNum,
})
}

func (mdl MergedPFManager) DeleteAfter(blockNum int64) {
for token, entries := range mdl {
var newEntries []entry
for _, entry := range entries {
if entry.BlockNumber <= blockNum {
newEntries = append(newEntries, entry)
}
}
if len(newEntries) == 0 {
delete(mdl, token)
} else {
mdl[token] = newEntries
}
}
}
2 changes: 1 addition & 1 deletion scripts/merged_pf_version_reset/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func main() {
} else {
mgr := ds.MergedPFManager{}
mgr.Load(adapter.GetDetails(), adapter.FirstLogAt)
// mgr.DeleteAfter(deletedB)
mgr.DeleteAfter(deletedB)
mgr.Save(&adapter.Details)
}
}
Expand Down

0 comments on commit 2cbc2d9

Please sign in to comment.