Skip to content

Commit

Permalink
fix(chainwatch): Upsert on chain_economics
Browse files Browse the repository at this point in the history
This table may get multiple updates depending on how many blocks get
added into a tipset. Each new block affects the tipset state, but the
parent state root will remain the same. This allows the very latest
value to be applied.
  • Loading branch information
placer14 committed Aug 28, 2020
1 parent 9e130af commit 5caafcb
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions cmd/lotus-chainwatch/syncer/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,10 @@ func (s *Syncer) storeCirculatingSupply(ctx context.Context, tipset *types.TipSe
return err
}

ceInsert := `insert into chain_economics (parent_state_root, circulating_fil, vested_fil, mined_fil, burnt_fil, locked_fil)` +
`values ('%s', '%s', '%s', '%s', '%s', '%s');`
ceInsert := `insert into chain_economics (parent_state_root, circulating_fil, vested_fil, mined_fil, burnt_fil, locked_fil) ` +
`values ('%s', '%s', '%s', '%s', '%s', '%s') on conflict on constraint chain_economics_pk do ` +
`update set (circulating_fil, vested_fil, mined_fil, burnt_fil, locked_fil) = ('%[2]s', '%[3]s', '%[4]s', '%[5]s', '%[6]s') ` +
`where parent_state_root = '%[1]s';`

if _, err := s.db.Exec(fmt.Sprintf(ceInsert,
tipset.ParentState().String(),
Expand Down

0 comments on commit 5caafcb

Please sign in to comment.