diff --git a/Makefile b/Makefile index 531789223d..86cff77c0c 100644 --- a/Makefile +++ b/Makefile @@ -66,7 +66,7 @@ BUILD_FLAGS := -tags "$(build_tags)" -ldflags '$(ldflags)' all: lint install install: go.sum - go install $(BUILD_FLAGS) ./cmd/seid + go install -race $(BUILD_FLAGS) ./cmd/seid # In case when running seid fails with nitro issue or if you make changes to nitro, please use install-all install-all: build-nitro install diff --git a/app/abci.go b/app/abci.go index 5e80ddafcc..4505683bc9 100644 --- a/app/abci.go +++ b/app/abci.go @@ -11,40 +11,40 @@ import ( ) func (app *App) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) (res abci.ResponseBeginBlock) { - tracectx, topSpan := (*app.tracingInfo.Tracer).Start(context.Background(), "Block") + tracectx, topSpan := app.tracingInfo.Start("Block") topSpan.SetAttributes(attribute.Int64("height", req.Header.Height)) app.tracingInfo.BlockSpan = &topSpan - app.tracingInfo.TracerContext = tracectx - _, beginBlockSpan := (*app.tracingInfo.Tracer).Start(app.tracingInfo.TracerContext, "BeginBlock") + app.tracingInfo.SetContext(tracectx) + _, beginBlockSpan := (*app.tracingInfo.Tracer).Start(app.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.tracingInfo.Tracer).Start(app.tracingInfo.TracerContext, "MidBlock") + _, span := app.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.tracingInfo.Tracer).Start(app.tracingInfo.TracerContext, "EndBlock") + _, span := app.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.tracingInfo.Tracer).Start(app.tracingInfo.TracerContext, "CheckTx") + _, span := app.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()) - tracectx, span := (*app.tracingInfo.Tracer).Start(app.tracingInfo.TracerContext, "DeliverTx") - oldCtx := app.tracingInfo.TracerContext - app.tracingInfo.TracerContext = tracectx + tracectx, span := app.tracingInfo.Start("DeliverTx") + oldCtx := app.tracingInfo.GetContext() + app.tracingInfo.SetContext(tracectx) defer span.End() - defer func() { app.tracingInfo.TracerContext = oldCtx }() + defer func() { app.tracingInfo.SetContext(oldCtx) }() return app.BaseApp.DeliverTx(ctx, req) } @@ -52,9 +52,9 @@ func (app *App) Commit(ctx context.Context) (res *abci.ResponseCommit, err error if app.tracingInfo.BlockSpan != nil { defer (*app.tracingInfo.BlockSpan).End() } - _, span := (*app.tracingInfo.Tracer).Start(app.tracingInfo.TracerContext, "Commit") + _, span := app.tracingInfo.Start("Commit") defer span.End() - app.tracingInfo.TracerContext = context.Background() + app.tracingInfo.SetContext(context.Background()) app.tracingInfo.BlockSpan = nil return app.BaseApp.Commit(ctx) } diff --git a/app/ante_test.go b/app/ante_test.go index 3dfd4e6fc3..95b53be4a2 100644 --- a/app/ante_test.go +++ b/app/ante_test.go @@ -70,6 +70,10 @@ func (suite *AnteTestSuite) SetupTest(isCheckTx bool) { otel.SetTracerProvider(defaultTracer) tr := defaultTracer.Tracer("component-main") + tracingInfo := &tracing.Info{ + Tracer: &tr, + } + tracingInfo.SetContext(context.Background()) antehandler, anteDepGenerator, err := app.NewAnteHandlerAndDepGenerator( app.HandlerOptions{ HandlerOptions: ante.HandlerOptions{ @@ -87,10 +91,7 @@ func (suite *AnteTestSuite) SetupTest(isCheckTx bool) { DexKeeper: &suite.App.DexKeeper, NitroKeeper: &suite.App.NitroKeeper, AccessControlKeeper: &suite.App.AccessControlKeeper, - TracingInfo: &tracing.Info{ - Tracer: &tr, - TracerContext: context.Background(), - }, + TracingInfo: tracingInfo, }, ) diff --git a/app/antedecorators/traced.go b/app/antedecorators/traced.go index c79b9c0e1a..732f125801 100644 --- a/app/antedecorators/traced.go +++ b/app/antedecorators/traced.go @@ -20,7 +20,7 @@ func NewTracedAnteDecorator(wrapped sdk.AnteDecorator, tracingInfo *tracing.Info func (d TracedAnteDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { if d.tracingInfo != nil { - _, span := (*d.tracingInfo.Tracer).Start(d.tracingInfo.TracerContext, d.traceName) + _, span := d.tracingInfo.Start(d.traceName) defer span.End() } return d.wrapped.AnteHandle(ctx, tx, simulate, next) diff --git a/app/app.go b/app/app.go index c91b609789..9712509ded 100644 --- a/app/app.go +++ b/app/app.go @@ -398,12 +398,12 @@ func New( tkeys: tkeys, memKeys: memKeys, tracingInfo: &tracing.Info{ - Tracer: &tr, - TracerContext: context.Background(), + Tracer: &tr, }, txDecoder: encodingConfig.TxConfig.TxDecoder(), versionInfo: version.NewInfo(), } + app.tracingInfo.SetContext(context.Background()) app.ParamsKeeper = initParamsKeeper(appCodec, cdc, keys[paramstypes.StoreKey], tkeys[paramstypes.TStoreKey]) diff --git a/cmd/seid/cmd/root.go b/cmd/seid/cmd/root.go index 3bcf664386..5034ef474c 100644 --- a/cmd/seid/cmd/root.go +++ b/cmd/seid/cmd/root.go @@ -6,6 +6,8 @@ import ( "io" "math" "math/rand" + "net/http" + _ "net/http/pprof" "os" "path/filepath" "time" @@ -61,6 +63,9 @@ func (s *rootOptions) apply(options ...Option) { //nolint:unused // I figure thi // NewRootCmd creates a new root command for a Cosmos SDK application func NewRootCmd() (*cobra.Command, params.EncodingConfig) { + go func() { + http.ListenAndServe(":6060", nil) + }() encodingConfig := app.MakeEncodingConfig() initClientCtx := client.Context{}. WithCodec(encodingConfig.Marshaler). diff --git a/go.mod b/go.mod index 6875621cdb..08936c5955 100644 --- a/go.mod +++ b/go.mod @@ -36,6 +36,7 @@ require ( go.opentelemetry.io/otel/trace v1.9.0 golang.org/x/exp v0.0.0-20221031165847-c99f073a8326 golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 + golang.org/x/text v0.7.0 google.golang.org/genproto v0.0.0-20230223222841-637eb2293923 google.golang.org/grpc v1.53.0 google.golang.org/protobuf v1.28.1 @@ -255,7 +256,6 @@ require ( golang.org/x/net v0.7.0 // indirect golang.org/x/sys v0.5.0 // indirect golang.org/x/term v0.5.0 // indirect - golang.org/x/text v0.7.0 // indirect golang.org/x/tools v0.2.0 // indirect gopkg.in/ini.v1 v1.66.6 // indirect honnef.co/go/tools v0.3.1 // indirect @@ -269,8 +269,8 @@ require ( replace ( github.com/CosmWasm/wasmd => github.com/sei-protocol/sei-wasmd v0.0.1 github.com/confio/ics23/go => github.com/cosmos/cosmos-sdk/ics23/go v0.8.0 - github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.2.1 - github.com/cosmos/iavl => github.com/sei-protocol/sei-iavl v0.1.2 + github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.2.1-tony-2 + github.com/cosmos/iavl => github.com/sei-protocol/sei-iavl v0.1.2-tony-3 github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 github.com/keybase/go-keychain => github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 github.com/tendermint/tendermint => github.com/sei-protocol/sei-tendermint v0.1.177 diff --git a/go.sum b/go.sum index b9c7b12dd9..349b6f3469 100644 --- a/go.sum +++ b/go.sum @@ -1066,10 +1066,10 @@ github.com/seccomp/libseccomp-golang v0.9.2-0.20210429002308-3879420cc921/go.mod github.com/securego/gosec/v2 v2.11.0 h1:+PDkpzR41OI2jrw1q6AdXZCbsNGNGT7pQjal0H0cArI= github.com/securego/gosec/v2 v2.11.0/go.mod h1:SX8bptShuG8reGC0XS09+a4H2BoWSJi+fscA+Pulbpo= github.com/segmentio/fasthash v1.0.3/go.mod h1:waKX8l2N8yckOgmSsXJi7x1ZfdKZ4x7KRMzBtS3oedY= -github.com/sei-protocol/sei-cosmos v0.2.1 h1:u1yUGasR7iDMVb2VMDmsCWx6duQQwvuq6iTwHrRc7dc= -github.com/sei-protocol/sei-cosmos v0.2.1/go.mod h1:LUhhplOtRXliV1x17gbOptKPy90xSK0Sxv8zmgsMvTY= -github.com/sei-protocol/sei-iavl v0.1.2 h1:jEYkZv83DbTRapJtkT5gBFa2uEBwD4udw8AiYx0gcsI= -github.com/sei-protocol/sei-iavl v0.1.2/go.mod h1:7PfkEVT5dcoQE+s/9KWdoXJ8VVVP1QpYYPLdxlkSXFk= +github.com/sei-protocol/sei-cosmos v0.2.1-tony-2 h1:RFs3RZ0VVV9IFTsK/0WX9E/p8axapU51+rtYinU08Lc= +github.com/sei-protocol/sei-cosmos v0.2.1-tony-2/go.mod h1:LUhhplOtRXliV1x17gbOptKPy90xSK0Sxv8zmgsMvTY= +github.com/sei-protocol/sei-iavl v0.1.2-tony-3 h1:udXCIcgpbJjX09c3udk8IlAyTRQyFWhZjw5SAgcuqaI= +github.com/sei-protocol/sei-iavl v0.1.2-tony-3/go.mod h1:7PfkEVT5dcoQE+s/9KWdoXJ8VVVP1QpYYPLdxlkSXFk= github.com/sei-protocol/sei-tendermint v0.1.177 h1:gn6/z82eGBBdyRgEyd8wpbB0C3/l1BhjzcsiCFoSrvo= github.com/sei-protocol/sei-tendermint v0.1.177/go.mod h1:+BtDvAwTkE64BlxzpH9ZP7S6vUYT9wRXiZa/WW8/o4g= github.com/sei-protocol/sei-tm-db v0.0.5 h1:3WONKdSXEqdZZeLuWYfK5hP37TJpfaUa13vAyAlvaQY= diff --git a/utils/tracing/tracer.go b/utils/tracing/tracer.go index ec5424cb4d..3afaa1c196 100644 --- a/utils/tracing/tracer.go +++ b/utils/tracing/tracer.go @@ -2,6 +2,7 @@ package tracing import ( "context" + "sync" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/exporters/jaeger" @@ -46,6 +47,29 @@ func GetTracerProviderOptions(url string) ([]trace.TracerProviderOption, error) type Info struct { Tracer *otrace.Tracer - TracerContext context.Context + tracerContext context.Context BlockSpan *otrace.Span + + mtx sync.RWMutex +} + +func (i *Info) Start(name string) (context.Context, otrace.Span) { + i.mtx.Lock() + defer i.mtx.Unlock() + if i.tracerContext == nil { + i.tracerContext = context.Background() + } + return (*i.Tracer).Start(i.tracerContext, "DeliverTx") +} + +func (i *Info) GetContext() context.Context { + i.mtx.RLock() + defer i.mtx.RUnlock() + return i.tracerContext +} + +func (i *Info) SetContext(c context.Context) { + i.mtx.Lock() + defer i.mtx.Unlock() + i.tracerContext = c } diff --git a/x/dex/contract/abci.go b/x/dex/contract/abci.go index 6d9527f813..c71d4bd89b 100644 --- a/x/dex/contract/abci.go +++ b/x/dex/contract/abci.go @@ -43,7 +43,7 @@ type environment struct { func EndBlockerAtomic(ctx sdk.Context, keeper *keeper.Keeper, validContractsInfo []types.ContractInfoV2, tracingInfo *tracing.Info) ([]types.ContractInfoV2, sdk.Context, bool) { tracer := tracingInfo.Tracer - spanCtx, span := (*tracer).Start(tracingInfo.TracerContext, "DexEndBlockerAtomic") + spanCtx, span := tracingInfo.Start("DexEndBlockerAtomic") defer span.End() env := newEnv(ctx, validContractsInfo, keeper) cachedCtx, msCached := cacheContext(ctx, env) diff --git a/x/dex/module.go b/x/dex/module.go index 144eab383f..bdd7da819f 100644 --- a/x/dex/module.go +++ b/x/dex/module.go @@ -226,7 +226,7 @@ func (am AppModule) getAllContractInfo(ctx sdk.Context) []types.ContractInfoV2 { // BeginBlock executes all ABCI BeginBlock logic respective to the capability module. func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) { defer func() { - _, span := (*am.tracingInfo.Tracer).Start(am.tracingInfo.TracerContext, "DexBeginBlockRollback") + _, span := am.tracingInfo.Start("DexBeginBlockRollback") defer span.End() }() @@ -245,7 +245,7 @@ func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) { } func (am AppModule) beginBlockForContract(ctx sdk.Context, contract types.ContractInfoV2, epoch int64, gasLimit uint64) { - _, span := (*am.tracingInfo.Tracer).Start(am.tracingInfo.TracerContext, "DexBeginBlock") + _, span := am.tracingInfo.Start("DexBeginBlock") contractAddr := contract.ContractAddr span.SetAttributes(attribute.String("contract", contractAddr)) defer span.End() @@ -271,7 +271,7 @@ func (am AppModule) beginBlockForContract(ctx sdk.Context, contract types.Contra // EndBlock executes all ABCI EndBlock logic respective to the capability module. It // returns no validator updates. func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) (ret []abci.ValidatorUpdate) { - _, span := (*am.tracingInfo.Tracer).Start(am.tracingInfo.TracerContext, "DexEndBlock") + _, span := am.tracingInfo.Start("DexEndBlock") defer span.End() defer dexutils.GetMemState(ctx.Context()).Clear(ctx)