diff --git a/pkg/pipe/engine.go b/pkg/pipe/engine.go index 13fd7a0..92cf9a8 100644 --- a/pkg/pipe/engine.go +++ b/pkg/pipe/engine.go @@ -232,16 +232,11 @@ func updateWalks(ctx context.Context, db redb.RedisDB, cache *walks.CachedWalker return nil } -const ( - followPrefix = "p" - maxFollows = 50000 -) - // Parse unique pubkeys (excluding author) from the "p" tags in the event. func ParsePubkeys(event *nostr.Event) []string { - pubkeys := make([]string, 0, min(len(event.Tags), maxFollows)) + pubkeys := make([]string, 0, min(len(event.Tags), maxTags)) for _, tag := range event.Tags { - if len(pubkeys) > maxFollows { + if len(pubkeys) > maxTags { // stop processing, list is too big break } @@ -251,7 +246,7 @@ func ParsePubkeys(event *nostr.Event) []string { } prefix, pubkey := tag[0], tag[1] - if prefix != followPrefix { + if prefix != "p" { continue } diff --git a/pkg/pipe/intake.go b/pkg/pipe/intake.go index a5ada29..5c27429 100644 --- a/pkg/pipe/intake.go +++ b/pkg/pipe/intake.go @@ -2,6 +2,7 @@ package pipe import ( "context" + "errors" "fmt" "log" "slices" @@ -324,3 +325,20 @@ func shutdown(pool *nostr.SimplePool) { return true }) } + +var ( + ErrEventTooBig = errors.New("event is too big") + maxTags = 20_000 + maxContent = 50_000 +) + +// EventTooBig is a [nastro.EventPolicy] that errs if the event is too big. +func EventTooBig(e *nostr.Event) error { + if len(e.Tags) > maxTags { + return fmt.Errorf("%w: event with ID %s has too many tags: %d", ErrEventTooBig, e.ID, len(e.Tags)) + } + if len(e.Content) > maxContent { + return fmt.Errorf("%w: event with ID %s has too much content: %d", ErrEventTooBig, e.ID, len(e.Content)) + } + return nil +}