(cherry picked from commit 076c20f1ca)
Co-authored-by: behzad nouri <behzadnouri@gmail.com>
			
			
This commit is contained in:
		@@ -313,7 +313,7 @@ impl Default for ClusterInfo {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[derive(Debug, Default, Deserialize, Serialize, AbiExample)]
 | 
					#[derive(Clone, Debug, Default, Deserialize, Serialize, AbiExample)]
 | 
				
			||||||
pub struct PruneData {
 | 
					pub struct PruneData {
 | 
				
			||||||
    /// Pubkey of the node that sent this prune data
 | 
					    /// Pubkey of the node that sent this prune data
 | 
				
			||||||
    pub pubkey: Pubkey,
 | 
					    pub pubkey: Pubkey,
 | 
				
			||||||
@@ -413,6 +413,8 @@ enum Protocol {
 | 
				
			|||||||
    PullRequest(CrdsFilter, CrdsValue),
 | 
					    PullRequest(CrdsFilter, CrdsValue),
 | 
				
			||||||
    PullResponse(Pubkey, Vec<CrdsValue>),
 | 
					    PullResponse(Pubkey, Vec<CrdsValue>),
 | 
				
			||||||
    PushMessage(Pubkey, Vec<CrdsValue>),
 | 
					    PushMessage(Pubkey, Vec<CrdsValue>),
 | 
				
			||||||
 | 
					    // TODO: Remove the redundant outer pubkey here,
 | 
				
			||||||
 | 
					    // and use the inner PruneData.pubkey instead.
 | 
				
			||||||
    PruneMessage(Pubkey, PruneData),
 | 
					    PruneMessage(Pubkey, PruneData),
 | 
				
			||||||
    PingMessage(Ping),
 | 
					    PingMessage(Ping),
 | 
				
			||||||
    PongMessage(Pong),
 | 
					    PongMessage(Pong),
 | 
				
			||||||
@@ -496,7 +498,13 @@ impl Sanitize for Protocol {
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
            Protocol::PullResponse(_, val) => val.sanitize(),
 | 
					            Protocol::PullResponse(_, val) => val.sanitize(),
 | 
				
			||||||
            Protocol::PushMessage(_, val) => val.sanitize(),
 | 
					            Protocol::PushMessage(_, val) => val.sanitize(),
 | 
				
			||||||
            Protocol::PruneMessage(_, val) => val.sanitize(),
 | 
					            Protocol::PruneMessage(from, val) => {
 | 
				
			||||||
 | 
					                if *from != val.pubkey {
 | 
				
			||||||
 | 
					                    Err(SanitizeError::InvalidValue)
 | 
				
			||||||
 | 
					                } else {
 | 
				
			||||||
 | 
					                    val.sanitize()
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
            Protocol::PingMessage(ping) => ping.sanitize(),
 | 
					            Protocol::PingMessage(ping) => ping.sanitize(),
 | 
				
			||||||
            Protocol::PongMessage(pong) => pong.sanitize(),
 | 
					            Protocol::PongMessage(pong) => pong.sanitize(),
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -4169,6 +4177,23 @@ mod tests {
 | 
				
			|||||||
        assert_eq!(msg.sanitize(), Err(SanitizeError::ValueOutOfBounds));
 | 
					        assert_eq!(msg.sanitize(), Err(SanitizeError::ValueOutOfBounds));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    #[test]
 | 
				
			||||||
 | 
					    fn test_protocol_prune_message_sanitize() {
 | 
				
			||||||
 | 
					        let keypair = Keypair::new();
 | 
				
			||||||
 | 
					        let mut prune_data = PruneData {
 | 
				
			||||||
 | 
					            pubkey: keypair.pubkey(),
 | 
				
			||||||
 | 
					            prunes: vec![],
 | 
				
			||||||
 | 
					            signature: Signature::default(),
 | 
				
			||||||
 | 
					            destination: Pubkey::new_unique(),
 | 
				
			||||||
 | 
					            wallclock: timestamp(),
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					        prune_data.sign(&keypair);
 | 
				
			||||||
 | 
					        let prune_message = Protocol::PruneMessage(keypair.pubkey(), prune_data.clone());
 | 
				
			||||||
 | 
					        assert_eq!(prune_message.sanitize(), Ok(()));
 | 
				
			||||||
 | 
					        let prune_message = Protocol::PruneMessage(Pubkey::new_unique(), prune_data);
 | 
				
			||||||
 | 
					        assert_eq!(prune_message.sanitize(), Err(SanitizeError::InvalidValue));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // computes the maximum size for pull request blooms
 | 
					    // computes the maximum size for pull request blooms
 | 
				
			||||||
    fn max_bloom_size() -> usize {
 | 
					    fn max_bloom_size() -> usize {
 | 
				
			||||||
        let filter_size = serialized_size(&CrdsFilter::default())
 | 
					        let filter_size = serialized_size(&CrdsFilter::default())
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user