/
abci.go
70 lines (61 loc) · 2.51 KB
/
abci.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package app
import (
"context"
"time"
"github.com/Timwood0x10/sei-chain/utils/metrics"
sdk "github.com/cosmos/cosmos-sdk/types"
abci "github.com/tendermint/tendermint/abci/types"
"go.opentelemetry.io/otel/attribute"
)
func (app *App) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) (res abci.ResponseBeginBlock) {
tracectx, topSpan := app.GetBaseApp().TracingInfo.Start("Block")
topSpan.SetAttributes(attribute.Int64("height", req.Header.Height))
app.GetBaseApp().TracingInfo.BlockSpan = &topSpan
app.GetBaseApp().TracingInfo.SetContext(tracectx)
_, beginBlockSpan := (*app.GetBaseApp().TracingInfo.Tracer).Start(app.GetBaseApp().TracingInfo.GetContext(), "BeginBlock")
defer beginBlockSpan.End()
return app.BaseApp.BeginBlock(ctx, req)
}
func (app *App) MidBlock(ctx sdk.Context, height int64) []abci.Event {
_, span := app.GetBaseApp().TracingInfo.Start("MidBlock")
defer span.End()
return app.BaseApp.MidBlock(ctx, height)
}
func (app *App) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) (res abci.ResponseEndBlock) {
_, span := app.GetBaseApp().TracingInfo.Start("EndBlock")
defer span.End()
return app.BaseApp.EndBlock(ctx, req)
}
func (app *App) CheckTx(ctx context.Context, req *abci.RequestCheckTx) (*abci.ResponseCheckTx, error) {
_, span := app.GetBaseApp().TracingInfo.Start("CheckTx")
defer span.End()
return app.BaseApp.CheckTx(ctx, req)
}
func (app *App) DeliverTx(ctx sdk.Context, req abci.RequestDeliverTx) abci.ResponseDeliverTx {
defer metrics.MeasureDeliverTxDuration(time.Now())
// ensure we carry the initial context from tracer here
ctx = ctx.WithTraceSpanContext(app.GetBaseApp().TracingInfo.GetContext())
spanCtx, span := app.GetBaseApp().TracingInfo.StartWithContext("DeliverTx", ctx.TraceSpanContext())
defer span.End()
// update context with trace span new context
ctx = ctx.WithTraceSpanContext(spanCtx)
return app.BaseApp.DeliverTx(ctx, req)
}
func (app *App) Commit(ctx context.Context) (res *abci.ResponseCommit, err error) {
if app.GetBaseApp().TracingInfo.BlockSpan != nil {
defer (*app.GetBaseApp().TracingInfo.BlockSpan).End()
}
_, span := app.GetBaseApp().TracingInfo.Start("Commit")
defer span.End()
app.GetBaseApp().TracingInfo.SetContext(context.Background())
app.GetBaseApp().TracingInfo.BlockSpan = nil
return app.BaseApp.Commit(ctx)
}
func (app *App) LoadLatest(ctx context.Context, req *abci.RequestLoadLatest) (*abci.ResponseLoadLatest, error) {
err := app.ReloadDB()
if err != nil {
return nil, err
}
app.mounter()
return app.BaseApp.LoadLatest(ctx, req)
}