Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
doitian committed Jun 17, 2019
2 parents 190e9f2 + 07532c3 commit 188b848
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 24 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,13 @@ All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.


# [v0.14.1](https://github.com/nervosnetwork/ckb/compare/v0.14.0...v0.14.1) (2019-06-16)

### Bug Fixes

* #1019: Miner log wrong block hash (@quake)
* #1025: Miner time interval panic (@quake)

# [v0.14.0](https://github.com/nervosnetwork/ckb/compare/v0.13.0...v0.14.0) (2019-06-15) rylai-v3

### BREAKING CHANGES
Expand Down
17 changes: 8 additions & 9 deletions miner/src/miner.rs
Expand Up @@ -88,25 +88,24 @@ impl Miner {

fn check_seal(&mut self, pow_hash: H256, seal: Seal) {
if let Some(work) = self.works.lock().get_refresh(&pow_hash) {
let block = &work.block;
if self
.pow
.verify_proof_difficulty(&seal.proof(), &block.header().difficulty())
.verify_proof_difficulty(&seal.proof(), &work.block.header().difficulty())
{
self.notify_workers(WorkerMessage::Stop);
let raw_header = work.block.header().raw().to_owned();
let block = BlockBuilder::from_block(work.block.clone())
.header(raw_header.with_seal(seal))
.build();

debug!(
"found seal {:?} of block #{} {:x}",
seal,
"Found! #{} {:#x}",
block.header().number(),
block.header().hash(),
);

// submit block and poll new work
{
let raw_header = block.header().raw().to_owned();
let block = BlockBuilder::from_block(block.clone())
.header(raw_header.with_seal(seal))
.build();
self.client.submit_block(&work.work_id.to_string(), &block);
self.client.try_update_block_template();
self.notify_workers(WorkerMessage::Start);
Expand All @@ -116,7 +115,7 @@ impl Miner {
{
self.seals_found += 1;
self.pb.println(format!(
"Found! #{} {:x}",
"Found! #{} {:#x}",
block.header().number(),
block.header().hash()
));
Expand Down
16 changes: 8 additions & 8 deletions miner/src/worker/cuckoo_simple.rs
Expand Up @@ -9,7 +9,7 @@ use numext_fixed_hash::H256;
use rand::random;
use serde_derive::{Deserialize, Serialize};
use std::thread;
use std::time::{Duration, SystemTime};
use std::time::{Duration, Instant};

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct CuckooSimpleConfig {
Expand Down Expand Up @@ -149,39 +149,39 @@ fn path(graph: &[u64], start: u64) -> Vec<u64> {
path
}

const STATE_UPDATE_INTERVAL: usize = 16;
const STATE_UPDATE_DURATION_MILLIS: u128 = 500;

impl Worker for CuckooSimple {
fn run(&mut self, progress_bar: ProgressBar) {
let mut state_update_counter = 0usize;
let mut start = SystemTime::now();
let mut start = Instant::now();
loop {
self.poll_worker_message();
if self.start {
if let Some(pow_hash) = self.pow_hash.clone() {
self.solve(&pow_hash, random());
state_update_counter += 1;

if state_update_counter == STATE_UPDATE_INTERVAL {
let elapsed = SystemTime::now().duration_since(start).unwrap();
let elapsed = start.elapsed();
if elapsed.as_millis() > STATE_UPDATE_DURATION_MILLIS {
let elapsed_nanos: f64 = (elapsed.as_secs() * 1_000_000_000
+ u64::from(elapsed.subsec_nanos()))
as f64
/ 1_000_000_000.0;
progress_bar.set_message(&format!(
"gps: {:>10.3} / cycles found: {:>10}",
STATE_UPDATE_INTERVAL as f64 / elapsed_nanos,
state_update_counter as f64 / elapsed_nanos,
self.seal_candidates_found,
));
progress_bar.inc(1);
state_update_counter = 0;
start = SystemTime::now();
start = Instant::now();
}
}
} else {
// reset state and sleep
state_update_counter = 0;
start = SystemTime::now();
start = Instant::now();
thread::sleep(Duration::from_millis(100));
}
}
Expand Down
61 changes: 54 additions & 7 deletions util/app-config/src/sentry_config.rs
@@ -1,35 +1,82 @@
use build_info::Version;
use sentry::{
configure_scope, init,
integrations::panic::register_panic_handler,
internals::{ClientInitGuard, Dsn},
protocol::Event,
ClientOptions,
};
use serde_derive::{Deserialize, Serialize};
use std::borrow::Cow;
use std::sync::Arc;

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct SentryConfig {
pub dsn: String,
}

impl SentryConfig {
pub fn init(&self, version: &Version) -> sentry::internals::ClientInitGuard {
let guard = sentry::init(self.build_sentry_client_options(&version));
pub fn init(&self, version: &Version) -> ClientInitGuard {
let guard = init(self.build_sentry_client_options(&version));
if guard.is_enabled() {
sentry::configure_scope(|scope| {
configure_scope(|scope| {
scope.set_tag("release.pre", version.is_pre());
scope.set_tag("release.dirty", version.is_dirty());
});

sentry::integrations::panic::register_panic_handler();
register_panic_handler();
}

guard
}

pub fn is_enabled(&self) -> bool {
self.dsn.parse::<sentry::internals::Dsn>().is_ok()
self.dsn.parse::<Dsn>().is_ok()
}

fn build_sentry_client_options(&self, version: &Version) -> sentry::ClientOptions {
sentry::ClientOptions {
fn build_sentry_client_options(&self, version: &Version) -> ClientOptions {
ClientOptions {
dsn: self.dsn.parse().ok(),
release: Some(version.long().into()),
before_send: Some(Arc::new(Box::new(before_send))),
..Default::default()
}
}
}

static DB_OPEN_FINGERPRINT: &[Cow<'static, str>] =
&[Cow::Borrowed("ckb-db"), Cow::Borrowed("open")];
static SQLITE_FINGERPRINT: &[Cow<'static, str>] = &[
Cow::Borrowed("ckb-network"),
Cow::Borrowed("peerstore"),
Cow::Borrowed("sqlite"),
];

fn before_send(mut event: Event<'static>) -> Option<Event<'static>> {
let ex = match event
.exception
.values
.iter()
.next()
.and_then(|ex| ex.value.as_ref())
{
Some(ex) => ex,
None => return Some(event),
};

// Group events via fingerprint, or ignore

if ex.starts_with("DBError failed to open the database") {
event.fingerprint = Cow::Borrowed(DB_OPEN_FINGERPRINT);
} else if ex.contains("SqliteFailure") {
event.fingerprint = Cow::Borrowed(SQLITE_FINGERPRINT);
} else if ex.starts_with("DBError the database version")
|| ex.contains("kind: AddrInUse")
|| ex.contains("kind: AddrNotAvailable")
{
// ignore
return None;
}

Some(event)
}

0 comments on commit 188b848

Please sign in to comment.