Skip to content

Commit 731aea3

Browse files
Migrate logging to uber-go/zap
1 parent 07a3164 commit 731aea3

58 files changed

Lines changed: 637 additions & 686 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

block/aggregation.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@ import (
44
"context"
55
"fmt"
66
"time"
7+
8+
"go.uber.org/zap"
79
)
810

911
// AggregationLoop is responsible for aggregating transactions into blocks.
1012
func (m *Manager) AggregationLoop(ctx context.Context, errCh chan<- error) {
1113
initialHeight := m.genesis.InitialHeight //nolint:gosec
1214
height, err := m.store.Height(ctx)
1315
if err != nil {
14-
m.logger.Error("error while getting store height", "error", err)
16+
m.logger.Error("error while getting store height", zap.Error(err))
1517
return
1618
}
1719
var delay time.Duration
@@ -24,7 +26,7 @@ func (m *Manager) AggregationLoop(ctx context.Context, errCh chan<- error) {
2426
}
2527

2628
if delay > 0 {
27-
m.logger.Info("waiting to produce block, delay:", delay)
29+
m.logger.Info("waiting to produce block", zap.Duration("delay", delay))
2830
time.Sleep(delay)
2931
}
3032

@@ -74,7 +76,7 @@ func (m *Manager) lazyAggregationLoop(ctx context.Context, blockTimer *time.Time
7476
m.txsAvailable = false
7577
} else {
7678
// Ensure we keep ticking even when there are no txs
77-
blockTimer.Reset(m.config.Node.BlockTime.Duration)
79+
blockTimer.Reset(getRemainingSleep(time.Now(), m.config.Node.BlockTime.Duration))
7880
}
7981
case <-m.txNotifyCh:
8082
m.txsAvailable = true
@@ -91,7 +93,7 @@ func (m *Manager) produceBlock(ctx context.Context, mode string, lazyTimer, bloc
9193
return fmt.Errorf("error while publishing block: %w", err)
9294
}
9395

94-
m.logger.Debug("Successfully published block", "mode", mode)
96+
m.logger.Debug("Successfully published block", zap.String("mode", mode))
9597

9698
// Reset both timers for the next aggregation window
9799
lazyTimer.Reset(getRemainingSleep(start, m.config.Node.LazyBlockInterval.Duration))

block/aggregation_test.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import (
88
"testing"
99
"time"
1010

11-
logging "github.com/ipfs/go-log/v2"
1211
"github.com/stretchr/testify/assert"
1312
"github.com/stretchr/testify/mock"
1413
"github.com/stretchr/testify/require"
14+
"go.uber.org/zap"
1515

1616
"github.com/evstack/ev-node/pkg/cache"
1717
"github.com/evstack/ev-node/pkg/config"
@@ -36,7 +36,7 @@ func TestAggregationLoop_Normal_BasicInterval(t *testing.T) {
3636
mockExec := mocks.NewMockExecutor(t)
3737
mockSeq := mocks.NewMockSequencer(t)
3838
mockDAC := mocks.NewMockDA(t)
39-
logger := logging.Logger("test")
39+
logger := zap.NewNop()
4040

4141
m := &Manager{
4242
store: mockStore,
@@ -71,7 +71,7 @@ func TestAggregationLoop_Normal_BasicInterval(t *testing.T) {
7171
publishLock.Lock()
7272
defer publishLock.Unlock()
7373
publishTimes = append(publishTimes, time.Now())
74-
m.logger.Debug("Mock publishBlock called", "time", publishTimes[len(publishTimes)-1])
74+
logger.Debug("Mock publishBlock called", zap.Time("time", publishTimes[len(publishTimes)-1]))
7575
return nil
7676
}
7777
m.publishBlock = mockPublishBlock
@@ -83,22 +83,22 @@ func TestAggregationLoop_Normal_BasicInterval(t *testing.T) {
8383
go func() {
8484
defer wg.Done()
8585
m.AggregationLoop(ctx, make(chan<- error))
86-
m.logger.Info("AggregationLoop exited")
86+
logger.Info("AggregationLoop exited")
8787
}()
8888

89-
m.logger.Info("Waiting for blocks..., duration:", waitTime)
89+
logger.Info("Waiting for blocks...", zap.Duration("duration", waitTime))
9090
time.Sleep(waitTime)
9191

92-
m.logger.Info("Cancelling context")
92+
logger.Info("Cancelling context")
9393
cancel()
94-
m.logger.Info("Waiting for WaitGroup")
94+
logger.Info("Waiting for WaitGroup")
9595
wg.Wait()
96-
m.logger.Info("WaitGroup finished")
96+
logger.Info("WaitGroup finished")
9797

9898
publishLock.Lock()
9999
defer publishLock.Unlock()
100100

101-
m.logger.Info("Recorded publish times, count:", len(publishTimes), "times:", publishTimes)
101+
logger.Info("Recorded publish times", zap.Int("count", len(publishTimes)), zap.Any("times", publishTimes))
102102

103103
expectedCallsLow := int(waitTime/blockTime) - 1
104104
expectedCallsHigh := int(waitTime/blockTime) + 1
@@ -108,7 +108,7 @@ func TestAggregationLoop_Normal_BasicInterval(t *testing.T) {
108108
if len(publishTimes) > 1 {
109109
for i := 1; i < len(publishTimes); i++ {
110110
interval := publishTimes[i].Sub(publishTimes[i-1])
111-
m.logger.Debug("Checking interval", "index", i, "interval", interval)
111+
logger.Debug("Checking interval", zap.Int("index", i), zap.Duration("interval", interval))
112112
tolerance := blockTime / 2
113113
assert.True(WithinDuration(t, blockTime, interval, tolerance), "Interval %d (%v) not within tolerance (%v) of blockTime (%v)", i, interval, tolerance, blockTime)
114114
}
@@ -131,7 +131,7 @@ func TestAggregationLoop_Normal_PublishBlockError(t *testing.T) {
131131
mockSeq := mocks.NewMockSequencer(t)
132132
mockDAC := mocks.NewMockDA(t)
133133

134-
logger := logging.Logger("test")
134+
logger := zap.NewNop()
135135

136136
// Create a basic Manager instance
137137
m := &Manager{
@@ -173,10 +173,10 @@ func TestAggregationLoop_Normal_PublishBlockError(t *testing.T) {
173173
publishLock.Unlock()
174174

175175
if callNum == 1 {
176-
m.logger.Debug("Mock publishBlock returning error", "call", callNum)
176+
logger.Debug("Mock publishBlock returning error", zap.Int64("call", callNum))
177177
return expectedErr
178178
}
179-
m.logger.Debug("Mock publishBlock returning nil", "call", callNum)
179+
logger.Debug("Mock publishBlock returning nil", zap.Int64("call", callNum))
180180
return nil
181181
}
182182
m.publishBlock = mockPublishBlock
@@ -189,7 +189,7 @@ func TestAggregationLoop_Normal_PublishBlockError(t *testing.T) {
189189
go func() {
190190
defer wg.Done()
191191
m.AggregationLoop(ctx, errCh)
192-
m.logger.Info("AggregationLoop exited")
192+
logger.Info("AggregationLoop exited")
193193
}()
194194

195195
time.Sleep(waitTime)

block/da_includer.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"encoding/binary"
66
"fmt"
77

8+
"go.uber.org/zap"
9+
810
coreda "github.com/evstack/ev-node/core/da"
911
storepkg "github.com/evstack/ev-node/pkg/store"
1012
)
@@ -25,11 +27,11 @@ func (m *Manager) DAIncluderLoop(ctx context.Context, errCh chan<- error) {
2527
daIncluded, err := m.IsDAIncluded(ctx, nextHeight)
2628
if err != nil {
2729
// No more blocks to check at this time
28-
m.logger.Debug("no more blocks to check at this time, height: ", nextHeight, "error: ", err)
30+
m.logger.Debug("no more blocks to check at this time", zap.Uint64("height", nextHeight), zap.Error(err))
2931
break
3032
}
3133
if daIncluded {
32-
m.logger.Debug("both header and data are DA-included, advancing height: ", nextHeight)
34+
m.logger.Debug("both header and data are DA-included, advancing height", zap.Uint64("height", nextHeight))
3335
if err := m.SetRollkitHeightToDAHeight(ctx, nextHeight); err != nil {
3436
errCh <- fmt.Errorf("failed to set rollkit height to DA height: %w", err)
3537
return
@@ -54,18 +56,18 @@ func (m *Manager) DAIncluderLoop(ctx context.Context, errCh chan<- error) {
5456
func (m *Manager) incrementDAIncludedHeight(ctx context.Context) error {
5557
currentHeight := m.GetDAIncludedHeight()
5658
newHeight := currentHeight + 1
57-
m.logger.Debug("setting final height: ", newHeight)
59+
m.logger.Debug("setting final height", zap.Uint64("height", newHeight))
5860
err := m.exec.SetFinal(ctx, newHeight)
5961
if err != nil {
60-
m.logger.Error("failed to set final height: ", newHeight, "error: ", err)
62+
m.logger.Error("failed to set final height", zap.Uint64("height", newHeight), zap.Error(err))
6163
return err
6264
}
6365
heightBytes := make([]byte, 8)
6466
binary.LittleEndian.PutUint64(heightBytes, newHeight)
65-
m.logger.Debug("setting DA included height: ", newHeight)
67+
m.logger.Debug("setting DA included height", zap.Uint64("height", newHeight))
6668
err = m.store.SetMetadata(ctx, storepkg.DAIncludedHeightKey, heightBytes)
6769
if err != nil {
68-
m.logger.Error("failed to set DA included height: ", newHeight, "error: ", err)
70+
m.logger.Error("failed to set DA included height", zap.Uint64("height", newHeight), zap.Error(err))
6971
return err
7072
}
7173
if !m.daIncludedHeight.CompareAndSwap(currentHeight, newHeight) {

block/da_includer_test.go

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
"github.com/stretchr/testify/assert"
1212
"github.com/stretchr/testify/mock"
13+
"go.uber.org/zap"
1314

1415
coreda "github.com/evstack/ev-node/core/da"
1516
"github.com/evstack/ev-node/core/sequencer"
@@ -20,24 +21,10 @@ import (
2021
)
2122

2223
// newTestManager creates a Manager with mocked Store and Executor for testing DAIncluder logic.
23-
func newTestManager(t *testing.T) (*Manager, *mocks.MockStore, *mocks.MockExecutor, *MockLogger) {
24+
func newTestManager(t *testing.T) (*Manager, *mocks.MockStore, *mocks.MockExecutor, *zap.Logger) {
2425
store := mocks.NewMockStore(t)
2526
exec := mocks.NewMockExecutor(t)
26-
logger := new(MockLogger)
27-
28-
// Allow logging calls with message string and optional key-value pairs (up to 2 pairs / 4 args for simplicity)
29-
logger.On("Debug", mock.AnythingOfType("string")).Maybe()
30-
logger.On("Debug", mock.AnythingOfType("string"), mock.Anything, mock.Anything).Maybe()
31-
logger.On("Debug", mock.AnythingOfType("string"), mock.Anything, mock.Anything, mock.Anything, mock.Anything).Maybe()
32-
logger.On("Info", mock.AnythingOfType("string")).Maybe()
33-
logger.On("Info", mock.AnythingOfType("string"), mock.Anything, mock.Anything).Maybe()
34-
logger.On("Info", mock.AnythingOfType("string"), mock.Anything, mock.Anything, mock.Anything, mock.Anything).Maybe()
35-
logger.On("Warn", mock.AnythingOfType("string")).Maybe()
36-
logger.On("Warn", mock.AnythingOfType("string"), mock.Anything, mock.Anything).Maybe()
37-
logger.On("Warn", mock.AnythingOfType("string"), mock.Anything, mock.Anything, mock.Anything, mock.Anything).Maybe()
38-
logger.On("Error", mock.AnythingOfType("string")).Maybe()
39-
logger.On("Error", mock.AnythingOfType("string"), mock.Anything, mock.Anything).Maybe()
40-
logger.On("Error", mock.AnythingOfType("string"), mock.Anything, mock.Anything, mock.Anything, mock.Anything).Maybe()
27+
logger := zap.NewNop() // Use no-op logger for tests
4128

4229
// Mock Height to always return a high value so IsDAIncluded works
4330
store.On("Height", mock.Anything).Return(uint64(100), nil).Maybe()
@@ -171,20 +158,17 @@ func TestDAIncluderLoop_StopsWhenDataNotDAIncluded(t *testing.T) {
171158
// if GetBlockData returns an error for the next block height.
172159
func TestDAIncluderLoop_StopsOnGetBlockDataError(t *testing.T) {
173160
t.Parallel()
174-
m, store, _, mockLogger := newTestManager(t)
161+
m, store, _, _ := newTestManager(t)
175162
startDAIncludedHeight := uint64(4)
176163
m.daIncludedHeight.Store(startDAIncludedHeight)
177164

178165
store.On("GetBlockData", mock.Anything, uint64(5)).Return(nil, nil, assert.AnError).Once()
179166

180167
// Expect the debug log for no more blocks to check
181-
mockLogger.ExpectedCalls = nil // Clear any previous expectations for specific checks
168+
182169
// Re-establish general Maybe calls after clearing, then specific Once call
183-
mockLogger.On("Debug", mock.AnythingOfType("string")).Maybe()
184-
mockLogger.On("Debug", mock.AnythingOfType("string"), mock.Anything, mock.Anything).Maybe()
185-
mockLogger.On("Debug", mock.AnythingOfType("string"), mock.Anything, mock.Anything, mock.Anything, mock.Anything).Maybe()
170+
186171
// Add other Maybe calls if Info/Warn/Error might also occur and are not asserted
187-
mockLogger.On("Info", mock.AnythingOfType("string")).Maybe()
188172

189173
ctx, loopCancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
190174
defer loopCancel()
@@ -201,7 +185,7 @@ func TestDAIncluderLoop_StopsOnGetBlockDataError(t *testing.T) {
201185

202186
assert.Equal(t, startDAIncludedHeight, m.GetDAIncludedHeight())
203187
store.AssertExpectations(t)
204-
mockLogger.AssertExpectations(t)
188+
205189
}
206190

207191
// TestIncrementDAIncludedHeight_Success verifies that incrementDAIncludedHeight increments the height
@@ -229,7 +213,7 @@ func TestIncrementDAIncludedHeight_Success(t *testing.T) {
229213
// if SetMetadata fails after SetFinal succeeds.
230214
func TestIncrementDAIncludedHeight_SetMetadataError(t *testing.T) {
231215
t.Parallel()
232-
m, store, exec, mockLogger := newTestManager(t)
216+
m, store, exec, _ := newTestManager(t)
233217
startDAIncludedHeight := uint64(4)
234218
expectedDAIncludedHeight := startDAIncludedHeight + 1
235219
m.daIncludedHeight.Store(startDAIncludedHeight)
@@ -243,14 +227,14 @@ func TestIncrementDAIncludedHeight_SetMetadataError(t *testing.T) {
243227
assert.Error(t, err)
244228
store.AssertExpectations(t)
245229
exec.AssertExpectations(t)
246-
mockLogger.AssertExpectations(t)
230+
247231
}
248232

249233
// TestIncrementDAIncludedHeight_SetFinalError verifies that incrementDAIncludedHeight returns an error
250234
// if SetFinal fails before SetMetadata, and logs the error.
251235
func TestIncrementDAIncludedHeight_SetFinalError(t *testing.T) {
252236
t.Parallel()
253-
m, store, exec, mockLogger := newTestManager(t)
237+
m, store, exec, _ := newTestManager(t)
254238
startDAIncludedHeight := uint64(4)
255239
expectedDAIncludedHeight := startDAIncludedHeight + 1
256240
m.daIncludedHeight.Store(startDAIncludedHeight)
@@ -263,7 +247,7 @@ func TestIncrementDAIncludedHeight_SetFinalError(t *testing.T) {
263247
assert.Error(t, err)
264248
exec.AssertExpectations(t)
265249
store.AssertExpectations(t)
266-
mockLogger.AssertExpectations(t)
250+
267251
}
268252

269253
// TestDAIncluderLoop_MultipleConsecutiveHeightsDAIncluded verifies that DAIncluderLoop advances the height

block/da_speed_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import (
1010

1111
goheaderstore "github.com/celestiaorg/go-header/store"
1212
ds "github.com/ipfs/go-datastore"
13-
logging "github.com/ipfs/go-log/v2"
1413
"github.com/libp2p/go-libp2p/core/crypto"
1514
"github.com/stretchr/testify/assert"
1615
"github.com/stretchr/testify/mock"
1716
"github.com/stretchr/testify/require"
17+
"go.uber.org/zap"
1818
"google.golang.org/protobuf/proto"
1919

2020
coreda "github.com/evstack/ev-node/core/da"
@@ -92,8 +92,7 @@ func TestDASpeed(t *testing.T) {
9292
func setupManagerForTest(t *testing.T, initialDAHeight uint64) (*Manager, *rollmocks.MockDA) {
9393
mockDAClient := rollmocks.NewMockDA(t)
9494
mockStore := rollmocks.NewMockStore(t)
95-
logger := logging.Logger("test")
96-
_ = logging.SetLogLevel("test", "FATAL")
95+
logger := zap.NewNop()
9796

9897
headerStore, _ := goheaderstore.NewStore[*types.SignedHeader](ds.NewMapDatastore())
9998
dataStore, _ := goheaderstore.NewStore[*types.Data](ds.NewMapDatastore())

block/lazy_aggregation_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import (
77
"testing"
88
"time"
99

10-
logging "github.com/ipfs/go-log/v2"
1110
"github.com/stretchr/testify/assert"
1211
"github.com/stretchr/testify/require"
12+
"go.uber.org/zap"
1313

1414
"github.com/evstack/ev-node/pkg/config"
1515
)
@@ -54,7 +54,7 @@ func setupTestManager(t *testing.T, blockTime, lazyTime time.Duration) (*Manager
5454
pubMock := &mockPublishBlock{
5555
calls: make(chan struct{}, 10), // Buffer to avoid blocking in tests
5656
}
57-
logger := logging.Logger("test")
57+
logger := zap.NewNop() // Use a no-op logger for tests
5858
m := &Manager{
5959
logger: logger,
6060
config: config.Config{

0 commit comments

Comments
 (0)