Skip to content

Commit 6d20063

Browse files
committed
try to reproduce
1 parent b07f827 commit 6d20063

File tree

2 files changed

+80
-24
lines changed

2 files changed

+80
-24
lines changed

test/src/specs/indexer/basic.rs

Lines changed: 79 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
use crate::node::{disconnect_all, waiting_for_sync};
1+
use crate::node::{connect_all, disconnect_all, waiting_for_sync};
22
use crate::util::mining::out_ibd_mode;
33
use crate::utils::find_available_port;
44
use crate::{Node, Spec};
55
use ckb_logger::{info, warn};
6+
use ckb_types::packed;
67
use postgresql_embedded::{Settings, blocking::PostgreSQL};
78
use std::thread::sleep;
89
use std::time::Duration;
@@ -28,7 +29,24 @@ impl Spec for RichIndexerChainReorgBug {
2829
settings.port = postgres_port;
2930
settings.username = "postgres".to_string();
3031
settings.password = "password".to_string();
31-
32+
// Make Postgres emit statements and durations to stderr
33+
settings
34+
.configuration
35+
.insert("log_destination".into(), "stderr".into());
36+
// Don't capture into files; send to stderr
37+
settings
38+
.configuration
39+
.insert("logging_collector".into(), "off".into());
40+
// Log every statement (alternatives: ddl | mod | none)
41+
settings
42+
.configuration
43+
.insert("log_statement".into(), "all".into());
44+
// Also log duration of every completed statement (0 ms threshold)
45+
settings
46+
.configuration
47+
.insert("log_min_duration_statement".into(), "0".into());
48+
49+
info!("setitngs; {:?}", settings);
3250
let mut postgresql = PostgreSQL::new(settings);
3351
postgresql.setup().expect("Failed to setup PostgreSQL");
3452
postgresql.start().expect("Failed to start PostgreSQL");
@@ -83,30 +101,64 @@ impl Spec for RichIndexerChainReorgBug {
83101
out_ibd_mode(nodes);
84102

85103
// Create shared history
86-
node0.mine(2);
87104
node1.connect(node0);
105+
node0.mine(1);
106+
node1.mine(1);
107+
88108
waiting_for_sync(&[node0, node1]);
89109
info!(
90110
"Both nodes synced to height {}",
91111
node0.get_tip_block_number()
92112
);
93113

94114
info!("=== Phase 2: Create competing chains ===");
95-
disconnect_all(nodes);
96-
97-
// Node0 mines shorter chain (3 blocks)
98-
node0.mine(3);
99-
let node0_tip = node0.get_tip_block_number();
100-
let node0_hash = node0.get_tip_block().hash();
101115

102-
// Node1 mines longer chain (5 blocks)
103-
node1.mine(5);
104-
let node1_tip = node1.get_tip_block_number();
105-
let node1_hash = node1.get_tip_block().hash();
116+
let node_dbg = |height: Option<u64>| {
117+
nodes.iter().enumerate().for_each(|(id, node)| {
118+
if let Some(h) = height {
119+
let block = node.get_block_by_number(h);
120+
info!(
121+
"Node{} block at height {}: hash={}, parent={}",
122+
id,
123+
h,
124+
block.hash(),
125+
block.parent_hash()
126+
);
127+
} else {
128+
if id == 0 {
129+
let indexer_tip = node
130+
.rpc_client()
131+
.get_indexer_tip()
132+
.expect("must get indexer tip");
133+
let indexer_tip_number: u64 = indexer_tip.block_number.into();
134+
let indexer_tip_hash: packed::Byte32 = indexer_tip.block_hash.into();
135+
info!(
136+
"Node{} indexer: {}-{}",
137+
id, indexer_tip_number, indexer_tip_hash,
138+
);
139+
}
140+
let tip = node.get_tip_block();
141+
info!("Node{} tip: height {}-{}", id, tip.number(), tip.hash(),);
142+
}
143+
});
144+
};
145+
146+
let now = std::time::Instant::now();
147+
while now.elapsed().le(&Duration::from_secs(600)) {
148+
info!("crete forking..............................................");
149+
disconnect_all(&nodes);
150+
node0.mine(1);
151+
node1.mine(1);
152+
let base_height = node0.get_tip_block_number();
153+
node_dbg(Some(base_height));
154+
node1.mine(1);
155+
connect_all(&nodes);
156+
waiting_for_sync(nodes);
157+
node_dbg(None);
158+
}
106159

107160
info!("Fork created:");
108-
info!(" Node0: height {} -> {:?}", node0_tip, node0_hash);
109-
info!(" Node1: height {} -> {:?}", node1_tip, node1_hash);
161+
node_dbg(None);
110162

111163
info!("=== Phase 3: Check rich-indexer before reorganization ===");
112164
let indexer_tip_before = node0.rpc_client().get_indexer_tip().unwrap();
@@ -116,16 +168,20 @@ impl Spec for RichIndexerChainReorgBug {
116168
);
117169

118170
info!("=== Phase 4: Trigger chain reorganization ===");
119-
// Connect nodes - node1's longer chain should win
120-
node0.connect(node1);
121171
waiting_for_sync(&[node0, node1]);
122172

123-
let final_tip = node0.get_tip_block_number();
124-
let final_hash = node0.get_tip_block().hash();
125-
info!(
126-
"After sync - chain tip: height {} -> {:?}",
127-
final_tip, final_hash
128-
);
173+
info!("After sync");
174+
nodes.iter().enumerate().for_each(|(id, node)| {
175+
let tip = node.get_tip_block();
176+
info!(
177+
"Node {} tip: height {} -> {:?}",
178+
id,
179+
tip.number(),
180+
tip.hash()
181+
);
182+
});
183+
184+
let final_tip = node0.get_tip_block().number();
129185

130186
// Wait for rich-indexer to catch up
131187
// sleep(Duration::from_secs(5));

test/src/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ where
133133
if f() {
134134
return true;
135135
}
136-
thread::sleep(Duration::new(1, 0));
136+
thread::sleep(Duration::from_millis(100));
137137
}
138138
false
139139
}

0 commit comments

Comments
 (0)