Statediff missing parent blocks automatically (#8)
Port of https://github.com/cerc-io/go-ethereum/pull/399 and https://github.com/cerc-io/go-ethereum/pull/397. Co-authored-by: Thomas E Lackey <telackey@bozemanpass.com> Reviewed-on: #8
This commit was merged in pull request #8.
This commit is contained in:
@@ -257,6 +257,7 @@ func (sdi *StateDiffIndexer) processHeader(tx *BatchTx, header *types.Header, he
|
||||
UnclesHash: header.UncleHash.String(),
|
||||
Timestamp: header.Time,
|
||||
Coinbase: header.Coinbase.String(),
|
||||
Canonical: true,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ type Statements interface {
|
||||
MaxHeaderStm() string
|
||||
ExistsHeaderStm() string
|
||||
InsertHeaderStm() string
|
||||
SetCanonicalHeaderStm() string
|
||||
InsertUncleStm() string
|
||||
InsertTxStm() string
|
||||
InsertRctStm() string
|
||||
|
||||
@@ -62,6 +62,12 @@ func (db *DB) InsertHeaderStm() string {
|
||||
return schema.TableHeader.ToInsertStatement(db.upsert)
|
||||
}
|
||||
|
||||
// SetCanonicalHeaderStm satisfies the sql.Statements interface
|
||||
// Stm == Statement
|
||||
func (db *DB) SetCanonicalHeaderStm() string {
|
||||
return fmt.Sprintf("UPDATE %s SET canonical = false WHERE block_number = $1::BIGINT AND block_hash <> $2::TEXT AND canonical = true", schema.TableHeader.Name)
|
||||
}
|
||||
|
||||
// InsertUncleStm satisfies the sql.Statements interface
|
||||
func (db *DB) InsertUncleStm() string {
|
||||
return schema.TableUncle.ToInsertStatement(db.upsert)
|
||||
|
||||
@@ -90,6 +90,7 @@ func (w *Writer) maxHeader() (*models.HeaderModel, error) {
|
||||
&model.Bloom,
|
||||
&model.Timestamp,
|
||||
&model.Coinbase,
|
||||
&model.Canonical,
|
||||
)
|
||||
model.BlockNumber = strconv.FormatUint(number, 10)
|
||||
model.TotalDifficulty = strconv.FormatUint(td, 10)
|
||||
@@ -118,11 +119,22 @@ func (w *Writer) upsertHeaderCID(tx Tx, header models.HeaderModel) error {
|
||||
header.UnclesHash,
|
||||
header.Bloom,
|
||||
header.Timestamp,
|
||||
header.Coinbase)
|
||||
header.Coinbase,
|
||||
header.Canonical,
|
||||
)
|
||||
if err != nil {
|
||||
return insertError{"eth.header_cids", err, w.db.InsertHeaderStm(), header}
|
||||
}
|
||||
metrics.IndexerMetrics.BlocksCounter.Inc(1)
|
||||
|
||||
_, err = tx.Exec(w.db.Context(), w.db.SetCanonicalHeaderStm(),
|
||||
header.BlockNumber,
|
||||
header.BlockHash,
|
||||
)
|
||||
if err != nil {
|
||||
return insertError{"eth.header_cids", err, w.db.SetCanonicalHeaderStm(), header}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user