Skip to content

Commit

Permalink
provenance v1.19.0-rc5 rev 7d6c507; mamoru-sniffer-go v0.13.5
Browse files Browse the repository at this point in the history
  • Loading branch information
gofmanaa committed Jul 17, 2024
1 parent aacfb5a commit 61bed8c
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 251 deletions.
32 changes: 9 additions & 23 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package app

import (
"encoding/json"
"github.com/provenance-io/provenance/mamoru_cosmos_sdk"
"io"
"io/fs"
"net/http"
Expand Down Expand Up @@ -186,8 +187,6 @@ import (
triggerkeeper "github.com/provenance-io/provenance/x/trigger/keeper"
triggermodule "github.com/provenance-io/provenance/x/trigger/module"
triggertypes "github.com/provenance-io/provenance/x/trigger/types"

"github.com/provenance-io/provenance/mamoru_cosmos_sdk"
)

var (
Expand Down Expand Up @@ -999,6 +998,14 @@ func New(
}

simappparams.AppEncodingConfig = app.GetEncodingConfig()

////////////////////////// MAMORU SNIFFER //////////////////////////
listener := mamoru_cosmos_sdk.NewStreamingService(logger, mamoru_cosmos_sdk.NewSniffer(logger))
streamingManager := storetypes.StreamingManager{ABCIListeners: []storetypes.ABCIListener{listener}, StopNodeOnErr: false}

bApp.SetStreamingManager(streamingManager)
////////////////////////// MAMORU SNIFFER //////////////////////////

return app
}

Expand Down Expand Up @@ -1084,27 +1091,6 @@ func (app *App) registerUpgradeHandlers(appOpts servertypes.AppOptions) {
// Verify configuration settings
storeLoader = ValidateWrapper(app.Logger(), appOpts, storeLoader)
app.SetStoreLoader(storeLoader)

if loadLatest {
if err := app.LoadLatestVersion(); err != nil {
tmos.Exit(err.Error())
}
}

app.ScopedIBCKeeper = scopedIBCKeeper
app.ScopedTransferKeeper = scopedTransferKeeper
app.ScopedICQKeeper = scopedICQKeeper
app.ScopedICAHostKeeper = scopedICAHostKeeper

////////////////////////// MAMORU SNIFFER //////////////////////////
listener := mamoru_cosmos_sdk.NewStreamingService(logger, mamoru_cosmos_sdk.NewSniffer(logger))
streamingManager := storetypes.StreamingManager{AbciListeners: []storetypes.ABCIListener{listener}}

bApp.SetStreamingManager(streamingManager)
////////////////////////// MAMORU SNIFFER //////////////////////////


return app
}

// GetBaseApp returns the base cosmos app
Expand Down
6 changes: 5 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ require (
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gotest.tools/v3 v3.5.1 // indirect
nhooyr.io/websocket v1.8.10 // indirect
pgregory.net/rapid v1.1.0 // indirect
)
Expand Down Expand Up @@ -235,3 +234,8 @@ replace (
// replace broken goleveldb
github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
)

require (
github.com/Mamoru-Foundation/mamoru-sniffer-go v0.13.5
gotest.tools/v3 v3.5.1
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3
github.com/DataDog/zstd v1.5.5 h1:oWf5W7GtOLgp6bciQYDmhHHjdhYkALu6S/5Ni9ZgSvQ=
github.com/DataDog/zstd v1.5.5/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw=
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
github.com/Mamoru-Foundation/mamoru-sniffer-go v0.13.5 h1:OFKKdHP560a2qt6V/E292wr8WYtExmiVWPa7Bp3EnPM=
github.com/Mamoru-Foundation/mamoru-sniffer-go v0.13.5/go.mod h1:u2UBuNW7Wxz5sL533/hygPYIt25EDGmWzoUuZ9XqtGo=
github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow=
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 h1:TngWCqHvy9oXAN6lEVMRuU21PR1EtLVZJmdB18Gu3Rw=
Expand Down
52 changes: 0 additions & 52 deletions mamoru_cosmos_sdk/mock_streaming.go

This file was deleted.

25 changes: 6 additions & 19 deletions mamoru_cosmos_sdk/sniffer.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
package mamoru_cosmos_sdk

import (
"fmt"
"os"
"strconv"
"sync"

"github.com/go-kit/log/level"
"github.com/go-kit/log/term"
"github.com/tendermint/tendermint/libs/log"

"cosmossdk.io/log"
"github.com/Mamoru-Foundation/mamoru-sniffer-go/mamoru_sniffer"
"github.com/Mamoru-Foundation/mamoru-sniffer-go/mamoru_sniffer/cosmos"
"github.com/provenance-io/provenance/mamoru_cosmos_sdk/sync_state"
Expand All @@ -30,28 +26,19 @@ func init() {
mamoru_sniffer.InitLogger(func(entry mamoru_sniffer.LogEntry) {
kvs := mapToInterfaceSlice(entry.Ctx)
msg := "Mamoru core: " + entry.Message
var tmLogger = log.NewTMLoggerWithColorFn(os.Stdout, func(keyvals ...interface{}) term.FgBgColor {
if keyvals[0] != level.Key() {
panic(fmt.Sprintf("expected level key to be first, got %v", keyvals[0]))
}
switch keyvals[1].(level.Value).String() {
case "debug":
return term.FgBgColor{Fg: term.Green}
case "error":
return term.FgBgColor{Fg: term.DarkRed}
default:
return term.FgBgColor{}
}
})
var tmLogger = log.NewLogger(os.Stdout, log.TraceOption(true), log.ColorOption(false))

switch entry.Level {
case mamoru_sniffer.LogLevelDebug:

tmLogger.Debug(msg, kvs...)
case mamoru_sniffer.LogLevelInfo:

tmLogger.Info(msg, kvs...)
case mamoru_sniffer.LogLevelWarning:
tmLogger.With("Warn").Error(msg, kvs...)
tmLogger.Warn(msg, kvs...)
case mamoru_sniffer.LogLevelError:

tmLogger.Error(msg, kvs...)
}
})
Expand Down
32 changes: 12 additions & 20 deletions mamoru_cosmos_sdk/sniffer_test.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package mamoru_cosmos_sdk

import (
sdk "github.com/cosmos/cosmos-sdk/types"
tmprototypes "github.com/tendermint/tendermint/proto/tendermint/types"
"gotest.tools/v3/assert"
log2 "cosmossdk.io/log"
"os"
"testing"

abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log"
abci "github.com/cometbft/cometbft/abci/types"
tmprototypes "github.com/cometbft/cometbft/proto/tendermint/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"gotest.tools/v3/assert"
)

// TestNewSniffer tests the NewSniffer function
func TestNewSniffer(t *testing.T) {
snifferTest := NewSniffer(log.NewTMLogger(log.NewSyncWriter(os.Stdout)))
snifferTest := NewSniffer(log2.NewLogger(os.Stdout, log2.TraceOption(true), log2.ColorOption(false)))
if snifferTest == nil {
t.Error("NewSniffer returned nil")
}
Expand All @@ -24,7 +24,7 @@ func TestIsSnifferEnable(t *testing.T) {

// Set environment variable for testing
t.Setenv("MAMORU_SNIFFER_ENABLE", "true")
logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout))
logger := log2.NewLogger(os.Stdout, log2.TraceOption(true), log2.ColorOption(false))
_ = NewSniffer(logger)
if !isSnifferEnabled() {
t.Error("Expected sniffer to be enabled")
Expand All @@ -39,7 +39,7 @@ func TestIsSnifferEnable(t *testing.T) {

// smoke test for the sniffer
func TestSnifferSmoke(t *testing.T) {
t.Skip()

t.Setenv("MAMORU_SNIFFER_ENABLE", "true")
t.Setenv("MAMORU_CHAIN_TYPE", "ETH_TESTNET")
t.Setenv("MAMORU_CHAIN_ID", "validationchain")
Expand All @@ -49,7 +49,7 @@ func TestSnifferSmoke(t *testing.T) {
//InitConnectFunc(func() (*cosmos.SnifferCosmos, error) {
// return nil, nil
//})
logger := log.TestingLogger()
logger := log2.NewLogger(os.Stdout, log2.TraceOption(true), log2.ColorOption(false))
sniffer := NewSniffer(logger)
if sniffer == nil {
t.Error("NewSniffer returned nil")
Expand All @@ -59,17 +59,9 @@ func TestSnifferSmoke(t *testing.T) {
ctx := sdk.NewContext(nil, header, ischeck, logger)

streamingService := NewStreamingService(logger, sniffer)
regBB := abci.RequestBeginBlock{}
resBB := abci.ResponseBeginBlock{}
err := streamingService.ListenBeginBlock(ctx, regBB, resBB)
assert.NilError(t, err)
regDT := abci.RequestDeliverTx{}
resDT := abci.ResponseDeliverTx{}
err = streamingService.ListenDeliverTx(ctx, regDT, resDT)
assert.NilError(t, err)
regEB := abci.RequestEndBlock{}
resEB := abci.ResponseEndBlock{}
err = streamingService.ListenEndBlock(ctx, regEB, resEB)
regBB := abci.RequestFinalizeBlock{}
resBB := abci.ResponseFinalizeBlock{}
err := streamingService.ListenFinalizeBlock(ctx, regBB, resBB)
assert.NilError(t, err)

resC := abci.ResponseCommit{}
Expand Down
Loading

0 comments on commit 61bed8c

Please sign in to comment.