Test the application for v1 release. #37

Merged
abdulrabbani00 merged 9 commits from feature/32-test-known_gaps-skipped-slots into develop 2022-05-17 20:05:16 +00:00
4 changed files with 66 additions and 39 deletions
Showing only changes of commit 67f1427c8b - Show all commits

View File

@ -322,31 +322,32 @@ func writeKnownGaps(db sql.Database, tableIncrement int, startSlot int, endSlot
EntryProcess: entryProcess, EntryProcess: entryProcess,
} }
upsertKnownGaps(db, kgModel) upsertKnownGaps(db, kgModel)
} } else {
totalSlots := endSlot - startSlot totalSlots := endSlot - startSlot
var chunks int var chunks int
chunks = totalSlots / tableIncrement chunks = totalSlots / tableIncrement
if totalSlots%tableIncrement != 0 { if totalSlots%tableIncrement != 0 {
chunks = chunks + 1 chunks = chunks + 1
} }
for i := 0; i < chunks; i++ { for i := 0; i < chunks; i++ {
var tempStart, tempEnd int var tempStart, tempEnd int
tempStart = startSlot + (i * tableIncrement) tempStart = startSlot + (i * tableIncrement)
if i+1 == chunks { if i+1 == chunks {
tempEnd = endSlot tempEnd = endSlot
} else { } else {
tempEnd = startSlot + ((i + 1) * tableIncrement) tempEnd = startSlot + ((i + 1) * tableIncrement)
}
kgModel := DbKnownGaps{
StartSlot: strconv.Itoa(tempStart),
EndSlot: strconv.Itoa(tempEnd),
CheckedOut: false,
ReprocessingError: "",
EntryError: entryError.Error(),
EntryProcess: entryProcess,
}
upsertKnownGaps(db, kgModel)
} }
kgModel := DbKnownGaps{
StartSlot: strconv.Itoa(tempStart),
EndSlot: strconv.Itoa(tempEnd),
CheckedOut: false,
ReprocessingError: "",
EntryError: entryError.Error(),
EntryProcess: entryProcess,
}
upsertKnownGaps(db, kgModel)
} }
} }

View File

@ -44,6 +44,7 @@ func handleIncomingSseEvent[P ProcessedEvents](eventHandler *SseEvents[P]) {
case message := <-eventHandler.MessagesCh: case message := <-eventHandler.MessagesCh:
// Message can be nil if its a keep-alive message // Message can be nil if its a keep-alive message
if len(message.Data) != 0 { if len(message.Data) != 0 {
log.WithFields(log.Fields{"msg": string(message.Data)}).Debug("We are going to send the following message to be processed.")
go processMsg(message.Data, eventHandler.ProcessCh, eventHandler.ErrorCh) go processMsg(message.Data, eventHandler.ProcessCh, eventHandler.ErrorCh)
} }
@ -54,9 +55,6 @@ func handleIncomingSseEvent[P ProcessedEvents](eventHandler *SseEvents[P]) {
"msg": headErr.msg, "msg": headErr.msg,
}, },
).Error("Unable to handle event.") ).Error("Unable to handle event.")
case process := <-eventHandler.ProcessCh:
log.WithFields(log.Fields{"processed": process}).Debug("Processesing a Message")
} }
} }
} }

View File

@ -8,7 +8,9 @@ import (
"strconv" "strconv"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"github.com/vulcanize/ipld-ethcl-indexer/pkg/database/sql"
"github.com/vulcanize/ipld-ethcl-indexer/pkg/loghelper" "github.com/vulcanize/ipld-ethcl-indexer/pkg/loghelper"
"golang.org/x/sync/errgroup"
) )
// This function will perform the necessary steps to handle a reorg. // This function will perform the necessary steps to handle a reorg.
@ -44,11 +46,23 @@ func (bc *BeaconClient) handleHead() {
writeKnownGaps(bc.Db, bc.KnownGapTableIncrement, bc.PreviousSlot, bcSlotsPerEpoch+errorSlots, fmt.Errorf("Bad Head Messages"), "headProcessing") writeKnownGaps(bc.Db, bc.KnownGapTableIncrement, bc.PreviousSlot, bcSlotsPerEpoch+errorSlots, fmt.Errorf("Bad Head Messages"), "headProcessing")
} }
err = processHeadSlot(bc.Db, bc.ServerEndpoint, slot, head.Block, head.State, bc.PreviousSlot, bc.PreviousBlockRoot, bc.Metrics, bc.KnownGapTableIncrement) log.WithFields(log.Fields{"head": head}).Debug("We are going to start processing the slot.")
if err != nil {
loghelper.LogSlotError(head.Slot, err).Error("Unable to process a slot") go func(db sql.Database, serverAddress string, slot int, blockRoot string, stateRoot string, previousSlot int, previousBlockRoot string, metrics *BeaconClientMetrics, knownGapsTableIncrement int) {
} errG := new(errgroup.Group)
log.WithFields(log.Fields{"head": head}).Debug("Received a new head event.") errG.Go(func() error {
err = processHeadSlot(db, serverAddress, slot, blockRoot, stateRoot, previousSlot, previousBlockRoot, metrics, knownGapsTableIncrement)
if err != nil {
return err
}
return nil
})
if err := errG.Wait(); err != nil {
loghelper.LogSlotError(strconv.Itoa(slot), err).Error("Unable to process a slot")
}
}(bc.Db, bc.ServerEndpoint, slot, head.Block, head.State, bc.PreviousSlot, bc.PreviousBlockRoot, bc.Metrics, bc.KnownGapTableIncrement)
log.WithFields(log.Fields{"head": head.Slot}).Debug("We finished calling processHeadSlot.")
// Update the previous block // Update the previous block
bc.PreviousSlot = slot bc.PreviousSlot = slot

