Add all challenges to chainwatch

Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
This commit is contained in:
Jakub Sztandera 2020-01-27 12:16:08 -08:00
parent c765289da9
commit 752be27815
No known key found for this signature in database
GPG Key ID: 9A9AF56F8B3879BA

View File

@ -302,6 +302,30 @@ create index if not exists deal_activations_activation_epoch_index
create unique index if not exists deal_activations_deal_uindex
on deal_activations (deal);
create table if not exists blocks_challenges
(
block text not null
constraint blocks_challenges_pk_2
primary key
constraint blocks_challenges_blocks_cid_fk
references blocks,
index bigint not null,
sector_id bigint not null,
partial bytea not null,
constraint blocks_challenges_pk
unique (block, index)
);
create index if not exists blocks_challenges_block_index
on blocks_challenges (block);
create index if not exists blocks_challenges_block_index_index
on blocks_challenges (block, index);
create index if not exists blocks_challenges_index_index
on blocks_challenges (index);
`)
if err != nil {
return err
@ -527,7 +551,7 @@ create temp table b (like blocks excluding constraints) on commit drop;
}
}
stmt2, err := tx.Prepare(`copy b (cid, parentWeight, parentStateRoot, height, miner, "timestamp", vrfproof, tickets, eprof, prand, ep0partial, ep0sector, ep0challangei) from stdin `)
stmt2, err := tx.Prepare(`copy b (cid, parentWeight, parentStateRoot, height, miner, "timestamp", vrfproof, tickets, eprof, prand, ep0partial, ep0sector, ep0challangei) from stdin`)
if err != nil {
return err
}
@ -565,9 +589,42 @@ create temp table b (like blocks excluding constraints) on commit drop;
}
err = tx.Commit()
if err != nil {
return xerrors.Errorf("commit: %w", err)
}
stmt3, err := tx.Prepare(`copy c(block, index, sector_id, parital) from stdin`)
if err != nil {
return xerrors.Errorf("s3 create: %w")
}
for _, bh := range bhs {
for index, c := range bh.EPostProof.Candidates {
if _, err := stmt3.Exec(
bh.Cid().String(),
index,
c.Partial,
c.SectorID,
c.ChallengeIndex); err != nil {
log.Error(err)
}
}
}
if err := stmt3.Close(); err != nil {
return xerrors.Errorf("s2 close: %w", err)
}
if _, err := tx.Exec(`insert into blocks_challenges * from c on conflict do nothing `); err != nil {
return xerrors.Errorf("blk put: %w", err)
}
err = tx.Commit()
if err != nil {
return xerrors.Errorf("commit: %w", err)
}
return nil
}