Add expired tx logging #484

Merged
fyrchik merged 1 commit from dstepanov-yadro/frostfs-node:fix/notary_prep_logger into master 2023-07-03 08:03:26 +00:00
3 changed files with 19 additions and 6 deletions

View file

@ -365,11 +365,14 @@ func (l *listener) parseAndHandleNotary(nr *result.NotaryRequestEvent) {
// prepare the notary event
notaryEvent, err := l.notaryEventsPreparator.Prepare(nr.NotaryRequest)
if err != nil {
var expErr *ExpiredTXError
switch {
case errors.Is(err, ErrTXAlreadyHandled):
case errors.Is(err, ErrMainTXExpired):
case errors.As(err, &expErr):
l.log.Warn(logs.EventSkipExpiredMainTXNotaryEvent,

I believe initial reasons for using String were to avoid having stacktrace for not-so-rare warnings.
Anyway, seems unrelated to the commit, move?

I believe initial reasons for using `String` were to avoid having stacktrace for not-so-rare warnings. Anyway, seems unrelated to the commit, move?

ok, fixed

ok, fixed
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(logs.EventCouldNotPrepareAndValidateNotaryEvent,

View file

@ -39,11 +39,18 @@ var (
// ErrTXAlreadyHandled is returned if received TX has already been signed.
ErrTXAlreadyHandled = errors.New("received main tx has already been handled")
// ErrMainTXExpired is returned if received fallback TX is already valid.
ErrMainTXExpired = errors.New("received main tx has expired")
)
// ExpiredTXError is returned if received fallback TX is already valid.
type ExpiredTXError struct {
CurrentBlockHeight uint32
FallbackTXNotValidBeforeHeight uint32
}
func (e *ExpiredTXError) Error() string {
return "received main tx has expired"
}
// BlockCounter must return block count of the network
// from which notary requests are received.
type BlockCounter interface {
@ -308,7 +315,10 @@ func (p Preparator) validateExpiration(fbTX *transaction.Transaction) error {
}
if currBlock >= nvb.Height {
return ErrMainTXExpired
return &ExpiredTXError{
CurrentBlockHeight: currBlock,
FallbackTXNotValidBeforeHeight: nvb.Height,
}

We log sth here and in the parseAndHandleNotary. Why not just use fmt.Errorf with these heights?

We log sth here and in the `parseAndHandleNotary`. Why not just use `fmt.Errorf` with these heights?

fixed

fixed
}
return nil

View file

@ -331,7 +331,7 @@ func TestPrepare_IncorrectNR(t *testing.T) {
{},
},
},
expErr: ErrMainTXExpired,
expErr: &ExpiredTXError{},
},
{
name: "incorrect invoker TX Alphabet witness",