View File

@ -5,6 +5,7 @@
package beaconclient package beaconclient
import ( import (
"context"
"encoding/hex" "encoding/hex"
"fmt" "fmt"
"strconv" "strconv"
@ -17,6 +18,7 @@ import (
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"github.com/vulcanize/ipld-ethcl-indexer/pkg/database/sql" "github.com/vulcanize/ipld-ethcl-indexer/pkg/database/sql"
"github.com/vulcanize/ipld-ethcl-indexer/pkg/loghelper" "github.com/vulcanize/ipld-ethcl-indexer/pkg/loghelper"
"golang.org/x/sync/errgroup"
) )
var ( var (
@ -66,18 +68,28 @@ func processFullSlot(db sql.Database, serverAddress string, slot int, blockRoot
Metrics: metrics, Metrics: metrics,
} }
g, _ := errgroup.WithContext(context.Background())
// Get the BeaconState. // Get the BeaconState.
err := ps.getBeaconState(serverAddress) g.Go(func() error {
if err != nil { err := ps.getBeaconState(serverAddress)
writeKnownGaps(ps.Db, 1, ps.Slot, ps.Slot, err, "processSlot") if err != nil {
return err return err
} }
return nil
})
// Get the SignedBeaconBlock. // Get the SignedBeaconBlock.
err = ps.getSignedBeaconBlock(serverAddress) g.Go(func() error {
if err != nil { err := ps.getSignedBeaconBlock(serverAddress)
if err != nil {
return err
}
return nil
})
if err := g.Wait(); err != nil {
writeKnownGaps(ps.Db, 1, ps.Slot, ps.Slot, err, "processSlot") writeKnownGaps(ps.Db, 1, ps.Slot, ps.Slot, err, "processSlot")
return err
} }
if ps.HeadOrHistoric == "head" && previousSlot == 0 && previousBlockRoot == "" { if ps.HeadOrHistoric == "head" && previousSlot == 0 && previousBlockRoot == "" {
@ -151,6 +163,7 @@ func (ps *ProcessSlot) getSignedBeaconBlock(serverAddress string) error {
err = ps.FullSignedBeaconBlock.UnmarshalSSZ(ps.SszSignedBeaconBlock) err = ps.FullSignedBeaconBlock.UnmarshalSSZ(ps.SszSignedBeaconBlock)
if err != nil { if err != nil {
loghelper.LogError(err).Debug("We are getting an error message when unmarshalling the SignedBeaconBlock.")
if ps.FullSignedBeaconBlock.Block.Slot == 0 { if ps.FullSignedBeaconBlock.Block.Slot == 0 {
loghelper.LogSlotError(strconv.Itoa(ps.Slot), err).Error(SlotUnmarshalError("SignedBeaconBlock")) loghelper.LogSlotError(strconv.Itoa(ps.Slot), err).Error(SlotUnmarshalError("SignedBeaconBlock"))
return fmt.Errorf(SlotUnmarshalError("SignedBeaconBlock")) return fmt.Errorf(SlotUnmarshalError("SignedBeaconBlock"))
@ -185,6 +198,7 @@ func (ps *ProcessSlot) getBeaconState(serverEndpoint string) error {
err := ps.FullBeaconState.UnmarshalSSZ(ps.SszBeaconState) err := ps.FullBeaconState.UnmarshalSSZ(ps.SszBeaconState)
if err != nil { if err != nil {
loghelper.LogError(err).Debug("We are getting an error message when unmarshalling the BeaconState")
if ps.FullBeaconState.Slot == 0 { if ps.FullBeaconState.Slot == 0 {
loghelper.LogSlotError(strconv.Itoa(ps.Slot), err).Error(SlotUnmarshalError("BeaconState")) loghelper.LogSlotError(strconv.Itoa(ps.Slot), err).Error(SlotUnmarshalError("BeaconState"))
return fmt.Errorf(SlotUnmarshalError("BeaconState")) return fmt.Errorf(SlotUnmarshalError("BeaconState"))