[wip] penalize peer for invalid rlp (#3232)

* save

* log

* save
This commit is contained in:
Alex Sharov 2022-01-13 21:45:23 +07:00 committed by GitHub
parent b22e0e4628
commit d8aa5d2d86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 4 deletions

View File

@ -306,8 +306,15 @@ func RecvMessage(
}
if err = handleInboundMessage(ctx, req, sentry); err != nil {
if rlp.IsDecodeError(err) {
log.Debug("[RecvMessage] Handling incoming message", "error", err)
if rlp.IsInvalidRLPError(err) {
log.Debug("[RecvMessage] Kick peer for invalid RLP", "error", err)
outreq := proto_sentry.PenalizePeerRequest{
PeerId: req.PeerId,
Penalty: proto_sentry.PenaltyKind_Kick, // TODO: Extend penalty kinds
}
if _, err1 := sentry.PenalizePeer(ctx, &outreq, &grpc.EmptyCallOption{}); err1 != nil {
log.Error("Could not send penalty", "err", err1)
}
} else {
log.Warn("[RecvMessage] Handling incoming message", "error", err)
}

View File

@ -60,7 +60,7 @@ var (
}
)
func IsDecodeError(err error) bool {
func IsInvalidRLPError(err error) bool {
return errors.Is(err, ErrExpectedString) ||
errors.Is(err, ErrExpectedList) ||
errors.Is(err, ErrCanonInt) ||
@ -70,7 +70,17 @@ func IsDecodeError(err error) bool {
errors.Is(err, ErrValueTooLarge) ||
errors.Is(err, ErrMoreThanOneValue) ||
errors.Is(err, ErrWrongTxTypePrefix) ||
errors.Is(err, ErrUnknownTxTypePrefix)
errors.Is(err, ErrUnknownTxTypePrefix) ||
// internal errors
errors.Is(err, errNotInList) ||
errors.Is(err, errNotAtEOL) ||
errors.Is(err, errUintOverflow) ||
// stream errors
strings.Contains(err.Error(), "rlp: input list has too many elements") ||
strings.Contains(err.Error(), "rlp: expected input string or byte") ||
strings.Contains(err.Error(), "rlp: expected input list") ||
strings.Contains(err.Error(), "rlp: non-canonical size information") ||
strings.Contains(err.Error(), "rlp: non-canonical integer (leading zero bytes)")
}
// Decoder is implemented by types that require custom RLP decoding rules or need to decode