Skip to content

Commit 23c2054

Browse files
authored
fix(p2p): ensure validation for local submission (#350)
Previously, locally published headers went only through verification, skipping validation.
1 parent ac2f078 commit 23c2054

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

p2p/subscriber.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -198,19 +198,20 @@ func (s *Subscriber[H]) verifyMessage(
198198
}
199199
}
200200

201-
func (s *Subscriber[H]) extractHeader(msg *pubsub.Message) (H, error) {
201+
func (s *Subscriber[H]) extractHeader(msg *pubsub.Message) (hdr H, err error) {
202202
if msg.ValidatorData != nil {
203-
hdr, ok := msg.ValidatorData.(H)
203+
var ok bool
204+
hdr, ok = msg.ValidatorData.(H)
204205
if !ok {
205206
panic(fmt.Sprintf("msg ValidatorData is of type %T", msg.ValidatorData))
206207
}
207-
return hdr, nil
208+
} else {
209+
hdr = header.New[H]()
210+
if err := hdr.UnmarshalBinary(msg.Data); err != nil {
211+
return hdr, err
212+
}
208213
}
209214

210-
hdr := header.New[H]()
211-
if err := hdr.UnmarshalBinary(msg.Data); err != nil {
212-
return hdr, err
213-
}
214215
if err := hdr.Validate(); err != nil {
215216
return hdr, err
216217
}

0 commit comments

Comments
 (0)