(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 -4
View File
@@ -26,7 +26,7 @@ type VatFluxRepository struct {
db *postgres.DB
}
func (repository VatFluxRepository) Create(headerId int64, models []interface{}) error {
func (repository VatFluxRepository) Create(headerID int64, models []interface{}) error {
tx, err := repository.db.Begin()
if err != nil {
return err
@@ -39,16 +39,22 @@ func (repository VatFluxRepository) Create(headerId int64, models []interface{})
return fmt.Errorf("model of type %T, not %T", model, VatFluxModel{})
}
_, err := tx.Exec(`INSERT INTO maker.vat_flux (header_id, ilk, dst, src, rad, tx_idx, log_idx, raw_log)
err = shared.ValidateHeaderConsistency(headerID, vatFlux.Raw, repository.db)
if err != nil {
tx.Rollback()
return err
}
_, err = tx.Exec(`INSERT INTO maker.vat_flux (header_id, ilk, dst, src, rad, tx_idx, log_idx, raw_log)
VALUES($1, $2, $3, $4, $5::NUMERIC, $6, $7, $8)`,
headerId, vatFlux.Ilk, vatFlux.Dst, vatFlux.Src, vatFlux.Rad, vatFlux.TransactionIndex, vatFlux.LogIndex, vatFlux.Raw)
headerID, vatFlux.Ilk, vatFlux.Dst, vatFlux.Src, vatFlux.Rad, vatFlux.TransactionIndex, vatFlux.LogIndex, vatFlux.Raw)
if err != nil {
tx.Rollback()
return err
}
}
err = shared.MarkHeaderCheckedInTransaction(headerId, tx, constants.VatFluxChecked)
err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatFluxChecked)
if err != nil {
tx.Rollback()
return err
+1 -1
View File
@@ -21,11 +21,11 @@ import (
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories"
"github.com/vulcanize/vulcanizedb/pkg/fakes"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/shared_behaviors"
"github.com/vulcanize/vulcanizedb/pkg/transformers/vat_flux"
"github.com/vulcanize/vulcanizedb/test_config"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
)
var _ = Describe("VatFlux Repository", func() {