Browse Source

log: dissallow nil loggers (#7445)

pull/7449/head
Sam Kleinman 3 years ago
committed by GitHub
parent
commit
2ff962a63a
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 38 additions and 34 deletions
  1. +2
    -2
      abci/client/creators.go
  2. +3
    -2
      abci/client/local_client.go
  3. +3
    -3
      internal/blocksync/pool.go
  4. +2
    -2
      internal/consensus/byzantine_test.go
  5. +2
    -2
      internal/consensus/common_test.go
  6. +2
    -2
      internal/consensus/reactor_test.go
  7. +1
    -1
      internal/consensus/state.go
  8. +3
    -1
      internal/statesync/stateprovider.go
  9. +2
    -1
      libs/events/event_cache_test.go
  10. +3
    -2
      libs/events/events.go
  11. +9
    -8
      libs/events/events_test.go
  12. +0
    -4
      libs/service/service.go
  13. +2
    -1
      libs/service/service_test.go
  14. +1
    -1
      light/proxy/proxy.go
  15. +3
    -2
      light/rpc/client.go

+ 2
- 2
abci/client/creators.go View File

@ -16,8 +16,8 @@ type Creator func(log.Logger) (Client, error)
func NewLocalCreator(app types.Application) Creator {
mtx := new(sync.Mutex)
return func(_ log.Logger) (Client, error) {
return NewLocalClient(mtx, app), nil
return func(logger log.Logger) (Client, error) {
return NewLocalClient(logger, mtx, app), nil
}
}


+ 3
- 2
abci/client/local_client.go View File

@ -5,6 +5,7 @@ import (
"sync"
types "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/libs/service"
)
@ -26,7 +27,7 @@ var _ Client = (*localClient)(nil)
// methods of the given app.
//
// Both Async and Sync methods ignore the given context.Context parameter.
func NewLocalClient(mtx *sync.Mutex, app types.Application) Client {
func NewLocalClient(logger log.Logger, mtx *sync.Mutex, app types.Application) Client {
if mtx == nil {
mtx = new(sync.Mutex)
}
@ -34,7 +35,7 @@ func NewLocalClient(mtx *sync.Mutex, app types.Application) Client {
mtx: mtx,
Application: app,
}
cli.BaseService = *service.NewBaseService(nil, "localClient", cli)
cli.BaseService = *service.NewBaseService(logger, "localClient", cli)
return cli
}


+ 3
- 3
internal/blocksync/pool.go View File

@ -418,7 +418,7 @@ func (pool *BlockPool) makeNextRequester(ctx context.Context) {
return
}
request := newBPRequester(pool, nextHeight)
request := newBPRequester(pool.logger, pool, nextHeight)
pool.requesters[nextHeight] = request
atomic.AddInt32(&pool.numPending, 1)
@ -565,7 +565,7 @@ type bpRequester struct {
block *types.Block
}
func newBPRequester(pool *BlockPool, height int64) *bpRequester {
func newBPRequester(logger log.Logger, pool *BlockPool, height int64) *bpRequester {
bpr := &bpRequester{
logger: pool.logger,
pool: pool,
@ -576,7 +576,7 @@ func newBPRequester(pool *BlockPool, height int64) *bpRequester {
peerID: "",
block: nil,
}
bpr.BaseService = *service.NewBaseService(nil, "bpRequester", bpr)
bpr.BaseService = *service.NewBaseService(logger, "bpRequester", bpr)
return bpr
}


+ 2
- 2
internal/consensus/byzantine_test.go View File

@ -68,8 +68,8 @@ func TestByzantinePrevoteEquivocation(t *testing.T) {
// one for mempool, one for consensus
mtx := new(sync.Mutex)
proxyAppConnMem := abciclient.NewLocalClient(mtx, app)
proxyAppConnCon := abciclient.NewLocalClient(mtx, app)
proxyAppConnMem := abciclient.NewLocalClient(logger, mtx, app)
proxyAppConnCon := abciclient.NewLocalClient(logger, mtx, app)
// Make Mempool
mempool := mempool.NewTxMempool(


+ 2
- 2
internal/consensus/common_test.go View File

@ -440,8 +440,8 @@ func newStateWithConfigAndBlockStore(
) *State {
// one for mempool, one for consensus
mtx := new(sync.Mutex)
proxyAppConnMem := abciclient.NewLocalClient(mtx, app)
proxyAppConnCon := abciclient.NewLocalClient(mtx, app)
proxyAppConnMem := abciclient.NewLocalClient(logger, mtx, app)
proxyAppConnCon := abciclient.NewLocalClient(logger, mtx, app)
// Make Mempool


+ 2
- 2
internal/consensus/reactor_test.go View File

@ -392,8 +392,8 @@ func TestReactorWithEvidence(t *testing.T) {
// one for mempool, one for consensus
mtx := new(sync.Mutex)
proxyAppConnMem := abciclient.NewLocalClient(mtx, app)
proxyAppConnCon := abciclient.NewLocalClient(mtx, app)
proxyAppConnMem := abciclient.NewLocalClient(logger, mtx, app)
proxyAppConnCon := abciclient.NewLocalClient(logger, mtx, app)
mempool := mempool.NewTxMempool(
log.TestingLogger().With("module", "mempool"),


+ 1
- 1
internal/consensus/state.go View File

@ -178,7 +178,7 @@ func NewState(
doWALCatchup: true,
wal: nilWAL{},
evpool: evpool,
evsw: tmevents.NewEventSwitch(),
evsw: tmevents.NewEventSwitch(logger),
metrics: NopMetrics(),
onStopCh: make(chan *cstypes.RoundState),
}


+ 3
- 1
internal/statesync/stateprovider.go View File

@ -44,6 +44,7 @@ type stateProviderRPC struct {
lc *light.Client
initialHeight int64
providers map[lightprovider.Provider]string
logger log.Logger
}
// NewRPCStateProvider creates a new StateProvider using a light client and RPC clients.
@ -79,6 +80,7 @@ func NewRPCStateProvider(
return nil, err
}
return &stateProviderRPC{
logger: logger,
lc: lc,
initialHeight: initialHeight,
providers: providerRemotes,
@ -176,7 +178,7 @@ func (s *stateProviderRPC) State(ctx context.Context, height uint64) (sm.State,
if err != nil {
return sm.State{}, fmt.Errorf("unable to create RPC client: %w", err)
}
rpcclient := lightrpc.NewClient(primaryRPC, s.lc)
rpcclient := lightrpc.NewClient(s.logger, primaryRPC, s.lc)
result, err := rpcclient.ConsensusParams(ctx, &currentLightBlock.Height)
if err != nil {
return sm.State{}, fmt.Errorf("unable to fetch consensus parameters for height %v: %w",


+ 2
- 1
libs/events/event_cache_test.go View File

@ -6,13 +6,14 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/libs/log"
)
func TestEventCache_Flush(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
evsw := NewEventSwitch()
evsw := NewEventSwitch(log.TestingLogger())
err := evsw.Start(ctx)
require.NoError(t, err)


+ 3
- 2
libs/events/events.go View File

@ -6,6 +6,7 @@ import (
"fmt"
"sync"
"github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/libs/service"
)
@ -61,12 +62,12 @@ type eventSwitch struct {
listeners map[string]*eventListener
}
func NewEventSwitch() EventSwitch {
func NewEventSwitch(logger log.Logger) EventSwitch {
evsw := &eventSwitch{
eventCells: make(map[string]*eventCell),
listeners: make(map[string]*eventListener),
}
evsw.BaseService = *service.NewBaseService(nil, "EventSwitch", evsw)
evsw.BaseService = *service.NewBaseService(logger, "EventSwitch", evsw)
return evsw
}


+ 9
- 8
libs/events/events_test.go View File

@ -9,6 +9,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/libs/rand"
)
@ -18,7 +19,7 @@ func TestAddListenerForEventFireOnce(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
evsw := NewEventSwitch()
evsw := NewEventSwitch(log.TestingLogger())
require.NoError(t, evsw.Start(ctx))
t.Cleanup(evsw.Wait)
@ -47,7 +48,7 @@ func TestAddListenerForEventFireMany(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
evsw := NewEventSwitch()
evsw := NewEventSwitch(log.TestingLogger())
require.NoError(t, evsw.Start(ctx))
t.Cleanup(evsw.Wait)
@ -83,7 +84,7 @@ func TestAddListenerForDifferentEvents(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
evsw := NewEventSwitch()
evsw := NewEventSwitch(log.TestingLogger())
require.NoError(t, evsw.Start(ctx))
t.Cleanup(evsw.Wait)
@ -145,7 +146,7 @@ func TestAddDifferentListenerForDifferentEvents(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
evsw := NewEventSwitch()
evsw := NewEventSwitch(log.TestingLogger())
require.NoError(t, evsw.Start(ctx))
t.Cleanup(evsw.Wait)
@ -235,7 +236,7 @@ func TestAddAndRemoveListenerConcurrency(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
evsw := NewEventSwitch()
evsw := NewEventSwitch(log.TestingLogger())
require.NoError(t, evsw.Start(ctx))
t.Cleanup(evsw.Wait)
@ -284,7 +285,7 @@ func TestAddAndRemoveListener(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
evsw := NewEventSwitch()
evsw := NewEventSwitch(log.TestingLogger())
require.NoError(t, evsw.Start(ctx))
t.Cleanup(evsw.Wait)
@ -340,7 +341,7 @@ func TestAddAndRemoveListener(t *testing.T) {
func TestRemoveListener(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
evsw := NewEventSwitch()
evsw := NewEventSwitch(log.TestingLogger())
require.NoError(t, evsw.Start(ctx))
t.Cleanup(evsw.Wait)
@ -397,7 +398,7 @@ func TestRemoveListener(t *testing.T) {
func TestRemoveListenersAsync(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
evsw := NewEventSwitch()
evsw := NewEventSwitch(log.TestingLogger())
require.NoError(t, evsw.Start(ctx))
t.Cleanup(evsw.Wait)


+ 0
- 4
libs/service/service.go View File

@ -104,10 +104,6 @@ type BaseService struct {
// NewBaseService creates a new BaseService.
func NewBaseService(logger log.Logger, name string, impl Implementation) *BaseService {
if logger == nil {
logger = log.NewNopLogger()
}
return &BaseService{
logger: logger,
name: name,


+ 2
- 1
libs/service/service_test.go View File

@ -6,6 +6,7 @@ import (
"time"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/libs/log"
)
type testService struct {
@ -22,7 +23,7 @@ func TestBaseServiceWait(t *testing.T) {
defer cancel()
ts := &testService{}
ts.BaseService = *NewBaseService(nil, "TestService", ts)
ts.BaseService = *NewBaseService(log.TestingLogger(), "TestService", ts)
err := ts.Start(ctx)
require.NoError(t, err)


+ 1
- 1
light/proxy/proxy.go View File

@ -40,7 +40,7 @@ func NewProxy(
return &Proxy{
Addr: listenAddr,
Config: config,
Client: lrpc.NewClient(rpcClient, lightClient, opts...),
Client: lrpc.NewClient(logger, rpcClient, lightClient, opts...),
Logger: logger,
}, nil
}


+ 3
- 2
light/rpc/client.go View File

@ -13,6 +13,7 @@ import (
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto/merkle"
tmbytes "github.com/tendermint/tendermint/libs/bytes"
"github.com/tendermint/tendermint/libs/log"
tmmath "github.com/tendermint/tendermint/libs/math"
service "github.com/tendermint/tendermint/libs/service"
rpcclient "github.com/tendermint/tendermint/rpc/client"
@ -88,14 +89,14 @@ func DefaultMerkleKeyPathFn() KeyPathFunc {
}
// NewClient returns a new client.
func NewClient(next rpcclient.Client, lc LightClient, opts ...Option) *Client {
func NewClient(logger log.Logger, next rpcclient.Client, lc LightClient, opts ...Option) *Client {
c := &Client{
next: next,
lc: lc,
prt: merkle.DefaultProofRuntime(),
quitCh: make(chan struct{}),
}
c.BaseService = *service.NewBaseService(nil, "Client", c)
c.BaseService = *service.NewBaseService(logger, "Client", c)
for _, o := range opts {
o(c)
}


Loading…
Cancel
Save