Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: logger to use local one #47

Merged
merged 2 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require (
cosmossdk.io/x/tx v0.13.3
cosmossdk.io/x/upgrade v0.1.3
github.com/allegro/bigcache/v3 v3.1.0
github.com/cometbft/cometbft v0.38.10
github.com/cometbft/cometbft v0.38.11
github.com/cosmos/cosmos-db v1.0.2
github.com/cosmos/cosmos-proto v1.0.0-beta.5
github.com/cosmos/cosmos-sdk v0.50.8
Expand Down Expand Up @@ -281,7 +281,7 @@ replace (

// initia custom
replace (
github.com/cometbft/cometbft => github.com/initia-labs/cometbft v0.0.0-20240807072006-9d86e6bfaf87
github.com/cometbft/cometbft => github.com/initia-labs/cometbft v0.0.0-20240820063101-22962752beb2
github.com/cosmos/ibc-go/v8 => github.com/initia-labs/ibc-go/v8 v8.0.0-20240802003717-19c0b4ad450d
github.com/ethereum/go-ethereum => github.com/initia-labs/evm v0.0.0-20240620024053-f13ebda716b7
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -815,8 +815,8 @@ github.com/initia-labs/OPinit v0.4.1 h1:g6IVEAOe2X31pgjk/q0zg4R1GfNj2QP3q5s3HMcW
github.com/initia-labs/OPinit v0.4.1/go.mod h1:n0eqwOnVGE1vuTnW+3jzyEXfE4ndTM0vCRGmPu9VvUc=
github.com/initia-labs/OPinit/api v0.4.1 h1:Q8etW92LiwekKZxzDYVFdiHF3uOpEA4nyajy8zpcxB0=
github.com/initia-labs/OPinit/api v0.4.1/go.mod h1:Xy/Nt3ubXLQ4zKn0m7RuQOM1sj8TVdlNNyek21TGYR0=
github.com/initia-labs/cometbft v0.0.0-20240807072006-9d86e6bfaf87 h1:pLdZxGPBfj/N3vq0XEJMdbb9mUZQ/Xi0NpjNq8DEpeg=
github.com/initia-labs/cometbft v0.0.0-20240807072006-9d86e6bfaf87/go.mod h1:xCLFOVbO/2WIk/3m0qVemx1FdYo5dI64ehkwPou08Yo=
github.com/initia-labs/cometbft v0.0.0-20240820063101-22962752beb2 h1:UwPPVwxKIptZ8RvaoICK3Kl6335qgmtszjwHbQzrw7k=
github.com/initia-labs/cometbft v0.0.0-20240820063101-22962752beb2/go.mod h1:xCLFOVbO/2WIk/3m0qVemx1FdYo5dI64ehkwPou08Yo=
github.com/initia-labs/evm v0.0.0-20240620024053-f13ebda716b7 h1:V7K8wvE5FVVv6WTeITI+nqWfo4b9WlZyXQH0Olz5UVI=
github.com/initia-labs/evm v0.0.0-20240620024053-f13ebda716b7/go.mod h1:x2gtBG0WHLgY08FE97lfhjtpcR5vcSAZbi34JnrsBbQ=
github.com/initia-labs/ibc-go/v8 v8.0.0-20240802003717-19c0b4ad450d h1:TLq8lB1PtQ0pjGf+bN8YgGVeLMuytZ26SBGMOs1seKY=
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.22.5

require (
cosmossdk.io/math v1.3.0
github.com/cometbft/cometbft v0.38.10
github.com/cometbft/cometbft v0.38.11
github.com/cosmos/cosmos-sdk v0.50.8
github.com/cosmos/ibc-go/v8 v8.4.0
github.com/ethereum/go-ethereum v1.14.7
Expand Down Expand Up @@ -265,7 +265,7 @@ replace (

// initia custom
replace (
github.com/cometbft/cometbft => github.com/initia-labs/cometbft v0.0.0-20240807072006-9d86e6bfaf87
github.com/cometbft/cometbft => github.com/initia-labs/cometbft v0.0.0-20240820063101-22962752beb2
github.com/cosmos/ibc-go/v8 => github.com/initia-labs/ibc-go/v8 v8.0.0-20240802003717-19c0b4ad450d
github.com/ethereum/go-ethereum => github.com/initia-labs/evm v0.0.0-20240620024053-f13ebda716b7
)
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -777,8 +777,8 @@ github.com/initia-labs/OPinit v0.4.1 h1:g6IVEAOe2X31pgjk/q0zg4R1GfNj2QP3q5s3HMcW
github.com/initia-labs/OPinit v0.4.1/go.mod h1:n0eqwOnVGE1vuTnW+3jzyEXfE4ndTM0vCRGmPu9VvUc=
github.com/initia-labs/OPinit/api v0.4.1 h1:Q8etW92LiwekKZxzDYVFdiHF3uOpEA4nyajy8zpcxB0=
github.com/initia-labs/OPinit/api v0.4.1/go.mod h1:Xy/Nt3ubXLQ4zKn0m7RuQOM1sj8TVdlNNyek21TGYR0=
github.com/initia-labs/cometbft v0.0.0-20240807072006-9d86e6bfaf87 h1:pLdZxGPBfj/N3vq0XEJMdbb9mUZQ/Xi0NpjNq8DEpeg=
github.com/initia-labs/cometbft v0.0.0-20240807072006-9d86e6bfaf87/go.mod h1:xCLFOVbO/2WIk/3m0qVemx1FdYo5dI64ehkwPou08Yo=
github.com/initia-labs/cometbft v0.0.0-20240820063101-22962752beb2 h1:UwPPVwxKIptZ8RvaoICK3Kl6335qgmtszjwHbQzrw7k=
github.com/initia-labs/cometbft v0.0.0-20240820063101-22962752beb2/go.mod h1:xCLFOVbO/2WIk/3m0qVemx1FdYo5dI64ehkwPou08Yo=
github.com/initia-labs/evm v0.0.0-20240620024053-f13ebda716b7 h1:V7K8wvE5FVVv6WTeITI+nqWfo4b9WlZyXQH0Olz5UVI=
github.com/initia-labs/evm v0.0.0-20240620024053-f13ebda716b7/go.mod h1:x2gtBG0WHLgY08FE97lfhjtpcR5vcSAZbi34JnrsBbQ=
github.com/initia-labs/ibc-go/v8 v8.0.0-20240802003717-19c0b4ad450d h1:TLq8lB1PtQ0pjGf+bN8YgGVeLMuytZ26SBGMOs1seKY=
Expand Down
8 changes: 6 additions & 2 deletions jsonrpc/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import (
"context"

"cosmossdk.io/log"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/server"

Expand All @@ -11,7 +12,9 @@
)

type JSONRPCBackend struct {
app *app.MinitiaApp
app *app.MinitiaApp
logger log.Logger

svrCtx *server.Context
clientCtx client.Context
cfg config.JSONRPCConfig
Expand All @@ -22,12 +25,13 @@
// NewJSONRPCBackend creates a new JSONRPCBackend instance
func NewJSONRPCBackend(
app *app.MinitiaApp,
logger log.Logger,
svrCtx *server.Context,
clientCtx client.Context,
cfg config.JSONRPCConfig,
) *JSONRPCBackend {
ctx := context.Background()
return &JSONRPCBackend{
app, svrCtx, clientCtx, cfg, ctx,
app, logger, svrCtx, clientCtx, cfg, ctx,

Check warning on line 35 in jsonrpc/backend/backend.go

View check run for this annotation

Codecov / codecov/patch

jsonrpc/backend/backend.go#L35

Added line #L35 was not covered by tests
}
}
8 changes: 4 additions & 4 deletions jsonrpc/backend/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
if err != nil && errors.Is(err, collections.ErrNotFound) {
return nil, nil
} else if err != nil {
b.svrCtx.Logger.Error("failed to get block header by number", "err", err)
b.logger.Error("failed to get block header by number", "err", err)

Check warning on line 76 in jsonrpc/backend/block.go

View check run for this annotation

Codecov / codecov/patch

jsonrpc/backend/block.go#L76

Added line #L76 was not covered by tests
return nil, err
}

Expand All @@ -90,7 +90,7 @@
if err != nil && errors.Is(err, collections.ErrNotFound) {
return nil, nil
} else if err != nil {
b.svrCtx.Logger.Error("failed to get block header by hash", "err", err)
b.logger.Error("failed to get block header by hash", "err", err)

Check warning on line 93 in jsonrpc/backend/block.go

View check run for this annotation

Codecov / codecov/patch

jsonrpc/backend/block.go#L93

Added line #L93 was not covered by tests
return nil, err
}

Expand All @@ -112,7 +112,7 @@
if err != nil && errors.Is(err, collections.ErrNotFound) {
return nil, nil
} else if err != nil {
b.svrCtx.Logger.Error("failed to get block header by number", "err", err)
b.logger.Error("failed to get block header by number", "err", err)

Check warning on line 115 in jsonrpc/backend/block.go

View check run for this annotation

Codecov / codecov/patch

jsonrpc/backend/block.go#L115

Added line #L115 was not covered by tests
return nil, err
}

Expand Down Expand Up @@ -140,7 +140,7 @@
if err != nil && errors.Is(err, collections.ErrNotFound) {
return nil, nil
} else if err != nil {
b.svrCtx.Logger.Error("failed to get block header by hash", "err", err)
b.logger.Error("failed to get block header by hash", "err", err)

Check warning on line 143 in jsonrpc/backend/block.go

View check run for this annotation

Codecov / codecov/patch

jsonrpc/backend/block.go#L143

Added line #L143 was not covered by tests
return nil, err
}

Expand Down
2 changes: 1 addition & 1 deletion jsonrpc/backend/gas.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@

gasInfo, _, err := b.app.Simulate(txBytes)
if err != nil {
b.svrCtx.Logger.Error("failed to simulate tx", "err", err)
b.logger.Error("failed to simulate tx", "err", err)

Check warning on line 86 in jsonrpc/backend/gas.go

View check run for this annotation

Codecov / codecov/patch

jsonrpc/backend/gas.go#L86

Added line #L86 was not covered by tests
return hexutil.Uint64(0), err
}

Expand Down
23 changes: 15 additions & 8 deletions jsonrpc/backend/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
coretypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/rpc"

authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
rpctypes "github.com/initia-labs/minievm/jsonrpc/types"
"github.com/initia-labs/minievm/x/evm/keeper"
"github.com/initia-labs/minievm/x/evm/types"
Expand Down Expand Up @@ -44,6 +45,12 @@
return err
}

if authTx, ok := cosmosTx.(authsigning.Tx); ok {
if sigs, err := authTx.GetSignaturesV2(); err == nil && len(sigs) > 0 {
b.logger.Debug("eth_sendTx", "sequence", sigs[0].Sequence)
}

Check warning on line 51 in jsonrpc/backend/tx.go

View check run for this annotation

Codecov / codecov/patch

jsonrpc/backend/tx.go#L48-L51

Added lines #L48 - L51 were not covered by tests
}

txBytes, err := b.app.TxEncode(cosmosTx)
if err != nil {
return err
Expand Down Expand Up @@ -79,7 +86,7 @@
if err != nil && errors.Is(err, collections.ErrNotFound) {
return nil, nil
} else if err != nil {
b.svrCtx.Logger.Error("failed to get transaction by hash", "err", err)
b.logger.Error("failed to get transaction by hash", "err", err)

Check warning on line 89 in jsonrpc/backend/tx.go

View check run for this annotation

Codecov / codecov/patch

jsonrpc/backend/tx.go#L89

Added line #L89 was not covered by tests
return nil, NewTxIndexingError()
}

Expand All @@ -101,7 +108,7 @@
if err != nil && errors.Is(err, collections.ErrNotFound) {
return nil, nil
} else if err != nil {
b.svrCtx.Logger.Error("failed to get block number by hash", "err", err)
b.logger.Error("failed to get block number by hash", "err", err)

Check warning on line 111 in jsonrpc/backend/tx.go

View check run for this annotation

Codecov / codecov/patch

jsonrpc/backend/tx.go#L111

Added line #L111 was not covered by tests
return nil, err
}

Expand Down Expand Up @@ -141,15 +148,15 @@
if err != nil && errors.Is(err, collections.ErrNotFound) {
return nil, nil
} else if err != nil {
b.svrCtx.Logger.Error("failed to get transaction by hash", "err", err)
b.logger.Error("failed to get transaction by hash", "err", err)

Check warning on line 151 in jsonrpc/backend/tx.go

View check run for this annotation

Codecov / codecov/patch

jsonrpc/backend/tx.go#L151

Added line #L151 was not covered by tests
return nil, NewTxIndexingError()
}

receipt, err := b.app.EVMIndexer().TxReceiptByHash(queryCtx, hash)
if err != nil && errors.Is(err, collections.ErrNotFound) {
return nil, nil
} else if err != nil {
b.svrCtx.Logger.Error("failed to get transaction receipt by hash", "err", err)
b.logger.Error("failed to get transaction receipt by hash", "err", err)

Check warning on line 159 in jsonrpc/backend/tx.go

View check run for this annotation

Codecov / codecov/patch

jsonrpc/backend/tx.go#L159

Added line #L159 was not covered by tests
return nil, NewTxIndexingError()
}

Expand All @@ -167,15 +174,15 @@
if err != nil && errors.Is(err, collections.ErrNotFound) {
return nil, nil
} else if err != nil {
b.svrCtx.Logger.Error("failed to get block number by hash", "err", err)
b.logger.Error("failed to get block number by hash", "err", err)

Check warning on line 177 in jsonrpc/backend/tx.go

View check run for this annotation

Codecov / codecov/patch

jsonrpc/backend/tx.go#L177

Added line #L177 was not covered by tests
return nil, err
}

rpcTx, err := b.app.EVMIndexer().TxByBlockAndIndex(queryCtx, number, uint64(idx))
if err != nil && errors.Is(err, collections.ErrNotFound) {
return nil, nil
} else if err != nil {
b.svrCtx.Logger.Error("failed to get transaction by block and index", "err", err)
b.logger.Error("failed to get transaction by block and index", "err", err)

Check warning on line 185 in jsonrpc/backend/tx.go

View check run for this annotation

Codecov / codecov/patch

jsonrpc/backend/tx.go#L185

Added line #L185 was not covered by tests
return nil, err
}

Expand All @@ -194,7 +201,7 @@
if err != nil && errors.Is(err, collections.ErrNotFound) {
return nil, nil
} else if err != nil {
b.svrCtx.Logger.Error("failed to get transaction by block and index", "err", err)
b.logger.Error("failed to get transaction by block and index", "err", err)

Check warning on line 204 in jsonrpc/backend/tx.go

View check run for this annotation

Codecov / codecov/patch

jsonrpc/backend/tx.go#L204

Added line #L204 was not covered by tests
return nil, err
}

Expand Down Expand Up @@ -238,7 +245,7 @@
if err != nil && errors.Is(err, collections.ErrNotFound) {
return nil, nil
} else if err != nil {
b.svrCtx.Logger.Error("failed to get raw transaction by hash", "err", err)
b.logger.Error("failed to get raw transaction by hash", "err", err)

Check warning on line 248 in jsonrpc/backend/tx.go

View check run for this annotation

Codecov / codecov/patch

jsonrpc/backend/tx.go#L248

Added line #L248 was not covered by tests
return nil, NewTxIndexingError()
} else if rpcTx == nil {
return nil, nil
Expand Down
20 changes: 10 additions & 10 deletions jsonrpc/jsonrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,42 +63,42 @@

rpcServer := rpc.NewServer()
rpcServer.SetBatchLimits(jsonRPCConfig.BatchRequestLimit, jsonRPCConfig.BatchResponseMaxSize)
bkd := backend.NewJSONRPCBackend(app, svrCtx, clientCtx, jsonRPCConfig)
bkd := backend.NewJSONRPCBackend(app, logger, svrCtx, clientCtx, jsonRPCConfig)

Check warning on line 66 in jsonrpc/jsonrpc.go

View check run for this annotation

Codecov / codecov/patch

jsonrpc/jsonrpc.go#L66

Added line #L66 was not covered by tests
apis := []rpc.API{
{
Namespace: EthNamespace,
Version: apiVersion,
Service: ethns.NewEthAPI(svrCtx.Logger, bkd),
Service: ethns.NewEthAPI(logger, bkd),

Check warning on line 71 in jsonrpc/jsonrpc.go

View check run for this annotation

Codecov / codecov/patch

jsonrpc/jsonrpc.go#L71

Added line #L71 was not covered by tests
Public: true,
},
{
Namespace: EthNamespace,
Version: apiVersion,
Service: filters.NewFilterAPI(app, bkd, svrCtx.Logger),
Service: filters.NewFilterAPI(app, bkd, logger),

Check warning on line 77 in jsonrpc/jsonrpc.go

View check run for this annotation

Codecov / codecov/patch

jsonrpc/jsonrpc.go#L77

Added line #L77 was not covered by tests
Public: true,
},
{
Namespace: NetNamespace,
Version: apiVersion,
Service: netns.NewNetAPI(svrCtx.Logger, bkd),
Service: netns.NewNetAPI(logger, bkd),

Check warning on line 83 in jsonrpc/jsonrpc.go

View check run for this annotation

Codecov / codecov/patch

jsonrpc/jsonrpc.go#L83

Added line #L83 was not covered by tests
Public: true,
},
{
Namespace: Web3Namespace,
Version: apiVersion,
Service: web3ns.NewWeb3API(svrCtx.Logger, bkd),
Service: web3ns.NewWeb3API(logger, bkd),

Check warning on line 89 in jsonrpc/jsonrpc.go

View check run for this annotation

Codecov / codecov/patch

jsonrpc/jsonrpc.go#L89

Added line #L89 was not covered by tests
Public: true,
},
{
Namespace: TxPoolNamespace,
Version: apiVersion,
Service: txpoolns.NewTxPoolAPI(svrCtx.Logger, bkd),
Service: txpoolns.NewTxPoolAPI(logger, bkd),

Check warning on line 95 in jsonrpc/jsonrpc.go

View check run for this annotation

Codecov / codecov/patch

jsonrpc/jsonrpc.go#L95

Added line #L95 was not covered by tests
Public: true,
},
{
Namespace: CosmosNamespace,
Version: apiVersion,
Service: cosmosns.NewCosmosAPI(svrCtx.Logger, bkd),
Service: cosmosns.NewCosmosAPI(logger, bkd),

Check warning on line 101 in jsonrpc/jsonrpc.go

View check run for this annotation

Codecov / codecov/patch

jsonrpc/jsonrpc.go#L101

Added line #L101 was not covered by tests
Public: true,
},
}
Expand All @@ -109,7 +109,7 @@
}

if err := rpcServer.RegisterName(api.Namespace, api.Service); err != nil {
svrCtx.Logger.Error(
logger.Error(

Check warning on line 112 in jsonrpc/jsonrpc.go

View check run for this annotation

Codecov / codecov/patch

jsonrpc/jsonrpc.go#L112

Added line #L112 was not covered by tests
"failed to register service in JSON RPC namespace",
"namespace", api.Namespace,
"service", api.Service,
Expand Down Expand Up @@ -158,9 +158,9 @@

go func() {
if !isWebSocket {
svrCtx.Logger.Info("Starting JSON-RPC server", "address", addr)
logger.Info("Starting JSON-RPC server", "address", addr)

Check warning on line 161 in jsonrpc/jsonrpc.go

View check run for this annotation

Codecov / codecov/patch

jsonrpc/jsonrpc.go#L161

Added line #L161 was not covered by tests
} else {
svrCtx.Logger.Info("Starting JSON-RPC WebSocket server", "address", addr)
logger.Info("Starting JSON-RPC WebSocket server", "address", addr)

Check warning on line 163 in jsonrpc/jsonrpc.go

View check run for this annotation

Codecov / codecov/patch

jsonrpc/jsonrpc.go#L163

Added line #L163 was not covered by tests
}

errCh <- httpSrv.Serve(ln)
Expand Down
Loading
Loading