Skip to content

Commit

Permalink
nits
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-ogrady committed Jul 15, 2020
1 parent dc6c157 commit 1151e4a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 19 deletions.
53 changes: 35 additions & 18 deletions cmd/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ const (
// InactiveFailureLookbackWindow blocks (this process continues
// until the client halts the search or the block is found).
InactiveFailureLookbackWindow = 250

// PeriodicLoggingFrequency is the frequency that stats are printed
// to the terminal.
//
// TODO: make configurable
PeriodicLoggingFrequency = 10 * time.Second
)

var (
Expand Down Expand Up @@ -619,7 +625,7 @@ func runCheckCmd(cmd *cobra.Command, args []string) {
g.Go(func() error {
for ctx.Err() == nil {
logger.LogCounterStorage(ctx)
time.Sleep(10 * time.Second)
time.Sleep(PeriodicLoggingFrequency)
}

return nil
Expand Down Expand Up @@ -670,34 +676,45 @@ func runCheckCmd(cmd *cobra.Command, args []string) {
}
}()

err = g.Wait()
handleCheckResult(g, counterStorage, reconcilerHandler, sigListeners)
}

// handleCheckResult interprets the check exectution result
// and terminates with the correct exit status.
func handleCheckResult(
g *errgroup.Group,
counterStorage *storage.CounterStorage,
reconcilerHandler *processor.ReconcilerHandler,
sigListeners []context.CancelFunc,
) {
// Initialize new context because calling context
// will no longer be usable when after termination.
ctx := context.Background()

err := g.Wait()
if signalReceived {
color.Red("Check halted")
os.Exit(1)
return
}

if err == nil || err == context.Canceled { // err == context.Canceled when --end
newCtx := context.Background()
activeReconciliations, err := counterStorage.Get(newCtx, storage.ActiveReconciliationCounter)
if err != nil {
color.Green("Check succeeded")
os.Exit(0)
}
activeReconciliations, activeErr := counterStorage.Get(
ctx,
storage.ActiveReconciliationCounter,
)
inactiveReconciliations, inactiveErr := counterStorage.Get(
ctx,
storage.InactiveReconciliationCounter,
)

inactiveReconciliations, err := counterStorage.Get(newCtx, storage.InactiveReconciliationCounter)
if err != nil {
if activeErr != nil || inactiveErr != nil ||
new(big.Int).Add(activeReconciliations, inactiveReconciliations).Sign() != 0 {
color.Green("Check succeeded")
os.Exit(0)
}

if new(big.Int).Add(activeReconciliations, inactiveReconciliations).Sign() == 0 {
} else { // warn caller when check succeeded but no reconciliations performed (as issues may still exist)
color.Yellow("Check succeeded, however, no reconciliations were performed!")
} else {
color.Green("Check succeeded")
}
os.Exit(0)

}

color.Red("Check failed: %s", err.Error())
Expand All @@ -714,7 +731,7 @@ func runCheckCmd(cmd *cobra.Command, args []string) {

color.Red("Searching for block with missing operations...hold tight")
badBlock, err := findMissingOps(
context.Background(),
ctx,
&sigListeners,
reconcilerHandler.InactiveFailure,
reconcilerHandler.InactiveFailureBlock.Index-InactiveFailureLookbackWindow,
Expand Down
6 changes: 5 additions & 1 deletion internal/processor/syncer_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ func (h *SyncerHandler) BlockAdded(

// Update Counters
h.logger.CounterStorage.Update(ctx, storage.BlockCounter, big.NewInt(1))
h.logger.CounterStorage.Update(ctx, storage.TransactionCounter, big.NewInt(int64(len(block.Transactions))))
h.logger.CounterStorage.Update(
ctx,
storage.TransactionCounter,
big.NewInt(int64(len(block.Transactions))),
)
opCount := int64(0)
for _, txn := range block.Transactions {
opCount += int64(len(txn.Operations))
Expand Down

0 comments on commit 1151e4a

Please sign in to comment.