mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 12:17:58 +00:00
cargo +nightly fmt (#3540)
* cargo +nightly fmt * add cargo-fmt check to ci * update ci * fmt * fmt * skip macro * ignore bridges
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -14,17 +14,17 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use std::time::Duration;
|
||||
use futures::{future, Future, executor};
|
||||
use super::*;
|
||||
use assert_matches::assert_matches;
|
||||
use futures::{executor, future, Future};
|
||||
use polkadot_node_network_protocol::{view, ObservedRole};
|
||||
use polkadot_node_primitives::approval::{
|
||||
AssignmentCertKind, VRFOutput, VRFProof, RELAY_VRF_MODULO_CONTEXT,
|
||||
};
|
||||
use polkadot_node_subsystem::messages::{AllMessages, ApprovalCheckError};
|
||||
use polkadot_node_subsystem_test_helpers as test_helpers;
|
||||
use polkadot_node_subsystem_util::TimeoutExt as _;
|
||||
use polkadot_node_network_protocol::{view, ObservedRole};
|
||||
use polkadot_node_primitives::approval::{
|
||||
AssignmentCertKind, RELAY_VRF_MODULO_CONTEXT, VRFOutput, VRFProof,
|
||||
};
|
||||
use super::*;
|
||||
use std::time::Duration;
|
||||
|
||||
type VirtualOverseer = test_helpers::TestSubsystemContextHandle<ApprovalDistributionMessage>;
|
||||
|
||||
@@ -34,10 +34,7 @@ fn test_harness<T: Future<Output = VirtualOverseer>>(
|
||||
) -> State {
|
||||
let _ = env_logger::builder()
|
||||
.is_test(true)
|
||||
.filter(
|
||||
Some(LOG_TARGET),
|
||||
log::LevelFilter::Trace,
|
||||
)
|
||||
.filter(Some(LOG_TARGET), log::LevelFilter::Trace)
|
||||
.try_init();
|
||||
|
||||
let pool = sp_core::testing::TaskExecutor::new();
|
||||
@@ -52,14 +49,17 @@ fn test_harness<T: Future<Output = VirtualOverseer>>(
|
||||
futures::pin_mut!(test_fut);
|
||||
futures::pin_mut!(subsystem);
|
||||
|
||||
executor::block_on(future::join(async move {
|
||||
let mut overseer = test_fut.await;
|
||||
overseer
|
||||
.send(FromOverseer::Signal(OverseerSignal::Conclude))
|
||||
.timeout(TIMEOUT)
|
||||
.await
|
||||
.expect("Conclude send timeout");
|
||||
}, subsystem));
|
||||
executor::block_on(future::join(
|
||||
async move {
|
||||
let mut overseer = test_fut.await;
|
||||
overseer
|
||||
.send(FromOverseer::Signal(OverseerSignal::Conclude))
|
||||
.timeout(TIMEOUT)
|
||||
.await
|
||||
.expect("Conclude send timeout");
|
||||
},
|
||||
subsystem,
|
||||
));
|
||||
}
|
||||
|
||||
state
|
||||
@@ -67,10 +67,7 @@ fn test_harness<T: Future<Output = VirtualOverseer>>(
|
||||
|
||||
const TIMEOUT: Duration = Duration::from_millis(100);
|
||||
|
||||
async fn overseer_send(
|
||||
overseer: &mut VirtualOverseer,
|
||||
msg: ApprovalDistributionMessage,
|
||||
) {
|
||||
async fn overseer_send(overseer: &mut VirtualOverseer, msg: ApprovalDistributionMessage) {
|
||||
tracing::trace!(msg = ?msg, "Sending message");
|
||||
overseer
|
||||
.send(FromOverseer::Communication { msg })
|
||||
@@ -79,14 +76,8 @@ async fn overseer_send(
|
||||
.expect("msg send timeout");
|
||||
}
|
||||
|
||||
async fn overseer_signal_block_finalized(
|
||||
overseer: &mut VirtualOverseer,
|
||||
number: BlockNumber,
|
||||
) {
|
||||
tracing::trace!(
|
||||
?number,
|
||||
"Sending a finalized signal",
|
||||
);
|
||||
async fn overseer_signal_block_finalized(overseer: &mut VirtualOverseer, number: BlockNumber) {
|
||||
tracing::trace!(?number, "Sending a finalized signal",);
|
||||
// we don't care about the block hash
|
||||
overseer
|
||||
.send(FromOverseer::Signal(OverseerSignal::BlockFinalized(Hash::zero(), number)))
|
||||
@@ -95,15 +86,9 @@ async fn overseer_signal_block_finalized(
|
||||
.expect("signal send timeout");
|
||||
}
|
||||
|
||||
async fn overseer_recv(
|
||||
overseer: &mut VirtualOverseer,
|
||||
) -> AllMessages {
|
||||
async fn overseer_recv(overseer: &mut VirtualOverseer) -> AllMessages {
|
||||
tracing::trace!("Waiting for a message");
|
||||
let msg = overseer
|
||||
.recv()
|
||||
.timeout(TIMEOUT)
|
||||
.await
|
||||
.expect("msg recv timeout");
|
||||
let msg = overseer.recv().timeout(TIMEOUT).await.expect("msg recv timeout");
|
||||
|
||||
tracing::trace!(msg = ?msg, "Received message");
|
||||
|
||||
@@ -117,16 +102,21 @@ async fn setup_peer_with_view(
|
||||
) {
|
||||
overseer_send(
|
||||
virtual_overseer,
|
||||
ApprovalDistributionMessage::NetworkBridgeUpdateV1(
|
||||
NetworkBridgeEvent::PeerConnected(peer_id.clone(), ObservedRole::Full, None)
|
||||
)
|
||||
).await;
|
||||
ApprovalDistributionMessage::NetworkBridgeUpdateV1(NetworkBridgeEvent::PeerConnected(
|
||||
peer_id.clone(),
|
||||
ObservedRole::Full,
|
||||
None,
|
||||
)),
|
||||
)
|
||||
.await;
|
||||
overseer_send(
|
||||
virtual_overseer,
|
||||
ApprovalDistributionMessage::NetworkBridgeUpdateV1(
|
||||
NetworkBridgeEvent::PeerViewChange(peer_id.clone(), view)
|
||||
)
|
||||
).await;
|
||||
ApprovalDistributionMessage::NetworkBridgeUpdateV1(NetworkBridgeEvent::PeerViewChange(
|
||||
peer_id.clone(),
|
||||
view,
|
||||
)),
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
async fn send_message_from_peer(
|
||||
@@ -136,16 +126,15 @@ async fn send_message_from_peer(
|
||||
) {
|
||||
overseer_send(
|
||||
virtual_overseer,
|
||||
ApprovalDistributionMessage::NetworkBridgeUpdateV1(
|
||||
NetworkBridgeEvent::PeerMessage(peer_id.clone(), msg)
|
||||
)
|
||||
).await;
|
||||
ApprovalDistributionMessage::NetworkBridgeUpdateV1(NetworkBridgeEvent::PeerMessage(
|
||||
peer_id.clone(),
|
||||
msg,
|
||||
)),
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
fn fake_assignment_cert(
|
||||
block_hash: Hash,
|
||||
validator: ValidatorIndex,
|
||||
) -> IndirectAssignmentCert {
|
||||
fn fake_assignment_cert(block_hash: Hash, validator: ValidatorIndex) -> IndirectAssignmentCert {
|
||||
let ctx = schnorrkel::signing_context(RELAY_VRF_MODULO_CONTEXT);
|
||||
let msg = b"WhenParachains?";
|
||||
let mut prng = rand_core::OsRng;
|
||||
@@ -157,11 +146,9 @@ fn fake_assignment_cert(
|
||||
block_hash,
|
||||
validator,
|
||||
cert: AssignmentCert {
|
||||
kind: AssignmentCertKind::RelayVRFModulo {
|
||||
sample: 1,
|
||||
},
|
||||
kind: AssignmentCertKind::RelayVRFModulo { sample: 1 },
|
||||
vrf: (VRFOutput(out), VRFProof(proof)),
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,7 +171,6 @@ async fn expect_reputation_change(
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/// import an assignment
|
||||
/// connect a new peer
|
||||
/// the new peer sends us the same assignment
|
||||
@@ -263,13 +249,7 @@ fn try_import_the_same_assignment() {
|
||||
expect_reputation_change(overseer, &peer_d, COST_UNEXPECTED_MESSAGE).await;
|
||||
expect_reputation_change(overseer, &peer_d, BENEFIT_VALID_MESSAGE).await;
|
||||
|
||||
assert!(overseer
|
||||
.recv()
|
||||
.timeout(TIMEOUT)
|
||||
.await
|
||||
.is_none(),
|
||||
"no message should be sent",
|
||||
);
|
||||
assert!(overseer.recv().timeout(TIMEOUT).await.is_none(), "no message should be sent",);
|
||||
virtual_overseer
|
||||
});
|
||||
}
|
||||
@@ -311,7 +291,8 @@ fn spam_attack_results_in_negative_reputation_change() {
|
||||
let validator_index = ValidatorIndex(candidate_index as u32);
|
||||
let cert = fake_assignment_cert(hash_b, validator_index);
|
||||
(cert, candidate_index as u32)
|
||||
}).collect();
|
||||
})
|
||||
.collect();
|
||||
|
||||
let msg = protocol_v1::ApprovalDistributionMessage::Assignments(assignments.clone());
|
||||
send_message_from_peer(overseer, peer, msg.clone()).await;
|
||||
@@ -338,10 +319,12 @@ fn spam_attack_results_in_negative_reputation_change() {
|
||||
// send a view update that removes block B from peer's view by bumping the finalized_number
|
||||
overseer_send(
|
||||
overseer,
|
||||
ApprovalDistributionMessage::NetworkBridgeUpdateV1(
|
||||
NetworkBridgeEvent::PeerViewChange(peer.clone(), View::with_finalized(2))
|
||||
)
|
||||
).await;
|
||||
ApprovalDistributionMessage::NetworkBridgeUpdateV1(NetworkBridgeEvent::PeerViewChange(
|
||||
peer.clone(),
|
||||
View::with_finalized(2),
|
||||
)),
|
||||
)
|
||||
.await;
|
||||
|
||||
// send the assignments again
|
||||
send_message_from_peer(overseer, peer, msg.clone()).await;
|
||||
@@ -355,7 +338,6 @@ fn spam_attack_results_in_negative_reputation_change() {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/// Imagine we send a message to peer A and peer B.
|
||||
/// Upon receiving them, they both will try to send the message each other.
|
||||
/// This test makes sure they will not punish each other for such duplicate messages.
|
||||
@@ -389,16 +371,19 @@ fn peer_sending_us_the_same_we_just_sent_them_is_ok() {
|
||||
let cert = fake_assignment_cert(hash, validator_index);
|
||||
overseer_send(
|
||||
overseer,
|
||||
ApprovalDistributionMessage::DistributeAssignment(cert.clone(), candidate_index)
|
||||
).await;
|
||||
ApprovalDistributionMessage::DistributeAssignment(cert.clone(), candidate_index),
|
||||
)
|
||||
.await;
|
||||
|
||||
// update peer view to include the hash
|
||||
overseer_send(
|
||||
overseer,
|
||||
ApprovalDistributionMessage::NetworkBridgeUpdateV1(
|
||||
NetworkBridgeEvent::PeerViewChange(peer.clone(), view![hash])
|
||||
)
|
||||
).await;
|
||||
ApprovalDistributionMessage::NetworkBridgeUpdateV1(NetworkBridgeEvent::PeerViewChange(
|
||||
peer.clone(),
|
||||
view![hash],
|
||||
)),
|
||||
)
|
||||
.await;
|
||||
|
||||
// we should send them the assignment
|
||||
assert_matches!(
|
||||
@@ -420,13 +405,7 @@ fn peer_sending_us_the_same_we_just_sent_them_is_ok() {
|
||||
let msg = protocol_v1::ApprovalDistributionMessage::Assignments(assignments);
|
||||
send_message_from_peer(overseer, peer, msg.clone()).await;
|
||||
|
||||
assert!(overseer
|
||||
.recv()
|
||||
.timeout(TIMEOUT)
|
||||
.await
|
||||
.is_none(),
|
||||
"we should not punish the peer",
|
||||
);
|
||||
assert!(overseer.recv().timeout(TIMEOUT).await.is_none(), "we should not punish the peer",);
|
||||
|
||||
// send the assignments again
|
||||
send_message_from_peer(overseer, peer, msg).await;
|
||||
@@ -469,8 +448,9 @@ fn import_approval_happy_path() {
|
||||
let cert = fake_assignment_cert(hash, validator_index);
|
||||
overseer_send(
|
||||
overseer,
|
||||
ApprovalDistributionMessage::DistributeAssignment(cert, candidate_index)
|
||||
).await;
|
||||
ApprovalDistributionMessage::DistributeAssignment(cert, candidate_index),
|
||||
)
|
||||
.await;
|
||||
|
||||
assert_matches!(
|
||||
overseer_recv(overseer).await,
|
||||
@@ -716,15 +696,9 @@ fn update_peer_view() {
|
||||
let cert_a = fake_assignment_cert(hash_a, ValidatorIndex(0));
|
||||
let cert_b = fake_assignment_cert(hash_b, ValidatorIndex(0));
|
||||
|
||||
overseer_send(
|
||||
overseer,
|
||||
ApprovalDistributionMessage::DistributeAssignment(cert_a, 0)
|
||||
).await;
|
||||
overseer_send(overseer, ApprovalDistributionMessage::DistributeAssignment(cert_a, 0)).await;
|
||||
|
||||
overseer_send(
|
||||
overseer,
|
||||
ApprovalDistributionMessage::DistributeAssignment(cert_b, 0)
|
||||
).await;
|
||||
overseer_send(overseer, ApprovalDistributionMessage::DistributeAssignment(cert_b, 0)).await;
|
||||
|
||||
// connect a peer
|
||||
setup_peer_with_view(overseer, peer, view![hash_a]).await;
|
||||
@@ -747,7 +721,8 @@ fn update_peer_view() {
|
||||
|
||||
assert_eq!(state.peer_views.get(peer).map(|v| v.finalized_number), Some(0));
|
||||
assert_eq!(
|
||||
state.blocks
|
||||
state
|
||||
.blocks
|
||||
.get(&hash_a)
|
||||
.unwrap()
|
||||
.known_by
|
||||
@@ -764,17 +739,20 @@ fn update_peer_view() {
|
||||
// update peer's view
|
||||
overseer_send(
|
||||
overseer,
|
||||
ApprovalDistributionMessage::NetworkBridgeUpdateV1(
|
||||
NetworkBridgeEvent::PeerViewChange(peer.clone(), View::new(vec![hash_b, hash_c, hash_d], 2))
|
||||
)
|
||||
).await;
|
||||
ApprovalDistributionMessage::NetworkBridgeUpdateV1(NetworkBridgeEvent::PeerViewChange(
|
||||
peer.clone(),
|
||||
View::new(vec![hash_b, hash_c, hash_d], 2),
|
||||
)),
|
||||
)
|
||||
.await;
|
||||
|
||||
let cert_c = fake_assignment_cert(hash_c, ValidatorIndex(0));
|
||||
|
||||
overseer_send(
|
||||
overseer,
|
||||
ApprovalDistributionMessage::DistributeAssignment(cert_c.clone(), 0)
|
||||
).await;
|
||||
ApprovalDistributionMessage::DistributeAssignment(cert_c.clone(), 0),
|
||||
)
|
||||
.await;
|
||||
|
||||
// we should send relevant assignments to the peer
|
||||
assert_matches!(
|
||||
@@ -795,7 +773,8 @@ fn update_peer_view() {
|
||||
|
||||
assert_eq!(state.peer_views.get(peer).map(|v| v.finalized_number), Some(2));
|
||||
assert_eq!(
|
||||
state.blocks
|
||||
state
|
||||
.blocks
|
||||
.get(&hash_c)
|
||||
.unwrap()
|
||||
.known_by
|
||||
@@ -813,22 +792,17 @@ fn update_peer_view() {
|
||||
// update peer's view
|
||||
overseer_send(
|
||||
overseer,
|
||||
ApprovalDistributionMessage::NetworkBridgeUpdateV1(
|
||||
NetworkBridgeEvent::PeerViewChange(peer.clone(), View::with_finalized(finalized_number))
|
||||
)
|
||||
).await;
|
||||
ApprovalDistributionMessage::NetworkBridgeUpdateV1(NetworkBridgeEvent::PeerViewChange(
|
||||
peer.clone(),
|
||||
View::with_finalized(finalized_number),
|
||||
)),
|
||||
)
|
||||
.await;
|
||||
virtual_overseer
|
||||
});
|
||||
|
||||
assert_eq!(state.peer_views.get(peer).map(|v| v.finalized_number), Some(finalized_number));
|
||||
assert!(
|
||||
state.blocks
|
||||
.get(&hash_c)
|
||||
.unwrap()
|
||||
.known_by
|
||||
.get(peer)
|
||||
.is_none()
|
||||
);
|
||||
assert!(state.blocks.get(&hash_c).unwrap().known_by.get(peer).is_none());
|
||||
}
|
||||
|
||||
/// E.g. if someone copies the keys...
|
||||
@@ -882,16 +856,11 @@ fn import_remotely_then_locally() {
|
||||
// import the same assignment locally
|
||||
overseer_send(
|
||||
overseer,
|
||||
ApprovalDistributionMessage::DistributeAssignment(cert, candidate_index)
|
||||
).await;
|
||||
ApprovalDistributionMessage::DistributeAssignment(cert, candidate_index),
|
||||
)
|
||||
.await;
|
||||
|
||||
assert!(overseer
|
||||
.recv()
|
||||
.timeout(TIMEOUT)
|
||||
.await
|
||||
.is_none(),
|
||||
"no message should be sent",
|
||||
);
|
||||
assert!(overseer.recv().timeout(TIMEOUT).await.is_none(), "no message should be sent",);
|
||||
|
||||
// send the approval remotely
|
||||
let approval = IndirectSignedApprovalVote {
|
||||
@@ -916,18 +885,9 @@ fn import_remotely_then_locally() {
|
||||
expect_reputation_change(overseer, peer, BENEFIT_VALID_MESSAGE_FIRST).await;
|
||||
|
||||
// import the same approval locally
|
||||
overseer_send(
|
||||
overseer,
|
||||
ApprovalDistributionMessage::DistributeApproval(approval)
|
||||
).await;
|
||||
overseer_send(overseer, ApprovalDistributionMessage::DistributeApproval(approval)).await;
|
||||
|
||||
assert!(overseer
|
||||
.recv()
|
||||
.timeout(TIMEOUT)
|
||||
.await
|
||||
.is_none(),
|
||||
"no message should be sent",
|
||||
);
|
||||
assert!(overseer.recv().timeout(TIMEOUT).await.is_none(), "no message should be sent",);
|
||||
virtual_overseer
|
||||
});
|
||||
}
|
||||
@@ -967,13 +927,12 @@ fn sends_assignments_even_when_state_is_approved() {
|
||||
|
||||
overseer_send(
|
||||
overseer,
|
||||
ApprovalDistributionMessage::DistributeAssignment(cert.clone(), candidate_index)
|
||||
).await;
|
||||
ApprovalDistributionMessage::DistributeAssignment(cert.clone(), candidate_index),
|
||||
)
|
||||
.await;
|
||||
|
||||
overseer_send(
|
||||
overseer,
|
||||
ApprovalDistributionMessage::DistributeApproval(approval.clone()),
|
||||
).await;
|
||||
overseer_send(overseer, ApprovalDistributionMessage::DistributeApproval(approval.clone()))
|
||||
.await;
|
||||
|
||||
// connect the peer.
|
||||
setup_peer_with_view(overseer, peer, view![hash]).await;
|
||||
@@ -1007,13 +966,7 @@ fn sends_assignments_even_when_state_is_approved() {
|
||||
}
|
||||
);
|
||||
|
||||
assert!(overseer
|
||||
.recv()
|
||||
.timeout(TIMEOUT)
|
||||
.await
|
||||
.is_none(),
|
||||
"no message should be sent",
|
||||
);
|
||||
assert!(overseer.recv().timeout(TIMEOUT).await.is_none(), "no message should be sent",);
|
||||
virtual_overseer
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user