4994f1fa94
* -- Intermediary Commit -- Just want to commit my code over the weekend, in case I spill coffee on my workstation. * Create DB models ready for write. * Handle SSE events * Update ref for stack-orchestrator * Use env in one place only. * Boot Application on PR * Update syntax * Update syntax * Correct command * Use bash instead of sh * Use until instead of while * Make linter happy and check sse subscription err * Handle Reorgs - Untested
32 lines
1021 B
Go
32 lines
1021 B
Go
package beaconclient
|
|
|
|
import (
|
|
log "github.com/sirupsen/logrus"
|
|
"github.com/vulcanize/ipld-ethcl-indexer/pkg/database/sql"
|
|
"github.com/vulcanize/ipld-ethcl-indexer/pkg/loghelper"
|
|
)
|
|
|
|
func processReorg(db sql.Database, slot string, latestBlockRoot string) {
|
|
// Check to see if there are slots in the DB with the given slot.
|
|
// Update them ALL to forked
|
|
// Upsert the new slot into the DB, mark the status to proposed.
|
|
// Query at the end to make sure that you have handled the reorg properly.
|
|
updatedRows, err := updateReorgs(db, slot, latestBlockRoot)
|
|
|
|
if err != nil {
|
|
// Add this slot to the knownGaps table..
|
|
// Maybe we need to rename the knownGaps table to the "batchProcess" table.
|
|
}
|
|
|
|
if updatedRows > 0 {
|
|
loghelper.LogReorg(slot, latestBlockRoot).WithFields(log.Fields{
|
|
"updatedRows": updatedRows,
|
|
}).Info("Updated DB based on Reorgs.")
|
|
} else {
|
|
loghelper.LogReorg(slot, latestBlockRoot).WithFields(log.Fields{
|
|
"updatedRows": updatedRows,
|
|
}).Warn("There were no rows to update.")
|
|
|
|
}
|
|
}
|