@@ -4773,3 +4773,81 @@ func TestPeerComparisonInBroadcast(t *testing.T) {
47734773 require .Equal (t , 1 , len (testPeer .sendBufferBulk ))
47744774 require .Equal (t , 0 , len (exceptPeer .sendBufferBulk ))
47754775}
4776+
4777+ func TestMaybeSendMessagesOfInterestLegacyPeer (t * testing.T ) {
4778+ t .Parallel ()
4779+
4780+ wn := & WebsocketNetwork {
4781+ log : logging .TestingLog (t ),
4782+ }
4783+ wn .messagesOfInterestGeneration .Store (1 )
4784+ wn .messagesOfInterest = map [protocol.Tag ]bool {
4785+ protocol .AgreementVoteTag : true ,
4786+ protocol .VotePackedTag : true ,
4787+ }
4788+ wn .messagesOfInterestEnc = marshallMessageOfInterestMap (wn .messagesOfInterest )
4789+
4790+ makePeer := func (features peerFeatureFlag ) (* wsPeer , chan sendMessage ) {
4791+ ch := make (chan sendMessage , 1 )
4792+ return & wsPeer {
4793+ log : logging .TestingLog (t ),
4794+ features : features ,
4795+ sendBufferHighPrio : ch ,
4796+ sendBufferBulk : make (chan sendMessage , 1 ),
4797+ closing : make (chan struct {}),
4798+ netCtx : context .Background (),
4799+ }, ch
4800+ }
4801+
4802+ t .Run ("drops VP for peers without stateful support" , func (t * testing.T ) {
4803+ peer , ch := makePeer (pfCompressedProposal | pfCompressedVoteVpack )
4804+
4805+ wn .maybeSendMessagesOfInterest (peer , nil )
4806+
4807+ select {
4808+ case msg := <- ch :
4809+ require .Len (t , msg .data , len (protocol .MsgOfInterestTag )+ len (msg .data [2 :]))
4810+ require .Equal (t , protocol .MsgOfInterestTag , protocol .Tag (msg .data [:2 ]))
4811+
4812+ topics , err := UnmarshallTopics (msg .data [2 :])
4813+ require .NoError (t , err )
4814+
4815+ tags , ok := topics .GetValue ("tags" )
4816+ require .True (t , ok )
4817+
4818+ for _ , tag := range strings .Split (string (tags ), "," ) {
4819+ require .NotEqual (t , string (protocol .VotePackedTag ), tag )
4820+ }
4821+ default :
4822+ t .Fatal ("expected MOI message for legacy peer" )
4823+ }
4824+ })
4825+
4826+ t .Run ("retains VP for peers with stateful support" , func (t * testing.T ) {
4827+ peer , ch := makePeer (pfCompressedProposal | pfCompressedVoteVpack | pfCompressedVoteVpackStateful256 )
4828+
4829+ wn .maybeSendMessagesOfInterest (peer , nil )
4830+
4831+ select {
4832+ case msg := <- ch :
4833+ require .Equal (t , protocol .MsgOfInterestTag , protocol .Tag (msg .data [:2 ]))
4834+
4835+ topics , err := UnmarshallTopics (msg .data [2 :])
4836+ require .NoError (t , err )
4837+
4838+ tags , ok := topics .GetValue ("tags" )
4839+ require .True (t , ok )
4840+
4841+ foundVP := false
4842+ for _ , tag := range strings .Split (string (tags ), "," ) {
4843+ if tag == string (protocol .VotePackedTag ) {
4844+ foundVP = true
4845+ break
4846+ }
4847+ }
4848+ require .True (t , foundVP , "expected VP tag for peer with stateful support" )
4849+ default :
4850+ t .Fatal ("expected MOI message for stateful peer" )
4851+ }
4852+ })
4853+ }
0 commit comments