Skip to content

Commit

Permalink
Merge branch 'merge-v0.15.4-to-develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
doitian committed Jul 4, 2019
2 parents 36d596b + f0c08be commit a02c675
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 26 deletions.
16 changes: 15 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [v0.15.3](https://github.com/nervosnetwork/ckb/compare/v0.15.0...v0.15.3) (2019-07-01)
# [v0.15.4](https://github.com/nervosnetwork/ckb/compare/v0.15.3...v0.15.4) (2019-07-04)

### Features

* #1151: Allow providing extra sentry info in config (@doitian)

### Bug Fixes

* #1164: Ban peer when validate received block failed (@TheWaWaR)
* #1167: Proposal reward calculate consistency (@zhangsoledad)
* #1169: Only sync with outbound peer in IBD mode (@quake)


# [v0.15.3](https://github.com/nervosnetwork/ckb/compare/v0.15.0...v0.15.3) (2019-07-02)

### Bug Fixes

Expand All @@ -11,6 +24,7 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
Node should fetch download from all peers which have better chain,
no matter it's known best's ancestor or not.


# [v0.15.0](https://github.com/nervosnetwork/ckb/compare/v0.14.2...v0.15.0) (2019-06-29)

**Important:** The default secp256k1 has changed. Now its code hash is
Expand Down
2 changes: 1 addition & 1 deletion chain/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ impl<CS: ChainStore + 'static> ChainService<CS> {
}
}
Err(err) => {
error!("block {}", serde_json::to_string(b).unwrap());
error!("block {:?} verify error{:?}", b, err);
found_error =
Some(SharedError::InvalidTransaction(err.to_string()));
*verified = Some(false);
Expand Down
3 changes: 3 additions & 0 deletions resource/ckb-miner.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ log_to_stdout = true # {{
dsn = "" # {{
# testnet => dsn = "https://48c6a88d92e246478e2d53b5917a887c@sentry.io/1422795"
# }}
# if you are willing to help us to improve,
# please leave a way to contact you when we have troubles to reproduce the errors.
# org_contact = ""

[miner.client]
rpc_url = "http://127.0.0.1:8114/" # {{
Expand Down
3 changes: 3 additions & 0 deletions resource/ckb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ log_to_stdout = true # {{
dsn = "" # {{
# testnet => dsn = "https://48c6a88d92e246478e2d53b5917a887c@sentry.io/1422795"
# }}
# if you are willing to help us to improve,
# please leave a way to contact you when we have troubles to reproduce the errors.
# org_contact = ""

[network]
listen_addresses = ["/ip4/0.0.0.0/tcp/8115"] # {{
Expand Down
1 change: 1 addition & 0 deletions sync/src/relayer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ impl<CS: ChainStore + 'static> Relayer<CS> {
if self
.shared()
.insert_new_block(&self.chain, peer, Arc::clone(&boxed))
.is_ok()
{
debug_target!(
crate::LOG_TARGET_RELAY,
Expand Down
23 changes: 18 additions & 5 deletions sync/src/synchronizer/block_process.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::synchronizer::Synchronizer;
use crate::{synchronizer::Synchronizer, BAD_MESSAGE_BAN_TIME};
use ckb_core::block::Block;
use ckb_logger::debug;
use ckb_logger::{debug, info};
use ckb_network::{CKBProtocolContext, PeerIndex};
use ckb_protocol::Block as PBlock;
use ckb_store::ChainStore;
Expand All @@ -11,6 +11,7 @@ pub struct BlockProcess<'a, CS: ChainStore + 'a> {
message: &'a PBlock<'a>,
synchronizer: &'a Synchronizer<CS>,
peer: PeerIndex,
nc: &'a CKBProtocolContext,
}

impl<'a, CS> BlockProcess<'a, CS>
Expand All @@ -21,12 +22,13 @@ where
message: &'a PBlock,
synchronizer: &'a Synchronizer<CS>,
peer: PeerIndex,
_nc: &'a CKBProtocolContext,
nc: &'a CKBProtocolContext,
) -> Self {
BlockProcess {
message,
synchronizer,
peer,
nc,
}
}

Expand All @@ -38,9 +40,20 @@ where
block.header().hash()
);

if self.synchronizer.shared().new_block_received(&block) {
self.synchronizer.process_new_block(self.peer, block);
if self.synchronizer.shared().new_block_received(&block)
&& self
.synchronizer
.process_new_block(self.peer, block)
.is_err()
{
info!(
"Ban peer {:?} for {} seconds because send us a invalid block",
self.peer,
BAD_MESSAGE_BAN_TIME.as_secs()
);
self.nc.ban_peer(self.peer, BAD_MESSAGE_BAN_TIME);
}

Ok(())
}
}
17 changes: 9 additions & 8 deletions sync/src/synchronizer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,16 @@ impl<CS: ChainStore> Synchronizer<CS> {
}

