Skip to content

Commit d2ee36d

Browse files
author
Abdul Rabbani
committed
Update upsert for eth.header_cids
1 parent 8593cfd commit d2ee36d

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

statediff/indexer/database/sql/postgres/database.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ type DB struct {
4040
func (db *DB) InsertHeaderStm() string {
4141
return `INSERT INTO eth.header_cids (block_number, block_hash, parent_hash, cid, td, node_id, reward, state_root, tx_root, receipt_root, uncle_root, bloom, timestamp, mh_key, times_validated, coinbase)
4242
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16)
43-
ON CONFLICT (block_hash, block_number) DO UPDATE SET (parent_hash, cid, td, node_id, reward, state_root, tx_root, receipt_root, uncle_root, bloom, timestamp, mh_key, times_validated, coinbase) = ($3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, eth.header_cids.times_validated + 1, $16)`
43+
ON CONFLICT (block_hash, block_number) DO UPDATE SET (parent_hash, cid, td, node_id, reward, state_root, tx_root, receipt_root, uncle_root, bloom, timestamp, mh_key, times_validated, coinbase) = ($3, $4, $5, array_cat(eth.header_cids.node_id, $6), $7, $8, $9, $10, $11, $12, $13, $14, eth.header_cids.times_validated + 1, $16)`
4444
}
4545

4646
// InsertUncleStm satisfies the sql.Statements interface

statediff/indexer/database/sql/writer.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121

2222
"github.com/ethereum/go-ethereum/common"
2323
"github.com/ethereum/go-ethereum/statediff/indexer/models"
24+
"github.com/lib/pq"
2425
)
2526

2627
var (
@@ -47,11 +48,12 @@ func (w *Writer) Close() error {
4748
/*
4849
INSERT INTO eth.header_cids (block_number, block_hash, parent_hash, cid, td, node_id, reward, state_root, tx_root, receipt_root, uncle_root, bloom, timestamp, mh_key, times_validated, coinbase)
4950
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16)
50-
ON CONFLICT (block_hash, block_number) DO UPDATE SET (block_number, parent_hash, cid, td, node_id, reward, state_root, tx_root, receipt_root, uncle_root, bloom, timestamp, mh_key, times_validated, coinbase) = ($1, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, eth.header_cids.times_validated + 1, $16)
51+
ON CONFLICT (block_hash, block_number) DO UPDATE SET (block_number, parent_hash, cid, td, node_id, reward, state_root, tx_root, receipt_root, uncle_root, bloom, timestamp, mh_key, times_validated, coinbase) = ($1, $3, $4, $5, array_cat(eth.header_cids.node_id, $6), $7, $8, $9, $10, $11, $12, $13, $14, eth.header_cids.times_validated + 1, $16)
5152
*/
5253
func (w *Writer) upsertHeaderCID(tx Tx, header models.HeaderModel) error {
54+
nodeIds := []string{w.db.NodeID()}
5355
_, err := tx.Exec(w.db.Context(), w.db.InsertHeaderStm(),
54-
header.BlockNumber, header.BlockHash, header.ParentHash, header.CID, header.TotalDifficulty, w.db.NodeID(),
56+
header.BlockNumber, header.BlockHash, header.ParentHash, header.CID, header.TotalDifficulty, pq.Array(nodeIds),
5557
header.Reward, header.StateRoot, header.TxRoot, header.RctRoot, header.UncleRoot, header.Bloom,
5658
header.Timestamp, header.MhKey, 1, header.Coinbase)
5759
if err != nil {

0 commit comments

Comments
 (0)