Skip to content

Commit

Permalink
fix: logger to use local one (#47)
Browse files Browse the repository at this point in the history
* use local logger

* update bin files
  • Loading branch information
beer-1 authored Aug 20, 2024
1 parent 41c1c3e commit a4d23d2
Show file tree
Hide file tree
Showing 18 changed files with 53 additions and 42 deletions.
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 @@ package backend
import (
"context"

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

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

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 @@ type JSONRPCBackend struct {
// 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,
}
}
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 @@ func (b *JSONRPCBackend) GetHeaderByNumber(ethBlockNum rpc.BlockNumber) (*corety
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)
return nil, err
}

Expand All @@ -90,7 +90,7 @@ func (b *JSONRPCBackend) GetHeaderByHash(hash common.Hash) (*coretypes.Header, e
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)
return nil, err
}

Expand All @@ -112,7 +112,7 @@ func (b *JSONRPCBackend) GetBlockByNumber(ethBlockNum rpc.BlockNumber, fullTx bo
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)
return nil, err
}

Expand Down Expand Up @@ -140,7 +140,7 @@ func (b *JSONRPCBackend) GetBlockByHash(hash common.Hash, fullTx bool) (map[stri
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)
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 @@ func (b *JSONRPCBackend) EstimateGas(args rpctypes.TransactionArgs, blockNrOrHas

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)
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 @@ import (
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 @@ func (b *JSONRPCBackend) SendTx(tx *coretypes.Transaction) error {
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)
}
}

txBytes, err := b.app.TxEncode(cosmosTx)
if err != nil {
return err
Expand Down Expand Up @@ -79,7 +86,7 @@ func (b *JSONRPCBackend) GetTransactionByHash(hash common.Hash) (*rpctypes.RPCTr
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)
return nil, NewTxIndexingError()
}

Expand All @@ -101,7 +108,7 @@ func (b *JSONRPCBackend) GetTransactionCount(address common.Address, blockNrOrHa
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)
return nil, err
}

Expand Down Expand Up @@ -141,15 +148,15 @@ func (b *JSONRPCBackend) GetTransactionReceipt(hash common.Hash) (map[string]int
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)
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)
return nil, NewTxIndexingError()
}

Expand All @@ -167,15 +174,15 @@ func (b *JSONRPCBackend) GetTransactionByBlockHashAndIndex(hash common.Hash, idx
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)
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)
return nil, err
}

Expand All @@ -194,7 +201,7 @@ func (b *JSONRPCBackend) GetTransactionByBlockNumberAndIndex(blockNum rpc.BlockN
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)
return nil, err
}

Expand Down Expand Up @@ -238,7 +245,7 @@ func (b *JSONRPCBackend) GetRawTransactionByHash(hash common.Hash) (hexutil.Byte
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)
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 @@ func StartJSONRPC(

rpcServer := rpc.NewServer()
rpcServer.SetBatchLimits(jsonRPCConfig.BatchRequestLimit, jsonRPCConfig.BatchResponseMaxSize)
bkd := backend.NewJSONRPCBackend(app, svrCtx, clientCtx, jsonRPCConfig)
bkd := backend.NewJSONRPCBackend(app, logger, svrCtx, clientCtx, jsonRPCConfig)
apis := []rpc.API{
{
Namespace: EthNamespace,
Version: apiVersion,
Service: ethns.NewEthAPI(svrCtx.Logger, bkd),
Service: ethns.NewEthAPI(logger, bkd),
Public: true,
},
{
Namespace: EthNamespace,
Version: apiVersion,
Service: filters.NewFilterAPI(app, bkd, svrCtx.Logger),
Service: filters.NewFilterAPI(app, bkd, logger),
Public: true,
},
{
Namespace: NetNamespace,
Version: apiVersion,
Service: netns.NewNetAPI(svrCtx.Logger, bkd),
Service: netns.NewNetAPI(logger, bkd),
Public: true,
},
{
Namespace: Web3Namespace,
Version: apiVersion,
Service: web3ns.NewWeb3API(svrCtx.Logger, bkd),
Service: web3ns.NewWeb3API(logger, bkd),
Public: true,
},
{
Namespace: TxPoolNamespace,
Version: apiVersion,
Service: txpoolns.NewTxPoolAPI(svrCtx.Logger, bkd),
Service: txpoolns.NewTxPoolAPI(logger, bkd),
Public: true,
},
{
Namespace: CosmosNamespace,
Version: apiVersion,
Service: cosmosns.NewCosmosAPI(svrCtx.Logger, bkd),
Service: cosmosns.NewCosmosAPI(logger, bkd),
Public: true,
},
}
Expand All @@ -109,7 +109,7 @@ func StartJSONRPC(
}

if err := rpcServer.RegisterName(api.Namespace, api.Service); err != nil {
svrCtx.Logger.Error(
logger.Error(
"failed to register service in JSON RPC namespace",
"namespace", api.Namespace,
"service", api.Service,
Expand Down Expand Up @@ -158,9 +158,9 @@ func StartJSONRPC(

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

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

0 comments on commit a4d23d2

Please sign in to comment.