Skip to content
This repository was archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Merge pull request #1495 from ethcore/work-notify
Browse files Browse the repository at this point in the history
Workaround for hyper panic
  • Loading branch information
arkpar authored Jun 30, 2016
2 parents 30fad64 + 51c6b85 commit ff29c82
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions ethcore/src/miner/work_notify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,37 @@ impl WorkPoster {
}
}
}).collect();
let client = Client::<PostHandler>::configure()
.keep_alive(false)
.build().expect("Error creating HTTP client");
let client = WorkPoster::create_client();
WorkPoster {
client: Mutex::new(client),
urls: urls,
seed_compute: Mutex::new(SeedHashCompute::new()),
}
}

fn create_client() -> Client<PostHandler> {
let client = Client::<PostHandler>::configure()
.keep_alive(true)
.build().expect("Error creating HTTP client") as Client<PostHandler>;
client
}

pub fn notify(&self, pow_hash: H256, difficulty: U256, number: u64) {
// TODO: move this to engine
let target = Ethash::difficulty_to_boundary(&difficulty);
let seed_hash = &self.seed_compute.lock().unwrap().get_seedhash(number);
let seed_hash = H256::from_slice(&seed_hash[..]);
let body = format!(r#"{{ "result": ["0x{}","0x{}","0x{}","0x{:x}"] }}"#,
pow_hash.hex(), seed_hash.hex(), target.hex(), number);
let client = self.client.lock().unwrap();
let mut client = self.client.lock().unwrap();
for u in &self.urls {
if let Err(e) = client.request(u.clone(), PostHandler { body: body.clone() }) {
warn!("Error sending HTTP notification to {} : {}", u, e);
warn!("Error sending HTTP notification to {} : {}, retrying", u, e);
// TODO: remove this once https://github.com/hyperium/hyper/issues/848 is fixed
*client = WorkPoster::create_client();
if let Err(e) = client.request(u.clone(), PostHandler { body: body.clone() }) {
warn!("Error sending HTTP notification to {} : {}", u, e);
}
}
}
}
Expand Down

0 comments on commit ff29c82

Please sign in to comment.