Do some cleanups (#14608)

* Do some cleanups

Found them while looking over the code.

* More

* Fix
This commit is contained in:
Bastian Köcher
2023-07-21 23:54:01 +02:00
committed by GitHub
parent 98304ee957
commit b16976053e
9 changed files with 39 additions and 45 deletions
@@ -23,7 +23,7 @@ use sc_network_gossip::{MessageIntent, ValidationResult, Validator, ValidatorCon
use sp_core::hashing::twox_64;
use sp_runtime::traits::{Block, Hash, Header, NumberFor};
use codec::{Decode, Encode};
use codec::{Decode, DecodeAll, Encode};
use log::{debug, trace};
use parking_lot::{Mutex, RwLock};
use sc_utils::mpsc::{tracing_unbounded, TracingUnboundedReceiver, TracingUnboundedSender};
@@ -374,7 +374,7 @@ where
mut data: &[u8],
) -> ValidationResult<B::Hash> {
let raw = data;
let action = match GossipMessage::<B>::decode(&mut data) {
let action = match GossipMessage::<B>::decode_all(&mut data) {
Ok(GossipMessage::Vote(msg)) => self.validate_vote(msg, sender, raw),
Ok(GossipMessage::FinalityProof(proof)) => self.validate_finality_proof(proof, sender),
Err(e) => {
@@ -402,7 +402,7 @@ where
fn message_expired<'a>(&'a self) -> Box<dyn FnMut(B::Hash, &[u8]) -> bool + 'a> {
let filter = self.gossip_filter.read();
Box::new(move |_topic, mut data| match GossipMessage::<B>::decode(&mut data) {
Box::new(move |_topic, mut data| match GossipMessage::<B>::decode_all(&mut data) {
Ok(GossipMessage::Vote(msg)) => {
let round = msg.commitment.block_number;
let set_id = msg.commitment.validator_set_id;
@@ -446,7 +446,7 @@ where
return do_rebroadcast
}
match GossipMessage::<B>::decode(&mut data) {
match GossipMessage::<B>::decode_all(&mut data) {
Ok(GossipMessage::Vote(msg)) => {
let round = msg.commitment.block_number;
let set_id = msg.commitment.validator_set_id;
@@ -16,7 +16,7 @@
//! Helper for handling (i.e. answering) BEEFY justifications requests from a remote peer.
use codec::Decode;
use codec::DecodeAll;
use futures::{channel::oneshot, StreamExt};
use log::{debug, error, trace};
use sc_client_api::BlockBackend;
@@ -77,7 +77,7 @@ impl<B: Block> IncomingRequest<B> {
F: FnOnce(usize) -> Vec<ReputationChange>,
{
let netconfig::IncomingRequest { payload, peer, pending_response } = raw;
let payload = match JustificationRequest::decode(&mut payload.as_ref()) {
let payload = match JustificationRequest::decode_all(&mut payload.as_ref()) {
Ok(payload) => payload,
Err(err) => {
let response = netconfig::OutgoingResponse {
@@ -17,7 +17,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
use crate::keystore::BeefyKeystore;
use codec::{Decode, Encode};
use codec::{DecodeAll, Encode};
use sp_consensus::Error as ConsensusError;
use sp_consensus_beefy::{
crypto::{AuthorityId, Signature},
@@ -43,7 +43,7 @@ pub(crate) fn decode_and_verify_finality_proof<Block: BlockT>(
target_number: NumberFor<Block>,
validator_set: &ValidatorSet<AuthorityId>,
) -> Result<BeefyVersionedFinalityProof<Block>, (ConsensusError, u32)> {
let proof = <BeefyVersionedFinalityProof<Block>>::decode(&mut &*encoded)
let proof = <BeefyVersionedFinalityProof<Block>>::decode_all(&mut &*encoded)
.map_err(|_| (ConsensusError::InvalidJustification, 0))?;
verify_with_validator_set::<Block>(target_number, validator_set, &proof).map(|_| proof)
}
@@ -30,7 +30,7 @@ use crate::{
round::{Rounds, VoteImportResult},
BeefyVoterLinks, LOG_TARGET,
};
use codec::{Codec, Decode, Encode};
use codec::{Codec, Decode, DecodeAll, Encode};
use futures::{stream::Fuse, FutureExt, StreamExt};
use log::{debug, error, info, log_enabled, trace, warn};
use sc_client_api::{Backend, FinalityNotification, FinalityNotifications, HeaderBackend};
@@ -810,7 +810,7 @@ where
self.gossip_engine
.messages_for(votes_topic::<B>())
.filter_map(|notification| async move {
let vote = GossipMessage::<B>::decode(&mut &notification.message[..])
let vote = GossipMessage::<B>::decode_all(&mut &notification.message[..])
.ok()
.and_then(|message| message.unwrap_vote());
trace!(target: LOG_TARGET, "🥩 Got vote message: {:?}", vote);
@@ -822,7 +822,7 @@ where
self.gossip_engine
.messages_for(proofs_topic::<B>())
.filter_map(|notification| async move {
let proof = GossipMessage::<B>::decode(&mut &notification.message[..])
let proof = GossipMessage::<B>::decode_all(&mut &notification.message[..])
.ok()
.and_then(|message| message.unwrap_finality_proof());
trace!(target: LOG_TARGET, "🥩 Got gossip proof message: {:?}", proof);