//TODO: process block which we don't request
pub fn process_new_block(&self, peer: PeerIndex, block: Block) {
pub fn process_new_block(&self, peer: PeerIndex, block: Block) -> Result<(), FailureError> {
if self.shared().contains_orphan_block(block.header()) {
debug!("block {:x} already in orphan pool", block.header().hash());
return;
return Ok(());
}

match self.shared().get_block_status(&block.header().hash()) {
BlockStatus::VALID_MASK => {
self.shared()
.insert_new_block(&self.chain, peer, Arc::new(block));
.insert_new_block(&self.chain, peer, Arc::new(block))?;
}
status => {
debug!(
Expand All @@ -168,6 +168,7 @@ impl<CS: ChainStore> Synchronizer<CS> {
);
}
}
Ok(())
}

pub fn get_blocks_to_fetch(&self, peer: PeerIndex) -> Option<Vec<H256>> {
Expand Down Expand Up @@ -297,12 +298,13 @@ impl<CS: ChainStore> Synchronizer<CS> {

fn start_sync_headers(&self, nc: &CKBProtocolContext) {
let now = unix_time_as_millis();
let ibd = self.shared().is_initial_block_download();
let peers: Vec<PeerIndex> = self
.peers()
.state
.read()
.iter()
.filter(|(_, state)| state.can_sync(now))
.filter(|(_, state)| state.can_sync(now, ibd))
.map(|(peer_id, _)| peer_id)
.cloned()
.collect();
Expand Down Expand Up @@ -332,9 +334,7 @@ impl<CS: ChainStore> Synchronizer<CS> {

for peer in peers {
// Only sync with 1 peer if we're in IBD
if self.shared.is_initial_block_download()
&& self.shared().n_sync_started().load(Ordering::Acquire) != 0
{
if ibd && self.shared().n_sync_started().load(Ordering::Acquire) != 0 {
break;
}
{
Expand Down Expand Up @@ -866,7 +866,8 @@ mod tests {
blocks.into_iter().for_each(|block| {
synchronizer
.shared()
.insert_new_block(&synchronizer.chain, peer, Arc::new(block));
.insert_new_block(&synchronizer.chain, peer, Arc::new(block))
.expect("Insert new block failed");
});
assert_eq!(
chain1_last_block.header(),
Expand Down
18 changes: 10 additions & 8 deletions sync/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use ckb_core::extras::EpochExt;
use ckb_core::header::{BlockNumber, Header};
use ckb_core::transaction::ProposalShortId;
use ckb_core::Cycle;
use ckb_logger::{debug, debug_target, error};
use ckb_logger::{debug, debug_target};
use ckb_network::{CKBProtocolContext, PeerIndex};
use ckb_protocol::SyncMessage;
use ckb_shared::chain_state::ChainState;
Expand Down Expand Up @@ -121,8 +121,10 @@ impl PeerState {
}
}

pub fn can_sync(&self, now: u64) -> bool {
!self.sync_started
pub fn can_sync(&self, now: u64, ibd: bool) -> bool {
// only sync with outbound peer in IBD
(self.is_outbound || !ibd)
&& !self.sync_started
&& self
.chain_sync
.not_sync_until
Expand Down Expand Up @@ -1096,7 +1098,7 @@ impl<CS: ChainStore> SyncSharedState<CS> {
chain: &ChainController,
pi: PeerIndex,
block: Arc<Block>,
) -> bool {
) -> Result<(), FailureError> {
let known_parent = |block: &Block| {
self.store()
.get_block_header(block.header().parent_hash())
Expand All @@ -1111,13 +1113,13 @@ impl<CS: ChainStore> SyncSharedState<CS> {
block.header().hash()
);
self.insert_orphan_block((*block).clone());
return false;
return Ok(());
}

// Attempt to accept the given block if its parent already exist in database
if let Err(err) = self.accept_block(chain, pi, Arc::clone(&block)) {
error!("accept block {:?} error {:?}", block, err);
return false;
debug!("accept block {:?} error {:?}", block, err);
return Err(err);
}

// The above block has been accepted. Attempt to accept its descendant blocks in orphan pool.
Expand Down Expand Up @@ -1146,7 +1148,7 @@ impl<CS: ChainStore> SyncSharedState<CS> {
}
}

true
Ok(())
}

fn accept_block(
Expand Down
12 changes: 11 additions & 1 deletion util/app-config/src/sentry_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use sentry::{
integrations::panic::register_panic_handler,
internals::{ClientInitGuard, Dsn},
protocol::Event,
ClientOptions,
ClientOptions, Level,
};
use serde_derive::{Deserialize, Serialize};
use std::borrow::Cow;
Expand All @@ -13,6 +13,8 @@ use std::sync::Arc;
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct SentryConfig {
pub dsn: String,
pub org_ident: Option<String>,
pub org_contact: Option<String>,
}

impl SentryConfig {
Expand All @@ -22,6 +24,12 @@ impl SentryConfig {
configure_scope(|scope| {
scope.set_tag("release.pre", version.is_pre());
scope.set_tag("release.dirty", version.is_dirty());
if let Some(org_ident) = &self.org_ident {
scope.set_tag("org_ident", org_ident);
}
if let Some(org_contact) = &self.org_contact {
scope.set_extra("org_contact", org_contact.clone().into());
}
});

register_panic_handler();
Expand Down Expand Up @@ -67,8 +75,10 @@ fn before_send(mut event: Event<'static>) -> Option<Event<'static>> {
// Group events via fingerprint, or ignore

if ex.starts_with("DBError failed to open the database") {
event.level = Level::Warning;
event.fingerprint = Cow::Borrowed(DB_OPEN_FINGERPRINT);
} else if ex.contains("SqliteFailure") {
event.level = Level::Warning;
event.fingerprint = Cow::Borrowed(SQLITE_FINGERPRINT);
} else if ex.starts_with("DBError the database version")
|| ex.contains("kind: AddrInUse")
Expand Down
4 changes: 2 additions & 2 deletions util/reward-calculator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ impl<'a, P: ChainProvider> RewardCalculator<'a, P> {
cmp::max(index.number().saturating_sub(proposal_window.farthest()), 1);

let previous_ids = store
.get_block_hash(competing_proposal_start)
.map(|hash| self.get_proposal_ids_by_hash(&hash))
.get_ancestor(parent.hash(), competing_proposal_start)
.map(|header| self.get_proposal_ids_by_hash(header.hash()))
.expect("finalize target exist");

proposed.extend(previous_ids);
Expand Down

0 comments on commit a02c675

Please sign in to comment.