Skip to content

Commit 89fd5b3

Browse files
committed
fix: replacer infof with infow in logs and fix event types after rebase
1 parent dd3b7f0 commit 89fd5b3

2 files changed

Lines changed: 32 additions & 32 deletions

File tree

pkg/timelock/worker_solana.go

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func (w *WorkerSolana) Listen(ctx context.Context) error {
120120
//schedulingDone = w.scheduler.runScheduler(ctxwc)
121121

122122
//// Retrieve logs asynchronously.
123-
pollDone, txCh := w.pollNewSignatures(ctxwc)
123+
pollDone, txCh := w.pollNewTransactions(ctxwc)
124124

125125
// Start processing transactions
126126
procDone := w.processTransactions(ctxwc, txCh)
@@ -148,26 +148,26 @@ func (w *WorkerSolana) Listen(ctx context.Context) error {
148148
return nil
149149
}
150150

151-
// pollNewSignatures continuously fetches only new signatures touching your program,
152-
// then loads each confirmed transaction so you can parse its LogMessages.
153-
func (w *WorkerSolana) pollNewSignatures(
151+
// pollNewTransactions continuously fetches only new txs touching the program,
152+
// then loads each confirmed transaction so it can parse its LogMessages.
153+
func (w *WorkerSolana) pollNewTransactions(
154154
ctx context.Context,
155155
) (<-chan struct{}, <-chan *rpc.TransactionWithMeta) {
156156
done := make(chan struct{})
157157
txCh := make(chan *rpc.TransactionWithMeta, w.pollSize)
158158

159159
go func() {
160160
defer func() {
161-
w.logger.Info("pollNewSignatures exiting")
161+
w.logger.Info("pollNewTransactions exiting")
162162
close(done)
163163
close(txCh)
164164
}()
165165

166-
w.logger.Infof(
167-
"starting pollNewSignatures: program=%s pollPeriod=%ds pollSize=%d",
168-
w.timelockProgramKey,
169-
w.pollPeriod,
170-
w.pollSize,
166+
w.logger.Infow(
167+
"starting pollNewTransactions",
168+
"program", w.timelockProgramKey,
169+
"pollPeriod", w.pollPeriod,
170+
"pollSize", w.pollSize,
171171
)
172172

173173
ticker := time.NewTicker(time.Duration(w.pollPeriod) * time.Second)
@@ -180,7 +180,7 @@ func (w *WorkerSolana) pollNewSignatures(
180180
return
181181

182182
case <-ticker.C:
183-
w.logger.Infof("new pollNewSignatures tick: %s", time.Now().Format(time.RFC3339))
183+
w.logger.Infow("new pollNewTransactions", "tick", time.Now().Format(time.RFC3339))
184184

185185
var until solana.Signature
186186
if w.lastSignature != nil {
@@ -210,7 +210,7 @@ func (w *WorkerSolana) pollNewSignatures(
210210
continue
211211
}
212212

213-
w.logger.Infof("found %d new signatures", len(sigs))
213+
w.logger.Infow("found new signatures", "num signatures", len(sigs))
214214

215215
// Build JSON-RPC batch requests (oldest→newest)
216216
requests := make(jsonrpc.RPCRequests, len(sigs))
@@ -303,7 +303,7 @@ func (w *WorkerSolana) handleTx(ctx context.Context, tx *rpc.TransactionWithMeta
303303
return nil
304304
}
305305

306-
timelockEvent, err := ParseTimelockEvents(w.logger, tx)
306+
timelockEvent, err := ParseTimelockEvents(tx)
307307
if err != nil {
308308
return fmt.Errorf("failed to parse timelock events: %w", err)
309309
}
@@ -337,16 +337,16 @@ func (w *WorkerSolana) handleTx(ctx context.Context, tx *rpc.TransactionWithMeta
337337
}
338338

339339
// handleEventCancelled checks if the operation is cancelled and deletes it from the scheduler if it is.
340-
func (w *WorkerSolana) handleEventCancelled(_ context.Context, event Cancelled) {
340+
func (w *WorkerSolana) handleEventCancelled(_ context.Context, event SolanaTimelockCallCancelledEvent) {
341341
w.logger.With(operationID, fmt.Sprintf("%x", event.ID)).
342-
Infof("%s received, cancelling operation", eventCancelled)
342+
Infow("event received, cancelling operation", "event type", eventCancelled)
343343

344344
// TODO: add scheduler call once scheduler is implemented
345345
//w.scheduler.delFromScheduler(event.ID)
346346
}
347347

348348
// handleEventExecuted checks if the operation is done and deletes it from the scheduler if it is.
349-
func (w *WorkerSolana) handleEventExecuted(ctx context.Context, event CallExecuted) error {
349+
func (w *WorkerSolana) handleEventExecuted(ctx context.Context, event SolanaTimelockCallExecutedEvent) error {
350350
logger := w.logger.With(eventIndex, fmt.Sprintf("%x", event.Index)).
351351
With(eventTarget, event.Target.String()).
352352
With(operationID, fmt.Sprintf("%x", event.ID))
@@ -356,7 +356,7 @@ func (w *WorkerSolana) handleEventExecuted(ctx context.Context, event CallExecut
356356
return fmt.Errorf("timelock.isOperationDone call failed (operation id: %x): %w", event.ID, err)
357357
}
358358
if isDone {
359-
logger.Infof("%s received, deleting operation from scheduler", eventCallExecuted)
359+
logger.Infow("event received, deleting operation from scheduler", "event type ", eventCallExecuted)
360360
// TODO: add scheduler call once scheduler is implemented
361361
//w.scheduler.delFromScheduler(event.ID)
362362
} else {
@@ -367,7 +367,7 @@ func (w *WorkerSolana) handleEventExecuted(ctx context.Context, event CallExecut
367367
}
368368

369369
// handleEventScheduled checks if the operation is already scheduled and adds it to the scheduler if it is not.
370-
func (w *WorkerSolana) handleEventScheduled(ctx context.Context, event CallScheduled) error {
370+
func (w *WorkerSolana) handleEventScheduled(ctx context.Context, event SolanaTimelockCallScheduledEvent) error {
371371
logger := w.logger.With(eventIndex, fmt.Sprintf("%x", event.Index)).
372372
With(eventTarget, event.Target.String()).
373373
With(operationID, fmt.Sprintf("%x", event.ID))
@@ -383,7 +383,7 @@ func (w *WorkerSolana) handleEventScheduled(ctx context.Context, event CallSched
383383
}
384384

385385
if isOp {
386-
logger.Infof("%s received", eventCallScheduled)
386+
logger.Infow("event received", "event type", eventCallScheduled)
387387
// TODO: add scheduler call once scheduler is implemented
388388
// w.scheduler.addToScheduler(cs)
389389
} else {
@@ -397,12 +397,12 @@ func (w *WorkerSolana) handleEventScheduled(ctx context.Context, event CallSched
397397
// startLog prints the timelock-worker configuration.
398398
func (w *WorkerSolana) startLog() {
399399
w.logger.Info("timelock-worker started [solana]")
400-
w.logger.Infof("\tTimelock program addresses: %v", w.timelockProgramKey.String())
400+
w.logger.Infow("\tTimelock program addresses: %v", w.timelockProgramKey.String())
401401

402402
wallet := w.privateKey.PublicKey()
403403

404-
w.logger.Infof("\tSolana account address: %v", wallet)
405-
w.logger.Infof("\tPoll Period: %v", time.Duration(w.pollPeriod*int64(time.Second)).String())
406-
w.logger.Infof("\tEvent Listener Poll Period: %v", time.Duration(w.listenerPollPeriod*int64(time.Second)).String())
407-
w.logger.Infof("\tEvent Listener Poll #Logs: %v", w.pollSize)
404+
w.logger.Infow("\tSolana account address: %v", wallet)
405+
w.logger.Infow("\tPoll Period: %v", time.Duration(w.pollPeriod*int64(time.Second)).String())
406+
w.logger.Infow("\tEvent Listener Poll Period: %v", time.Duration(w.listenerPollPeriod*int64(time.Second)).String())
407+
w.logger.Infow("\tEvent Listener Poll #Logs: %v", w.pollSize)
408408
}

pkg/timelock/worker_solana_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ func TestPollNewSignatures(t *testing.T) {
158158
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
159159
defer cancel()
160160

161-
done, ch := w.pollNewSignatures(ctx)
161+
done, ch := w.pollNewTransactions(ctx)
162162
got := 0
163163

164164
Loop:
@@ -199,7 +199,7 @@ func TestHandleEventCancelled(t *testing.T) {
199199
logger: testLogger,
200200
}
201201

202-
worker.handleEventCancelled(context.Background(), Cancelled{ID: id})
202+
worker.handleEventCancelled(context.Background(), SolanaTimelockCallCancelledEvent{ID: id})
203203
// TODO: once scheduler is added we can assert expectation from a mock scheduler here.
204204
}
205205

@@ -213,7 +213,7 @@ func TestHandleEventExecuted_Done(t *testing.T) {
213213
inspector: mockInsp,
214214
logger: testLogger,
215215
}
216-
event := CallExecuted{ID: id, Target: solana.PublicKey{}}
216+
event := SolanaTimelockCallExecutedEvent{ID: id, Target: solana.PublicKey{}}
217217
err := worker.handleEventExecuted(context.Background(), event)
218218
require.NoError(t, err)
219219
mockInsp.AssertExpectations(t)
@@ -231,7 +231,7 @@ func TestHandleEventScheduled_IsOp(t *testing.T) {
231231
inspector: mockInsp,
232232
logger: testLogger,
233233
}
234-
event := CallScheduled{ID: id, Target: solana.PublicKey{}}
234+
event := SolanaTimelockCallScheduledEvent{ID: id, Target: solana.PublicKey{}}
235235
err := worker.handleEventScheduled(context.Background(), event)
236236
require.NoError(t, err)
237237
mockInsp.AssertExpectations(t)
@@ -247,7 +247,7 @@ func TestHandleEventScheduled_OperationDone(t *testing.T) {
247247
inspector: mockInsp,
248248
logger: testLogger,
249249
}
250-
event := CallScheduled{ID: id, Target: solana.PublicKey{}}
250+
event := SolanaTimelockCallScheduledEvent{ID: id, Target: solana.PublicKey{}}
251251
err := worker.handleEventScheduled(context.Background(), event)
252252
require.NoError(t, err)
253253
mockInsp.AssertExpectations(t)
@@ -263,7 +263,7 @@ func TestHandleEventExecuted_NotDone(t *testing.T) {
263263
inspector: mockInsp,
264264
logger: testLogger,
265265
}
266-
event := CallExecuted{ID: id, Target: solana.PublicKey{}}
266+
event := SolanaTimelockCallExecutedEvent{ID: id, Target: solana.PublicKey{}}
267267
err := worker.handleEventExecuted(context.Background(), event)
268268
require.NoError(t, err)
269269
mockInsp.AssertExpectations(t)
@@ -281,7 +281,7 @@ func TestHandleEventScheduled_IsOp_Error(t *testing.T) {
281281
inspector: mockInsp,
282282
logger: testLogger,
283283
}
284-
event := CallScheduled{ID: id, Target: solana.PublicKey{}}
284+
event := SolanaTimelockCallScheduledEvent{ID: id, Target: solana.PublicKey{}}
285285
require.ErrorContains(t, worker.handleEventScheduled(context.Background(), event), "timelock.isOperation call failed")
286286
}
287287

@@ -295,7 +295,7 @@ func TestHandleEventExecuted_Error(t *testing.T) {
295295
inspector: mockInsp,
296296
logger: testLogger,
297297
}
298-
event := CallExecuted{ID: id, Target: solana.PublicKey{}}
298+
event := SolanaTimelockCallExecutedEvent{ID: id, Target: solana.PublicKey{}}
299299
require.ErrorContains(t, worker.handleEventExecuted(context.Background(), event), "timelock.isOperationDone call failed")
300300
// TODO: once scheduler is added we can assert expectation from a mock scheduler here.
301301
}

0 commit comments

Comments
 (0)