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

network: Ignore invalid tags #4517

Merged
merged 24 commits into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
0346b11
don't queue messages with unrecognized tags
cce Aug 31, 2022
0b0f37c
Merge remote-tracking branch 'upstream/master' into ignore-invalid-tags
cce Sep 8, 2022
0e2fe4c
update and add debug logging for bad tags
cce Sep 8, 2022
1b5595b
switch to setting telemetry field
cce Sep 8, 2022
9df1d0c
skip dropping message
cce Sep 8, 2022
06f5c56
add allowCustomTags
cce Sep 8, 2022
bfb3ca1
Merge remote-tracking branch 'upstream/master' into ignore-invalid-tags
cce Nov 9, 2022
ce2af33
turn OutOfProtocol into a counter
cce Nov 9, 2022
5e04cb8
Merge remote-tracking branch 'upstream/master' into ignore-invalid-tags
cce Jan 10, 2023
b7719f7
merge count test
cce Jan 10, 2023
0e702e4
update metric name
cce Jan 10, 2023
18ace9d
update OutOfProtocol to Unknown
cce Jan 10, 2023
ccd5f37
remove drop check behind dedupSafeTag
cce Jan 26, 2023
0c6f169
add test for wsPeer.readLoop to make sure the switch statement checks…
cce Jan 26, 2023
936e568
fix lint
cce Jan 26, 2023
5f0cd15
add protocol.TagList completeness check test
cce Jan 27, 2023
c91c1a4
remove UniCatchupReqTag
cce Jan 27, 2023
ceba110
add license to tags_test.go
cce Jan 27, 2023
12dbc02
add partitiontest for linter
cce Jan 27, 2023
a7dd7a7
add strconv.Unquote to TestTagList
cce Jan 27, 2023
0346817
add TestWebsocketNetworkBasicInvalidTags
cce Jan 27, 2023
e390c9a
update TestTagList
cce Jan 27, 2023
4fbc0f6
add TestHashIDPrefix and a few more comments
cce Jan 28, 2023
4a780fd
Update network/wsNetwork_test.go
algorandskiy Feb 1, 2023
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
9 changes: 6 additions & 3 deletions agreement/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ type multicastParams struct {
exclude nodeID
}

// UnknownMsgTag ensures the testingNetwork implementation below will drop a message.
const UnknownMsgTag protocol.Tag = "??"

func (n *testingNetwork) multicast(tag protocol.Tag, data []byte, source nodeID, exclude nodeID) {
// fmt.Println("mc", source, "x", exclude)
n.mu.Lock()
Expand Down Expand Up @@ -262,7 +265,7 @@ func (n *testingNetwork) multicast(tag protocol.Tag, data []byte, source nodeID,
msgChans = n.bundleMessages
case protocol.ProposalPayloadTag:
msgChans = n.payloadMessages
case protocol.UnknownMsgTag:
case UnknownMsgTag:
// We use this intentionally - just drop it
return
default:
Expand Down Expand Up @@ -1681,7 +1684,7 @@ func TestAgreementRecoverGlobalStartingValueBadProposal(t *testing.T) {
// intercept all proposals for the next period; replace with unexpected
baseNetwork.intercept(func(params multicastParams) multicastParams {
if params.tag == protocol.ProposalPayloadTag {
params.tag = protocol.UnknownMsgTag
params.tag = UnknownMsgTag
}
return params
})
Expand Down Expand Up @@ -2280,7 +2283,7 @@ func TestAgreementCertificateDoesNotStallSingleRelay(t *testing.T) {
return params
}
}
params.tag = protocol.UnknownMsgTag
params.tag = UnknownMsgTag
}

return params
Expand Down
14 changes: 14 additions & 0 deletions network/wsPeer.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,20 @@ func (wp *wsPeer) readLoop() {
// network maintenance message handled immediately instead of handing off to general handlers
wp.handleFilterMessage(msg)
continue
// the remaining valid tags: no special handling here
case protocol.AgreementVoteTag:
cce marked this conversation as resolved.
Show resolved Hide resolved
case protocol.NetPrioResponseTag:
case protocol.PingTag:
case protocol.PingReplyTag:
case protocol.ProposalPayloadTag:
case protocol.StateProofSigTag:
case protocol.TxnTag:
case protocol.UniCatchupReqTag:
case protocol.UniEnsBlockReqTag:
case protocol.VoteBundleTag:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need that exhaustive switch statement linter

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that would be cool, but these tags are not defined in an enum... idk if there is something to lint switching on const Tag variable assignments

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let me see if I can put a test together

Copy link
Contributor Author

@cce cce Jan 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a test for this, TestPeerReadLoopSwitchAllTags

default: // unrecognized tag
wp.net.log.Debugf("peer reported unrecognized tag %x: %s", tag, wp.conn.RemoteAddr().String())
continue // drop message, skip adding it to the queue
}
if len(msg.Data) > 0 && wp.incomingMsgFilter != nil && dedupSafeTag(msg.Tag) {
if wp.incomingMsgFilter.CheckIncomingMessage(msg.Tag, msg.Data, true, true) {
Expand Down
2 changes: 0 additions & 2 deletions protocol/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ type Tag string
// are encoded using a comma separator (see network/msgOfInterest.go).
// The tags must be 2 bytes long.
const (
UnknownMsgTag Tag = "??"
AgreementVoteTag Tag = "AV"
MsgOfInterestTag Tag = "MI"
MsgDigestSkipTag Tag = "MS"
Expand All @@ -46,7 +45,6 @@ const (
// TagList is a list of all currently used protocol tags.
// TODO: generate this and/or have a test that it is complete.
var TagList = []Tag{
UnknownMsgTag,
AgreementVoteTag,
MsgOfInterestTag,
MsgDigestSkipTag,
Expand Down