Skip to content

Commit ed9bb09

Browse files
Merge #115: Revert "errors if expecing headers notification but not subscribed"
2d44350 Revert "errors if expecing headers notification but not subscribed" (Riccardo Casatta) Pull request description: This reverts commit b86f2bb. Some errors started to happen in downstream tests after this commit #114 ACKs for top commit: danielabrozzoni: utACK 2d44350 Tree-SHA512: d31174055f4245cc9d99f336b166a44271067b8daecaf2bb55d507ecfa4eb557b9802d576742fba59fd4dfda3f45fc76f02d7896af31353f19fc3a38698ac5a2
2 parents 84b1435 + 2d44350 commit ed9bb09

File tree

3 files changed

+9
-38
lines changed

3 files changed

+9
-38
lines changed

src/client.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ macro_rules! impl_inner_call {
4949
drop(read_client);
5050
match res {
5151
Ok(val) => return Ok(val),
52-
Err(Error::Protocol(_) | Error::AlreadySubscribed(_) | Error::NotSubscribed(_) | Error::NotSubscribedToHeaders) => {
52+
Err(Error::Protocol(_) | Error::AlreadySubscribed(_)) => {
5353
return res;
5454
},
5555
Err(e) => {

src/raw_client.rs

+8-33
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ where
133133
last_id: AtomicUsize,
134134
waiting_map: Mutex<HashMap<usize, Sender<ChannelMessage>>>,
135135

136-
headers: Mutex<Option<VecDeque<RawHeaderNotification>>>,
136+
headers: Mutex<VecDeque<RawHeaderNotification>>,
137137
script_notifications: Mutex<HashMap<ScriptHash, VecDeque<ScriptStatus>>>,
138138

139139
#[cfg(feature = "debug-calls")]
@@ -154,7 +154,7 @@ where
154154
last_id: AtomicUsize::new(0),
155155
waiting_map: Mutex::new(HashMap::new()),
156156

157-
headers: Mutex::new(None),
157+
headers: Mutex::new(VecDeque::new()),
158158
script_notifications: Mutex::new(HashMap::new()),
159159

160160
#[cfg(feature = "debug-calls")]
@@ -648,17 +648,11 @@ impl<S: Read + Write> RawClient<S> {
648648

649649
fn handle_notification(&self, method: &str, result: serde_json::Value) -> Result<(), Error> {
650650
match method {
651-
"blockchain.headers.subscribe" => {
652-
let mut queue = self.headers.lock()?;
653-
match queue.as_mut() {
654-
None => return Err(Error::NotSubscribedToHeaders),
655-
Some(queue) => queue.append(
656-
&mut serde_json::from_value::<Vec<RawHeaderNotification>>(result)?
657-
.into_iter()
658-
.collect(),
659-
),
660-
}
661-
}
651+
"blockchain.headers.subscribe" => self.headers.lock()?.append(
652+
&mut serde_json::from_value::<Vec<RawHeaderNotification>>(result)?
653+
.into_iter()
654+
.collect(),
655+
),
662656
"blockchain.scripthash.subscribe" => {
663657
let unserialized: ScriptNotification = serde_json::from_value(result)?;
664658
let mut script_notifications = self.script_notifications.lock()?;
@@ -768,11 +762,6 @@ impl<T: Read + Write> ElectrumApi for RawClient<T> {
768762
}
769763

770764
fn block_headers_subscribe_raw(&self) -> Result<RawHeaderNotification, Error> {
771-
let mut headers = self.headers.lock()?;
772-
if headers.is_none() {
773-
*headers = Some(VecDeque::new());
774-
}
775-
776765
let req = Request::new_id(
777766
self.last_id.fetch_add(1, Ordering::SeqCst),
778767
"blockchain.headers.subscribe",
@@ -784,11 +773,7 @@ impl<T: Read + Write> ElectrumApi for RawClient<T> {
784773
}
785774

786775
fn block_headers_pop_raw(&self) -> Result<Option<RawHeaderNotification>, Error> {
787-
let mut queue = self.headers.lock()?;
788-
match queue.as_mut() {
789-
None => Err(Error::NotSubscribedToHeaders),
790-
Some(queue) => Ok(queue.pop_front()),
791-
}
776+
Ok(self.headers.lock()?.pop_front())
792777
}
793778

794779
fn block_header_raw(&self, height: usize) -> Result<Vec<u8>, Error> {
@@ -1348,16 +1333,6 @@ mod test {
13481333
assert!(resp.height >= 639000);
13491334
}
13501335

1351-
#[test]
1352-
fn test_block_headers_subscribe_pop() {
1353-
let client = RawClient::new(get_test_server(), None).unwrap();
1354-
let resp = client.block_headers_pop();
1355-
assert_eq!(format!("{:?}", resp), "Err(NotSubscribedToHeaders)");
1356-
client.block_headers_subscribe().unwrap();
1357-
let resp = client.block_headers_pop();
1358-
assert!(resp.is_ok());
1359-
}
1360-
13611336
#[test]
13621337
fn test_script_subscribe() {
13631338
use std::str::FromStr;

src/types.rs

-4
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,6 @@ pub enum Error {
327327
#[cfg(feature = "use-openssl")]
328328
/// SSL Handshake failed with the server
329329
SslHandshakeError(openssl::ssl::HandshakeError<std::net::TcpStream>),
330-
331-
/// Expecting notification on headers but we are not subscribed
332-
NotSubscribedToHeaders,
333330
}
334331

335332
impl Display for Error {
@@ -367,7 +364,6 @@ impl Display for Error {
367364
Error::MissingDomain => f.write_str("Missing domain while it was explicitly asked to validate it"),
368365
Error::CouldntLockReader => f.write_str("Couldn't take a lock on the reader mutex. This means that there's already another reader thread is running"),
369366
Error::Mpsc => f.write_str("Broken IPC communication channel: the other thread probably has exited"),
370-
Error::NotSubscribedToHeaders => write!(f, "Expecting notification on headers but we are not subscribed"),
371367
}
372368
}
373369
}

0 commit comments

Comments
 (0)