Exemplo n.º 1
0
// Ticker triggers the system to update itself with any new data available.
func (sys *System) Tick(ctx context.Context) {
	sys.Init(ctx)

	log.Debugln(ctx, "ticking txsub system")
	for _, hash := range sys.Pending.Pending(ctx) {
		r := sys.Results.ResultByHash(ctx, hash)

		if r.Err == nil {
			log.WithField(ctx, "hash", hash).Debug("finishing open submission")
			sys.Pending.Finish(ctx, r)
			continue
		}

		_, ok := r.Err.(*FailedTransactionError)

		if ok {
			log.WithField(ctx, "hash", hash).Debug("finishing open submission")
			sys.Pending.Finish(ctx, r)
			continue
		}

		if r.Err != ErrNoResults {
			log.WithStack(ctx, r.Err).Error(r.Err)
		}
	}

	stillOpen, err := sys.Pending.Clean(ctx, sys.SubmissionTimeout)
	if err != nil {
		log.WithStack(ctx, err).Error(err)
	}

	sys.Metrics.OpenSubmissionsGauge.Update(int64(stillOpen))
}
Exemplo n.º 2
0
// UpdateMetrics triggers a refresh of several metrics gauges, such as open
// db connections and ledger state
func (a *App) UpdateLedgerState() {
	var ls db.LedgerState
	q := db.LedgerStateQuery{a.HistoryQuery(), a.CoreQuery()}
	err := db.Get(context.Background(), q, &ls)

	if err != nil {
		log.WithStack(err).
			WithField("err", err.Error()).
			Error("failed to load ledger state")
		return
	}

	a.latestLedgerState = ls
}
Exemplo n.º 3
0
func renderErr(ctx context.Context, w http.ResponseWriter, err error) {
	origErr := err

	if err, ok := err.(*errors.Error); ok {
		origErr = err.Err
	}

	p, ok := errToProblemMap[origErr]

	if !ok {
		p = ServerError
	}

	log.WithStack(ctx, err).Error(err)
	render(ctx, w, p)
}
Exemplo n.º 4
0
func render(ctx context.Context, w http.ResponseWriter, p P) {

	Inflate(ctx, &p)

	w.Header().Set("Content-Type", "application/problem+json")
	js, err := json.MarshalIndent(p, "", "  ")

	if err != nil {
		err := errors.Wrap(err, 1)
		log.WithStack(ctx, err).Error(err)
		http.Error(w, "error rendering problem", http.StatusInternalServerError)
		return
	}

	w.WriteHeader(p.Status)
	w.Write(js)
}
Exemplo n.º 5
0
// UpdateLedgerState triggers a refresh of several metrics gauges, such as open
// db connections and ledger state
func (a *App) UpdateLedgerState() {
	var err error

	err = a.CoreQ().LatestLedger(&a.latestLedgerState.Core)
	if err != nil {
		goto Failed
	}

	err = a.HistoryQ().LatestLedger(&a.latestLedgerState.Horizon)
	if err != nil {
		goto Failed
	}

	return

Failed:
	log.WithStack(err).
		WithField("err", err.Error()).
		Error("failed to load ledger state")

}
Exemplo n.º 6
0
// UpdateMetrics triggers a refresh of several metrics gauges, such as open
// db connections and ledger state
func (a *App) UpdateMetrics(ctx context.Context) {

	a.goroutineGauge.Update(int64(runtime.NumGoroutine()))

	var ls db.LedgerState
	q := db.LedgerStateQuery{a.HistoryQuery(), a.CoreQuery()}
	err := db.Get(ctx, q, &ls)

	if err != nil {
		log.WithStack(ctx, err).
			WithField("err", err.Error()).
			Error("failed to load ledger state")
		return
	}

	a.horizonLedgerGauge.Update(int64(ls.HorizonSequence))
	a.stellarCoreLedgerGauge.Update(int64(ls.StellarCoreSequence))

	a.horizonConnGauge.Update(int64(a.historyDb.Stats().OpenConnections))
	a.stellarCoreConnGauge.Update(int64(a.coreDb.Stats().OpenConnections))
}