(VDB-68) Verify log block hash matches header block hash

- Delete header on conflict to prompt data refresh (cascade deletes all
  data associated with that block)
- Derive header hash from rpc payload rather than computing it from data
  (prevents hash mismatch between blockchain and cache)
This commit is contained in:
Rob Mulholand
2018-11-13 14:51:39 -06:00
parent 9d26c174d4
commit 82fd73ba3f
95 changed files with 557 additions and 298 deletions
+10 -3
View File
@@ -31,7 +31,7 @@ func (repository *VatHealRepository) SetDB(db *postgres.DB) {
repository.db = db
}
func (repository VatHealRepository) Create(headerId int64, models []interface{}) error {
func (repository VatHealRepository) Create(headerID int64, models []interface{}) error {
tx, err := repository.db.Begin()
if err != nil {
return err
@@ -43,16 +43,23 @@ func (repository VatHealRepository) Create(headerId int64, models []interface{})
tx.Rollback()
return fmt.Errorf("model of type %T, not %T", model, VatHealModel{})
}
err = shared.ValidateHeaderConsistency(headerID, vatHeal.Raw, repository.db)
if err != nil {
tx.Rollback()
return err
}
_, err := tx.Exec(`INSERT INTO maker.vat_heal (header_id, urn, v, rad, log_idx, tx_idx, raw_log)
VALUES($1, $2, $3, $4::NUMERIC, $5, $6, $7)`,
headerId, vatHeal.Urn, vatHeal.V, vatHeal.Rad, vatHeal.LogIndex, vatHeal.TransactionIndex, vatHeal.Raw)
headerID, vatHeal.Urn, vatHeal.V, vatHeal.Rad, vatHeal.LogIndex, vatHeal.TransactionIndex, vatHeal.Raw)
if err != nil {
tx.Rollback()
return err
}
}
err = shared.MarkHeaderCheckedInTransaction(headerId, tx, constants.VatHealChecked)
err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatHealChecked)
if err != nil {
tx.Rollback()
return err