Skip to content

Commit

Permalink
Use zap logger in txs package (#5973)
Browse files Browse the repository at this point in the history
## Motivation

In the continued effort to replace our custom `log.Log` with `zap.Logger` I updated the `txs` package to not depend on our logger any more.
  • Loading branch information
fasmat committed May 23, 2024
1 parent 794aa17 commit f9b4108
Show file tree
Hide file tree
Showing 15 changed files with 270 additions and 211 deletions.
2 changes: 1 addition & 1 deletion api/grpcserver/grpcserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2275,7 +2275,7 @@ func TestEventsReceived(t *testing.T) {
time.Sleep(time.Millisecond * 50)

svm := vm.New(sql.InMemory(), vm.WithLogger(logtest.New(t)))
conState := txs.NewConservativeState(svm, sql.InMemory(), txs.WithLogger(logtest.New(t).WithName("conState")))
conState := txs.NewConservativeState(svm, sql.InMemory(), txs.WithLogger(zaptest.NewLogger(t).Named("conState")))
conState.AddToCache(context.Background(), globalTx, time.Now())

weight := new(big.Rat).SetFloat64(18.7)
Expand Down
6 changes: 3 additions & 3 deletions blocks/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,11 @@ func getBlockTXs(
stateF := func(_ types.Address) (uint64, uint64) {
return 0, math.MaxUint64
}
txCache := txs.NewCache(stateF, logger)
txCache := txs.NewCache(stateF, logger.Zap())
if err := txCache.BuildFromTXs(mtxs, blockSeed); err != nil {
return nil, fmt.Errorf("build txs for block: %w", err)
}
byAddrAndNonce := txCache.GetMempool(logger)
byAddrAndNonce := txCache.GetMempool(logger.Zap())
if len(byAddrAndNonce) == 0 {
logger.With().Warning("no feasible txs for block")
return nil, nil
Expand All @@ -179,7 +179,7 @@ func getBlockTXs(
mt := mt19937.New()
mt.SeedFromSlice(toUint64Slice(blockSeed))
rng := rand.New(mt)
ordered := txs.ShuffleWithNonceOrder(logger, rng, len(candidates), candidates, byAddrAndNonce)
ordered := txs.ShuffleWithNonceOrder(logger.Zap(), rng, len(candidates), candidates, byAddrAndNonce)
if gasLimit > 0 {
ordered = prune(logger, ordered, byTid, gasLimit)
}
Expand Down
4 changes: 2 additions & 2 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ func (app *App) initServices(ctx context.Context) error {
BlockGasLimit: app.Config.BlockGasLimit,
NumTXsPerProposal: app.Config.TxsPerProposal,
}),
txs.WithLogger(app.addLogger(ConStateLogger, lg)))
txs.WithLogger(app.addLogger(ConStateLogger, lg).Zap()))

genesisAccts := app.Config.Genesis.ToAccounts()
if len(genesisAccts) > 0 {
Expand Down Expand Up @@ -785,7 +785,7 @@ func (app *App) initServices(ctx context.Context) error {
app.txHandler = txs.NewTxHandler(
app.conState,
app.host.ID(),
app.addLogger(TxHandlerLogger, lg),
app.addLogger(TxHandlerLogger, lg).Zap(),
)

app.hOracle = eligibility.New(
Expand Down

0 comments on commit f9b4108

Please sign in to comment.