Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check the validity of ECChain first in chain exchange #837

Merged
merged 1 commit into from
Jan 22, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions chainexchange/pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,21 @@
log.Debugw("failed to decode message", "from", msg.GetFrom(), "err", err)
return pubsub.ValidationReject
}
if cmsg.Chain.IsZero() {
// No peer should broadcast a zero-length chain.
return pubsub.ValidationReject
}

Check warning on line 215 in chainexchange/pubsub.go

View check run for this annotation

Codecov / codecov/patch

chainexchange/pubsub.go#L213-L215

Added lines #L213 - L215 were not covered by tests
if err := cmsg.Chain.Validate(); err != nil {
// Invalid chain.
log.Debugw("Invalid chain", "from", msg.GetFrom(), "err", err)
return pubsub.ValidationReject
}

Check warning on line 220 in chainexchange/pubsub.go

View check run for this annotation

Codecov / codecov/patch

chainexchange/pubsub.go#L217-L220

Added lines #L217 - L220 were not covered by tests
switch current := p.progress(); {
case
cmsg.Instance < current.ID,
cmsg.Instance > current.ID+p.maxInstanceLookahead:
// Too far ahead or too far behind.
return pubsub.ValidationIgnore
case cmsg.Chain.IsZero():
// No peer should broadcast a zero-length chain.
return pubsub.ValidationReject
}
// TODO: wire in the current base chain from an on-going instance to further
// tighten up validation.
Expand Down
Loading