2022-04-27 18:01:59 +00:00
|
|
|
// This file contains all the functions to handle SSE events after they have been turned
|
|
|
|
// to the structs.
|
|
|
|
|
2022-04-27 14:28:42 +00:00
|
|
|
package beaconclient
|
|
|
|
|
2022-04-29 22:26:52 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
log "github.com/sirupsen/logrus"
|
2022-05-04 21:25:36 +00:00
|
|
|
"github.com/vulcanize/ipld-ethcl-indexer/pkg/database/sql"
|
2022-05-04 13:34:23 +00:00
|
|
|
"github.com/vulcanize/ipld-ethcl-indexer/pkg/loghelper"
|
2022-04-29 22:26:52 +00:00
|
|
|
)
|
2022-04-27 14:28:42 +00:00
|
|
|
|
|
|
|
// This function will perform the necessary steps to handle a reorg.
|
|
|
|
func (bc *BeaconClient) handleReorgs() {
|
|
|
|
log.Info("Starting to process reorgs.")
|
|
|
|
for {
|
|
|
|
// We will add real functionality later
|
|
|
|
reorg := <-bc.ReOrgTracking.ProcessCh
|
|
|
|
log.WithFields(log.Fields{"reorg": reorg}).Debug("Received a new reorg message.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-04 21:25:36 +00:00
|
|
|
// // This function will perform the necessary steps to handle a reorg.
|
|
|
|
// func (bc *BeaconClient) handleFinalizedCheckpoint() {
|
|
|
|
// log.Info("Starting to process finalized checkpoints.")
|
|
|
|
// for {
|
|
|
|
// // We will add real functionality later
|
|
|
|
// finalized := <-bc.FinalizationTracking.ProcessCh
|
|
|
|
// log.WithFields(log.Fields{"finalized": finalized}).Debug("Received a new finalized checkpoint.")
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// }
|
2022-04-27 14:28:42 +00:00
|
|
|
|
|
|
|
// This function will handle the latest head event.
|
2022-05-04 21:25:36 +00:00
|
|
|
func (bc *BeaconClient) handleHead(db sql.Database) {
|
2022-04-27 14:28:42 +00:00
|
|
|
log.Info("Starting to process head.")
|
|
|
|
for {
|
2022-04-29 22:26:52 +00:00
|
|
|
head := <-bc.HeadTracking.ProcessCh
|
|
|
|
// Process all the work here.
|
2022-05-04 13:34:23 +00:00
|
|
|
slot, err := strconv.Atoi(head.Slot)
|
|
|
|
if err != nil {
|
|
|
|
bc.HeadTracking.ErrorCh <- &SseError{
|
|
|
|
err: fmt.Errorf("Unable to turn the slot from string to int: %s", head.Slot),
|
2022-04-29 22:26:52 +00:00
|
|
|
}
|
2022-05-04 13:34:23 +00:00
|
|
|
}
|
2022-05-04 21:25:36 +00:00
|
|
|
err = handleHeadSlot(db, bc.ServerEndpoint, slot, head.Block, head.State, uint64(bc.PreviousSlot), bc.PreviousBlockRoot)
|
2022-05-04 13:34:23 +00:00
|
|
|
if err != nil {
|
|
|
|
loghelper.LogSlotError(head.Slot, err)
|
2022-04-29 22:26:52 +00:00
|
|
|
}
|
2022-04-27 14:28:42 +00:00
|
|
|
log.WithFields(log.Fields{"head": head}).Debug("Received a new head event.")
|
2022-05-04 13:34:23 +00:00
|
|
|
|
|
|
|
// Update the previous block
|
|
|
|
bc.PreviousSlot = slot
|
|
|
|
bc.PreviousBlockRoot = head.Block
|
2022-04-27 14:28:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|