[#1437] ir: Fix contextcheck linters

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2024-10-21 12:21:01 +03:00
parent 16598553d9
commit 6921a89061
Signed by: dstepanov-yadro
GPG key ID: 237AF1A763293BC0
27 changed files with 165 additions and 157 deletions

View file

@ -1,11 +1,13 @@
package event
import (
"context"
"github.com/nspcc-dev/neo-go/pkg/core/block"
)
// Handler is an Event processing function.
type Handler func(Event)
type Handler func(context.Context, Event)
// BlockHandler is a chain block processing function.
type BlockHandler func(*block.Block)

View file

@ -280,7 +280,7 @@ loop:
continue loop
}
l.handleNotaryEvent(notaryEvent)
l.handleNotaryEvent(ctx, notaryEvent)
case b, ok := <-chs.BlockCh:
if !ok {
l.log.Warn(ctx, logs.EventStopEventListenerByBlockChannel)
@ -307,11 +307,11 @@ func (l *listener) handleBlockEvent(b *block.Block) {
}
}
func (l *listener) handleNotaryEvent(notaryEvent *result.NotaryRequestEvent) {
func (l *listener) handleNotaryEvent(ctx context.Context, notaryEvent *result.NotaryRequestEvent) {
if err := l.pool.Submit(func() {
l.parseAndHandleNotary(notaryEvent)
l.parseAndHandleNotary(ctx, notaryEvent)
}); err != nil {
l.log.Warn(context.Background(), logs.EventListenerWorkerPoolDrained,
l.log.Warn(ctx, logs.EventListenerWorkerPoolDrained,
zap.Int("capacity", l.pool.Cap()))
}
}
@ -376,11 +376,11 @@ func (l *listener) parseAndHandleNotification(ctx context.Context, notifyEvent *
}
for _, handler := range handlers {
handler(event)
handler(ctx, event)
}
}
func (l *listener) parseAndHandleNotary(nr *result.NotaryRequestEvent) {
func (l *listener) parseAndHandleNotary(ctx context.Context, nr *result.NotaryRequestEvent) {
// prepare the notary event
notaryEvent, err := l.notaryEventsPreparator.Prepare(nr.NotaryRequest)
if err != nil {
@ -388,13 +388,13 @@ func (l *listener) parseAndHandleNotary(nr *result.NotaryRequestEvent) {
switch {
case errors.Is(err, ErrTXAlreadyHandled):
case errors.As(err, &expErr):
l.log.Warn(context.Background(), logs.EventSkipExpiredMainTXNotaryEvent,
l.log.Warn(ctx, logs.EventSkipExpiredMainTXNotaryEvent,
zap.String("error", err.Error()),
zap.Uint32("current_block_height", expErr.CurrentBlockHeight),
zap.Uint32("fallback_tx_not_valid_before_height", expErr.FallbackTXNotValidBeforeHeight),
)
default:
l.log.Warn(context.Background(), logs.EventCouldNotPrepareAndValidateNotaryEvent,
l.log.Warn(ctx, logs.EventCouldNotPrepareAndValidateNotaryEvent,
zap.String("error", err.Error()),
)
}
@ -418,7 +418,7 @@ func (l *listener) parseAndHandleNotary(nr *result.NotaryRequestEvent) {
l.mtx.RUnlock()
if !ok {
log.Debug(context.Background(), logs.EventNotaryParserNotSet)
log.Debug(ctx, logs.EventNotaryParserNotSet)
return
}
@ -426,7 +426,7 @@ func (l *listener) parseAndHandleNotary(nr *result.NotaryRequestEvent) {
// parse the notary event
event, err := parser(notaryEvent)
if err != nil {
log.Warn(context.Background(), logs.EventCouldNotParseNotaryEvent,
log.Warn(ctx, logs.EventCouldNotParseNotaryEvent,
zap.String("error", err.Error()),
)
@ -439,14 +439,14 @@ func (l *listener) parseAndHandleNotary(nr *result.NotaryRequestEvent) {
l.mtx.RUnlock()
if !ok {
log.Info(context.Background(), logs.EventNotaryHandlersForParsedNotificationEventWereNotRegistered,
log.Info(ctx, logs.EventNotaryHandlersForParsedNotificationEventWereNotRegistered,
zap.Any("event", event),
)
return
}
handler(event)
handler(ctx, event)
}
// SetNotificationParser sets the parser of particular contract event.

View file

@ -59,7 +59,7 @@ func TestEventHandling(t *testing.T) {
handledNotifications := make([]Event, 0)
l.RegisterNotificationHandler(NotificationHandlerInfo{
scriptHashWithType: key,
h: func(e Event) {
h: func(_ context.Context, e Event) {
handledNotifications = append(handledNotifications, e)
notificationHandled <- true
},

View file

@ -85,12 +85,12 @@ func (s typeValue) GetType() Type {
// WorkerPoolHandler sets closure over worker pool w with passed handler h.
func WorkerPoolHandler(w util2.WorkerPool, h Handler, log *logger.Logger) Handler {
return func(e Event) {
return func(ctx context.Context, e Event) {
err := w.Submit(func() {
h(e)
h(ctx, e)
})
if err != nil {
log.Warn(context.Background(), logs.EventCouldNotSubmitHandlerToWorkerPool,
log.Warn(ctx, logs.EventCouldNotSubmitHandlerToWorkerPool,
zap.String("error", err.Error()),
)
}