2019-11-15 16:38:56 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
2019-11-19 12:57:16 +00:00
|
|
|
"sync"
|
2019-11-17 12:01:10 +00:00
|
|
|
"time"
|
2019-11-15 18:37:57 +00:00
|
|
|
|
2019-11-15 16:38:56 +00:00
|
|
|
"github.com/ipfs/go-cid"
|
2019-12-10 23:42:36 +00:00
|
|
|
_ "github.com/lib/pq"
|
2019-11-15 18:37:57 +00:00
|
|
|
|
|
|
|
"github.com/filecoin-project/lotus/chain/address"
|
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
2019-11-15 16:38:56 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type storage struct {
|
|
|
|
db *sql.DB
|
2019-11-19 12:57:16 +00:00
|
|
|
|
|
|
|
headerLk sync.Mutex
|
2019-11-15 16:38:56 +00:00
|
|
|
}
|
|
|
|
|
2019-12-05 11:58:19 +00:00
|
|
|
func openStorage(dbSource string) (*storage, error) {
|
2019-12-10 23:42:36 +00:00
|
|
|
db, err := sql.Open("postgres", dbSource)
|
2019-11-15 16:38:56 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
st := &storage{db: db}
|
|
|
|
|
|
|
|
return st, st.setup()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (st *storage) setup() error {
|
|
|
|
tx, err := st.db.Begin()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
_, err = tx.Exec(`
|
2019-12-10 23:42:36 +00:00
|
|
|
create table if not exists blocks_synced
|
|
|
|
(
|
|
|
|
cid text not null
|
|
|
|
constraint blocks_synced_pk
|
|
|
|
primary key,
|
|
|
|
add_ts int not null
|
|
|
|
);
|
|
|
|
|
|
|
|
create unique index if not exists blocks_synced_cid_uindex
|
|
|
|
on blocks_synced (cid);
|
|
|
|
|
|
|
|
create table if not exists block_parents
|
|
|
|
(
|
|
|
|
block text not null
|
|
|
|
constraint block_parents_pk
|
|
|
|
primary key,
|
|
|
|
parent text not null
|
|
|
|
);
|
|
|
|
|
|
|
|
create unique index if not exists block_parents_block_parent_uindex
|
|
|
|
on block_parents (block, parent);
|
|
|
|
|
|
|
|
create table if not exists blocks
|
|
|
|
(
|
|
|
|
cid text not null
|
|
|
|
constraint blocks_pk
|
2019-12-11 22:17:44 +00:00
|
|
|
primary key,
|
2019-12-10 23:42:36 +00:00
|
|
|
parentWeight numeric not null,
|
|
|
|
parentStateRoot text not null,
|
|
|
|
height int not null,
|
|
|
|
miner text not null,
|
2019-12-12 16:56:57 +00:00
|
|
|
timestamp int not null,
|
|
|
|
vrfproof bytea,
|
|
|
|
tickets int not null,
|
|
|
|
eprof bytea,
|
|
|
|
prand bytea,
|
|
|
|
ep0partial bytea,
|
|
|
|
ep0sector int not null,
|
|
|
|
ep0challangei int not null
|
2019-12-10 23:42:36 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
create unique index if not exists block_cid_uindex
|
|
|
|
on blocks (cid);
|
|
|
|
|
|
|
|
create table if not exists id_address_map
|
|
|
|
(
|
|
|
|
id text not null,
|
|
|
|
address text not null,
|
|
|
|
constraint id_address_map_pk
|
|
|
|
primary key (id, address)
|
|
|
|
);
|
|
|
|
|
|
|
|
create unique index if not exists id_address_map_id_uindex
|
|
|
|
on id_address_map (id);
|
|
|
|
|
|
|
|
create unique index if not exists id_address_map_address_uindex
|
|
|
|
on id_address_map (address);
|
|
|
|
|
2019-11-16 19:47:06 +00:00
|
|
|
create table if not exists actors
|
2019-11-15 18:37:57 +00:00
|
|
|
(
|
2019-12-10 23:42:36 +00:00
|
|
|
id text not null
|
|
|
|
constraint id_address_map_actors_id_fk
|
|
|
|
references id_address_map (id),
|
2019-11-15 18:37:57 +00:00
|
|
|
code text not null,
|
|
|
|
head text not null,
|
|
|
|
nonce int not null,
|
2019-11-16 19:47:06 +00:00
|
|
|
balance text not null,
|
2019-11-16 12:34:52 +00:00
|
|
|
stateroot text
|
2019-11-15 18:37:57 +00:00
|
|
|
);
|
2019-11-16 19:47:06 +00:00
|
|
|
|
|
|
|
create index if not exists actors_id_index
|
|
|
|
on actors (id);
|
2019-11-15 18:37:57 +00:00
|
|
|
|
2019-11-16 19:47:06 +00:00
|
|
|
create index if not exists id_address_map_address_index
|
|
|
|
on id_address_map (address);
|
|
|
|
|
|
|
|
create index if not exists id_address_map_id_index
|
|
|
|
on id_address_map (id);
|
|
|
|
|
|
|
|
create table if not exists messages
|
2019-11-15 16:38:56 +00:00
|
|
|
(
|
|
|
|
cid text not null
|
|
|
|
constraint messages_pk
|
|
|
|
primary key,
|
2019-11-15 18:37:57 +00:00
|
|
|
"from" text not null
|
|
|
|
constraint messages_id_address_map_from_fk
|
|
|
|
references id_address_map (address),
|
|
|
|
"to" text not null
|
|
|
|
constraint messages_id_address_map_to_fk
|
|
|
|
references id_address_map (address),
|
2019-11-15 16:38:56 +00:00
|
|
|
nonce int not null,
|
|
|
|
value text not null,
|
|
|
|
gasprice int not null,
|
|
|
|
gaslimit int not null,
|
|
|
|
method int,
|
2019-12-10 23:42:36 +00:00
|
|
|
params bytea
|
2019-11-15 16:38:56 +00:00
|
|
|
);
|
|
|
|
|
2019-11-16 19:47:06 +00:00
|
|
|
create unique index if not exists messages_cid_uindex
|
2019-11-15 16:38:56 +00:00
|
|
|
on messages (cid);
|
|
|
|
|
2019-11-16 19:47:06 +00:00
|
|
|
create table if not exists block_messages
|
2019-11-15 16:38:56 +00:00
|
|
|
(
|
|
|
|
block text not null
|
|
|
|
constraint block_messages_blk_fk
|
|
|
|
references blocks (cid),
|
|
|
|
message text not null
|
|
|
|
constraint block_messages_msg_fk
|
|
|
|
references messages,
|
|
|
|
constraint block_messages_pk
|
2019-11-16 12:34:52 +00:00
|
|
|
primary key (block, message)
|
|
|
|
);
|
|
|
|
|
2019-11-17 12:01:10 +00:00
|
|
|
create table if not exists mpool_messages
|
|
|
|
(
|
|
|
|
msg text not null
|
|
|
|
constraint mpool_messages_pk
|
|
|
|
primary key
|
|
|
|
constraint mpool_messages_messages_cid_fk
|
|
|
|
references messages,
|
|
|
|
add_ts int not null
|
|
|
|
);
|
|
|
|
|
|
|
|
create unique index if not exists mpool_messages_msg_uindex
|
|
|
|
on mpool_messages (msg);
|
|
|
|
|
2019-12-03 11:05:12 +00:00
|
|
|
create table if not exists receipts
|
|
|
|
(
|
|
|
|
msg text not null
|
|
|
|
constraint receipts_messages_cid_fk
|
|
|
|
references messages,
|
2019-12-10 23:42:36 +00:00
|
|
|
state text not null,
|
2019-12-03 11:05:12 +00:00
|
|
|
idx int not null,
|
|
|
|
exit int not null,
|
|
|
|
gas_used int not null,
|
2019-12-10 23:42:36 +00:00
|
|
|
return bytea,
|
2019-12-03 11:05:12 +00:00
|
|
|
constraint receipts_pk
|
|
|
|
primary key (msg, state)
|
|
|
|
);
|
|
|
|
|
|
|
|
create index if not exists receipts_msg_state_index
|
|
|
|
on receipts (msg, state);
|
|
|
|
|
2019-11-16 19:47:06 +00:00
|
|
|
create table if not exists miner_heads
|
2019-11-16 12:34:52 +00:00
|
|
|
(
|
2019-12-10 23:42:36 +00:00
|
|
|
head text not null,
|
|
|
|
addr text not null,
|
|
|
|
stateroot text not null,
|
2019-11-16 12:34:52 +00:00
|
|
|
sectorset text not null,
|
2019-12-11 23:31:59 +00:00
|
|
|
setsize int not null,
|
2019-11-16 12:34:52 +00:00
|
|
|
provingset text not null,
|
2019-12-11 23:31:59 +00:00
|
|
|
provingsize int not null,
|
2019-11-16 12:34:52 +00:00
|
|
|
owner text not null,
|
|
|
|
worker text not null,
|
|
|
|
peerid text not null,
|
|
|
|
sectorsize int not null,
|
|
|
|
power text not null,
|
|
|
|
active int,
|
|
|
|
ppe int not null,
|
|
|
|
slashed_at int not null,
|
2019-11-16 19:47:06 +00:00
|
|
|
constraint miner_heads_id_address_map_owner_fk
|
|
|
|
foreign key (owner) references id_address_map (address),
|
|
|
|
constraint miner_heads_id_address_map_worker_fk
|
|
|
|
foreign key (worker) references id_address_map (address),
|
2019-11-16 12:34:52 +00:00
|
|
|
constraint miner_heads_pk
|
|
|
|
primary key (head, addr)
|
2019-11-15 16:38:56 +00:00
|
|
|
);
|
2019-11-16 12:34:52 +00:00
|
|
|
|
2019-11-15 16:38:56 +00:00
|
|
|
`)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return tx.Commit()
|
|
|
|
}
|
|
|
|
|
2019-12-11 22:17:44 +00:00
|
|
|
func (st *storage) hasList() map[cid.Cid]struct{} {
|
|
|
|
rws, err := st.db.Query(`select cid FROM blocks_synced`)
|
2019-11-15 16:38:56 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Error(err)
|
2019-12-11 22:17:44 +00:00
|
|
|
return map[cid.Cid]struct{}{}
|
2019-11-15 16:38:56 +00:00
|
|
|
}
|
2019-12-11 22:17:44 +00:00
|
|
|
out := map[cid.Cid]struct{}{}
|
|
|
|
|
|
|
|
for rws.Next() {
|
|
|
|
var c string
|
|
|
|
if err := rws.Scan(&c); err != nil {
|
|
|
|
log.Error(err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
ci, err := cid.Parse(c)
|
|
|
|
if err != nil {
|
|
|
|
log.Error(err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
out[ci] = struct{}{}
|
|
|
|
}
|
|
|
|
|
|
|
|
return out
|
2019-11-15 16:38:56 +00:00
|
|
|
}
|
|
|
|
|
2019-11-16 12:34:52 +00:00
|
|
|
func (st *storage) storeActors(actors map[address.Address]map[types.Actor]cid.Cid) error {
|
2019-11-15 16:38:56 +00:00
|
|
|
tx, err := st.db.Begin()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-12-10 23:42:36 +00:00
|
|
|
stmt, err := tx.Prepare(`insert into actors (id, code, head, nonce, balance, stateroot) values ($1, $2, $3, $4, $5, $6) on conflict do nothing`)
|
2019-11-15 18:37:57 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer stmt.Close()
|
|
|
|
for addr, acts := range actors {
|
2019-11-16 12:34:52 +00:00
|
|
|
for act, st := range acts {
|
|
|
|
if _, err := stmt.Exec(addr.String(), act.Code.String(), act.Head.String(), act.Nonce, act.Balance.String(), st.String()); err != nil {
|
2019-11-15 18:37:57 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return tx.Commit()
|
|
|
|
}
|
|
|
|
|
2019-11-16 12:34:52 +00:00
|
|
|
func (st *storage) storeMiners(miners map[minerKey]*minerInfo) error {
|
|
|
|
tx, err := st.db.Begin()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-12-12 16:56:57 +00:00
|
|
|
stmt, err := tx.Prepare(`insert into miner_heads (head, addr, stateroot, sectorset, setsize, provingset, provingsize, owner, worker, peerid, sectorsize, power, active, ppe, slashed_at) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15) on conflict do nothing`)
|
2019-11-16 12:34:52 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer stmt.Close()
|
|
|
|
for k, i := range miners {
|
|
|
|
if _, err := stmt.Exec(
|
|
|
|
k.act.Head.String(),
|
|
|
|
k.addr.String(),
|
|
|
|
k.stateroot.String(),
|
|
|
|
i.state.Sectors.String(),
|
2019-12-11 23:31:59 +00:00
|
|
|
i.ssize,
|
2019-11-16 12:34:52 +00:00
|
|
|
i.state.ProvingSet.String(),
|
2019-12-11 23:31:59 +00:00
|
|
|
i.psize,
|
2019-11-16 12:34:52 +00:00
|
|
|
i.info.Owner.String(),
|
|
|
|
i.info.Worker.String(),
|
|
|
|
i.info.PeerID.String(),
|
|
|
|
i.info.SectorSize,
|
|
|
|
i.state.Power.String(),
|
|
|
|
i.state.Active,
|
2019-11-30 04:31:16 +00:00
|
|
|
i.state.ElectionPeriodStart,
|
2019-11-16 12:34:52 +00:00
|
|
|
i.state.SlashedAt,
|
|
|
|
); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return tx.Commit()
|
|
|
|
}
|
|
|
|
|
2019-11-19 12:57:16 +00:00
|
|
|
func (st *storage) storeHeaders(bhs map[cid.Cid]*types.BlockHeader, sync bool) error {
|
|
|
|
st.headerLk.Lock()
|
|
|
|
defer st.headerLk.Unlock()
|
|
|
|
|
2019-11-15 18:37:57 +00:00
|
|
|
tx, err := st.db.Begin()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-12-12 16:56:57 +00:00
|
|
|
stmt, err := tx.Prepare(`insert into block_parents (block, parent) values ($1, $2) on conflict do nothing`)
|
2019-11-15 16:38:56 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer stmt.Close()
|
2019-11-15 18:37:57 +00:00
|
|
|
|
2019-12-12 16:56:57 +00:00
|
|
|
for _, bh := range bhs {
|
2019-11-18 20:11:43 +00:00
|
|
|
for _, parent := range bh.Parents {
|
2019-12-12 16:56:57 +00:00
|
|
|
if _, err := stmt.Exec(bh.Cid().String(), parent.String()); err != nil {
|
2019-12-11 22:17:44 +00:00
|
|
|
log.Error(err)
|
|
|
|
}
|
2019-11-18 20:11:43 +00:00
|
|
|
}
|
2019-12-12 16:56:57 +00:00
|
|
|
}
|
2019-11-18 20:11:43 +00:00
|
|
|
|
2019-11-19 12:57:16 +00:00
|
|
|
if sync {
|
2019-12-08 15:49:13 +00:00
|
|
|
now := time.Now().Unix()
|
|
|
|
|
2019-12-12 16:56:57 +00:00
|
|
|
stmt, err := tx.Prepare(`insert into blocks_synced (cid, add_ts) values ($1, $2) on conflict do nothing`)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer stmt.Close()
|
|
|
|
|
|
|
|
for _, bh := range bhs {
|
|
|
|
if _, err := tx.Exec(bh.Cid().String(), now); err != nil {
|
2019-12-11 22:17:44 +00:00
|
|
|
log.Error(err)
|
2019-11-19 12:57:16 +00:00
|
|
|
}
|
2019-12-12 16:56:57 +00:00
|
|
|
}
|
2019-11-19 12:57:16 +00:00
|
|
|
}
|
|
|
|
|
2019-12-12 16:56:57 +00:00
|
|
|
stmt2, err := tx.Prepare(`insert into blocks (cid, parentWeight, parentStateRoot, height, miner, "timestamp", vrfproof, tickets, eprof, prand, ep0partial, ep0sector, ep0challangei) values ($1, $2, $3, $4, $5, $6,$7,$8,$9,$10,$11,$12,$13) on conflict do nothing`)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer stmt2.Close()
|
|
|
|
|
2019-11-15 16:38:56 +00:00
|
|
|
for _, bh := range bhs {
|
2019-12-12 13:53:38 +00:00
|
|
|
l := len(bh.EPostProof.Candidates)
|
|
|
|
if len(bh.EPostProof.Candidates) == 0 {
|
|
|
|
bh.EPostProof.Candidates = append(bh.EPostProof.Candidates, types.EPostTicket{})
|
|
|
|
}
|
|
|
|
|
2019-12-12 16:56:57 +00:00
|
|
|
if _, err := stmt2.Exec(
|
|
|
|
bh.Cid().String(),
|
2019-12-12 13:53:38 +00:00
|
|
|
bh.ParentWeight.String(),
|
|
|
|
bh.ParentStateRoot.String(),
|
|
|
|
bh.Height,
|
|
|
|
bh.Miner.String(),
|
|
|
|
bh.Timestamp,
|
|
|
|
bh.Ticket.VRFProof,
|
|
|
|
l,
|
|
|
|
bh.EPostProof.Proof,
|
|
|
|
bh.EPostProof.PostRand,
|
|
|
|
bh.EPostProof.Candidates[0].Partial,
|
|
|
|
bh.EPostProof.Candidates[0].SectorID,
|
2019-12-12 16:56:57 +00:00
|
|
|
bh.EPostProof.Candidates[0].ChallengeIndex); err != nil {
|
2019-12-11 22:17:44 +00:00
|
|
|
log.Error(err)
|
2019-12-10 23:42:36 +00:00
|
|
|
}
|
2019-11-15 16:38:56 +00:00
|
|
|
}
|
2019-12-10 23:42:36 +00:00
|
|
|
|
2019-12-11 22:17:44 +00:00
|
|
|
return nil
|
2019-11-15 16:38:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (st *storage) storeMessages(msgs map[cid.Cid]*types.Message) error {
|
|
|
|
tx, err := st.db.Begin()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-12-10 23:42:36 +00:00
|
|
|
stmt, err := tx.Prepare(`insert into messages (cid, "from", "to", nonce, "value", gasprice, gaslimit, method, params) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9) on conflict do nothing`)
|
2019-11-15 16:38:56 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer stmt.Close()
|
|
|
|
|
|
|
|
for c, m := range msgs {
|
|
|
|
if _, err := stmt.Exec(
|
|
|
|
c.String(),
|
|
|
|
m.From.String(),
|
|
|
|
m.To.String(),
|
|
|
|
m.Nonce,
|
|
|
|
m.Value.String(),
|
|
|
|
m.GasPrice.String(),
|
|
|
|
m.GasLimit.String(),
|
|
|
|
m.Method,
|
|
|
|
m.Params,
|
|
|
|
); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return tx.Commit()
|
|
|
|
}
|
|
|
|
|
2019-12-03 11:05:12 +00:00
|
|
|
func (st *storage) storeReceipts(recs map[mrec]*types.MessageReceipt) error {
|
|
|
|
tx, err := st.db.Begin()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-12-10 23:42:36 +00:00
|
|
|
stmt, err := tx.Prepare(`insert into receipts (msg, state, idx, exit, gas_used, return) VALUES ($1,$2,$3,$4,$5,$6) on conflict do nothing`)
|
2019-12-03 11:05:12 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer stmt.Close()
|
|
|
|
|
|
|
|
for c, m := range recs {
|
|
|
|
if _, err := stmt.Exec(
|
|
|
|
c.msg.String(),
|
|
|
|
c.state.String(),
|
|
|
|
c.idx,
|
|
|
|
m.ExitCode,
|
|
|
|
m.GasUsed.String(),
|
|
|
|
m.Return,
|
|
|
|
); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return tx.Commit()
|
|
|
|
}
|
|
|
|
|
2019-11-15 18:37:57 +00:00
|
|
|
func (st *storage) storeAddressMap(addrs map[address.Address]address.Address) error {
|
|
|
|
tx, err := st.db.Begin()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-12-10 23:42:36 +00:00
|
|
|
stmt, err := tx.Prepare(`insert into id_address_map (id, address) VALUES ($1, $2) on conflict do nothing`)
|
2019-11-15 18:37:57 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer stmt.Close()
|
|
|
|
|
|
|
|
for a, i := range addrs {
|
|
|
|
if i == address.Undef {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if _, err := stmt.Exec(
|
|
|
|
i.String(),
|
|
|
|
a.String(),
|
|
|
|
); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return tx.Commit()
|
|
|
|
}
|
|
|
|
|
2019-11-15 16:38:56 +00:00
|
|
|
func (st *storage) storeMsgInclusions(incls map[cid.Cid][]cid.Cid) error {
|
|
|
|
tx, err := st.db.Begin()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-12-10 23:42:36 +00:00
|
|
|
stmt, err := tx.Prepare(`insert into block_messages (block, message) VALUES ($1, $2) on conflict do nothing`)
|
2019-11-15 16:38:56 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer stmt.Close()
|
|
|
|
|
|
|
|
for b, msgs := range incls {
|
|
|
|
for _, msg := range msgs {
|
|
|
|
if _, err := stmt.Exec(
|
|
|
|
b.String(),
|
|
|
|
msg.String(),
|
|
|
|
); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return tx.Commit()
|
|
|
|
}
|
|
|
|
|
2019-11-17 12:01:10 +00:00
|
|
|
func (st *storage) storeMpoolInclusion(msg cid.Cid) error {
|
|
|
|
tx, err := st.db.Begin()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-12-10 23:42:36 +00:00
|
|
|
stmt, err := tx.Prepare(`insert into mpool_messages (msg, add_ts) VALUES ($1, $2) on conflict do nothing`)
|
2019-11-17 12:01:10 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer stmt.Close()
|
|
|
|
|
|
|
|
if _, err := stmt.Exec(
|
|
|
|
msg.String(),
|
|
|
|
time.Now().Unix(),
|
|
|
|
); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return tx.Commit()
|
|
|
|
}
|
|
|
|
|
2019-11-15 16:38:56 +00:00
|
|
|
func (st *storage) close() error {
|
|
|
|
return st.db.Close()
|
|
|
|
}
|