Skip to content

Commit 57c43f9

Browse files
committed
stuffing the blocks from the reference into the testing system
1 parent f76aa6d commit 57c43f9

File tree

4 files changed

+74
-9
lines changed

4 files changed

+74
-9
lines changed

proptest-regressions/models/peer/tests/automaton.txt

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

src/models/peer/tests/automaton.rs

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
use futures::SinkExt;
55
use proptest_state_machine::ReferenceStateMachine;
6-
use reference::AssosiatedData;
6+
use reference::{AssosiatedData, Transition};
77
use tokio::runtime::Runtime;
88

99
use crate::{
@@ -13,6 +13,8 @@ use crate::{
1313
pub mod reference;
1414
mod stream_mock;
1515

16+
const BLOCKS_NEW_LEN: usize = 11;
17+
1618
struct TheSut {
1719
main_sim: crate::mpsc::Receiver<PeerTaskToMain>,
1820
// h: PeerLoopHandler,
@@ -25,6 +27,7 @@ struct TheSut {
2527
g: GlobalStateLock,
2628
peer_address: std::net::SocketAddr,
2729
// h: PeerLoopHandler,
30+
stopped: bool,
2831
}
2932
impl proptest_state_machine::StateMachineTest for TheSut {
3033
type SystemUnderTest = Self;
@@ -83,6 +86,7 @@ impl proptest_state_machine::StateMachineTest for TheSut {
8386
g: g.clone(),
8487
peer_address,
8588
// h
89+
stopped: false,
8690
}
8791
}
8892

@@ -91,6 +95,9 @@ impl proptest_state_machine::StateMachineTest for TheSut {
9195
_ref_state: &<Self::Reference as ReferenceStateMachine>::State,
9296
transition: <Self::Reference as ReferenceStateMachine>::Transition,
9397
) -> Self::SystemUnderTest {
98+
if state.stopped {
99+
return state;
100+
}
94101
let Self {
95102
// mut h,
96103
mut main_sim,
@@ -103,14 +110,54 @@ impl proptest_state_machine::StateMachineTest for TheSut {
103110
g,
104111
peer_address,
105112
// h
113+
mut stopped,
106114
} = state;
107115

116+
let mut g_cloned = g.clone();
117+
let mut blocks_stuff = async |bs: Vec<crate::models::blockchain::block::Block>| {
118+
let jq = g_cloned.vm_job_queue().clone();
119+
let mut g_guard = g_cloned.lock_guard_mut().await;
120+
for b in bs {
121+
dbg!(g_guard.set_new_tip(b).await.unwrap())
122+
.into_iter()
123+
.for_each(|j| {
124+
rt.block_on(async {
125+
j.upgrade(&jq, Default::default()).await.unwrap();
126+
})
127+
});
128+
}
129+
};
130+
// this gives a path problem
131+
// let mut g_cloned = g.clone();
132+
// let mut blocks_stuff_t = async |bs: Vec<crate::models::blockchain::block::Block>| {
133+
// let mut g_guard = g_cloned.lock_guard_mut().await;
134+
// let archival = g_guard.chain.archival_state_mut();
135+
// for b in bs {
136+
// crate::tests::shared::add_block_to_archival_state(archival, b).await.unwrap();
137+
// }
138+
// };
139+
#[allow(clippy::shadow_unrelated)]
108140
let g_cloned = g.clone();
109141

110-
if let Some(AssosiatedData::Randomness(_r)) = transition.1 {
111-
todo!("h.set_rng(StdRng::from(r));");
112-
}
113142
rt.block_on(async {
143+
dbg!(&transition);
144+
match transition {
145+
Transition(_, Some(AssosiatedData::MakeNewBlocks(..))) => {
146+
// blocks_stuff(ref_state.blocks[ref_state.blocks.len()-1 - BLOCKS_NEW_LEN..].into()).await;
147+
148+
// let mut g_guard = g_cloned.lock_guard_mut().await;
149+
// let l = ref_state.blocks.len();
150+
// for i in BLOCKS_NEW_LEN..1 {
151+
// // let _ = g_guard.store_block_not_tip(ref_state.blocks[l-1 -i].clone());
152+
// }
153+
// // let _ = dbg!(g_guard.set_new_tip(ref_state.blocks[l-1].clone()).await);
154+
}
155+
Transition(_, Some(AssosiatedData::NewBlock(b))) => {
156+
blocks_stuff(vec![b]).await;
157+
}
158+
_ => {}
159+
};
160+
114161
// h.handle_peer_message_test(transition, &mut sink, &mut counter)
115162
sock.send(transition.0).await.unwrap();
116163

@@ -126,6 +173,18 @@ impl proptest_state_machine::StateMachineTest for TheSut {
126173
// .standing;
127174
// PeerTaskToMain::,
128175
// ];
176+
177+
if let Some(crate::models::peer::peer_info::PeerInfo { standing, .. }) = g_cloned
178+
.lock_guard()
179+
.await
180+
.net
181+
.peer_map
182+
.get(&state.peer_address)
183+
{
184+
if standing.is_bad() {
185+
stopped = true;
186+
}
187+
}
129188
});
130189

131190
Self {
@@ -136,6 +195,7 @@ impl proptest_state_machine::StateMachineTest for TheSut {
136195
g,
137196
peer_address,
138197
// h
198+
stopped,
139199
}
140200
}
141201
}

src/models/peer/tests/automaton/reference/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ enum SyncStage {
3434
// Feels like for peering it's not relevant what mode the node is on: syncing or mining.
3535
#[derive(Debug, Clone)]
3636
pub(crate) struct Automaton {
37-
blocks: Vec<Block>,
37+
pub blocks: Vec<Block>,
3838
// inbound_connection: bool,
3939
// distance: u8,
4040
sync_stage: Option<SyncStage>,
@@ -46,7 +46,9 @@ pub struct Transition(pub PeerMessage, pub Option<AssosiatedData>);
4646
#[derive(Debug, Clone)]
4747
pub enum AssosiatedData {
4848
NewBlock(Block),
49-
Randomness([u8; 32]),
49+
/// feels like randomness is not interesting, but flagging validity could be
50+
// Randomness([u8; 32]),
51+
Valid,
5052
MakeNewBlocks(Timestamp, [u8; 32]),
5153
}
5254
impl From<SyncChallengeResponse> for Transition {

src/models/peer/tests/automaton/reference/strategy_the.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ impl proptest_state_machine::strategy::ReferenceStateMachine for Automaton {
155155
],
156156
// `BlockRequestBatch`
157157
// TODO need an example of the MMR part
158+
// look into `peer_loop_tests::sync_challenges`
158159
// (
159160
// proptest::collection::vec(arb::<Digest>(), 0..crate::main_loop::MAX_NUM_DIGESTS_IN_BATCH_REQUEST),
160161
// 1u16..100u16,
@@ -201,7 +202,8 @@ impl proptest_state_machine::strategy::ReferenceStateMachine for Automaton {
201202
randomness,
202203
)
203204
.into(),
204-
Some(AssosiatedData::Randomness(randomness)),
205+
// Some(AssosiatedData::Randomness(randomness)),
206+
Some(AssosiatedData::Valid),
205207
)
206208
})
207209
.boxed(),
@@ -221,7 +223,7 @@ impl proptest_state_machine::strategy::ReferenceStateMachine for Automaton {
221223
&tip_at_request,
222224
*ts,
223225
*seed_the,
224-
11,
226+
super::super::BLOCKS_NEW_LEN,
225227
),
226228
));
227229
if &PeerMessage::BlockNotificationRequest == variant {
@@ -238,7 +240,7 @@ impl proptest_state_machine::strategy::ReferenceStateMachine for Automaton {
238240
state.sync_stage = Some(SyncStage::WaitingForChallengeResponse);
239241
}
240242
}
241-
Transition(PeerMessage::SyncChallenge(_), Some(AssosiatedData::Randomness(_))) => {
243+
Transition(PeerMessage::SyncChallenge(_), Some(AssosiatedData::Valid)) => {
242244
state.sync_stage =
243245
// Some(SyncStage::DoneWithRandomness(randomness.clone()));
244246
None;

0 commit comments

Comments
 (0)