Merge pull request #793 from filecoin-project/feat/chainwatch-block-add-ts

chainwatch: Collect incoming block tstamps
This commit is contained in:
Łukasz Magiera 2019-12-08 23:31:55 +01:00 committed by GitHub
commit dec458718f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -113,7 +113,8 @@ create table if not exists blocks_synced
constraint blocks_synced_pk constraint blocks_synced_pk
primary key primary key
constraint blocks_synced_blocks_cid_fk constraint blocks_synced_blocks_cid_fk
references blocks references blocks,
add_ts int not null
); );
create unique index if not exists blocks_synced_cid_uindex create unique index if not exists blocks_synced_cid_uindex
@ -316,13 +317,15 @@ func (st *storage) storeHeaders(bhs map[cid.Cid]*types.BlockHeader, sync bool) e
} }
if sync { if sync {
stmt, err := tx.Prepare(`insert into blocks_synced (cid) values (?) on conflict do nothing`) stmt, err := tx.Prepare(`insert into blocks_synced (cid, add_ts) values (?, ?) on conflict do nothing`)
if err != nil { if err != nil {
return err return err
} }
defer stmt.Close() defer stmt.Close()
now := time.Now().Unix()
for _, bh := range bhs { for _, bh := range bhs {
if _, err := stmt.Exec(bh.Cid().String()); err != nil { if _, err := stmt.Exec(bh.Cid().String(), now); err != nil {
return err return err
} }
} }