diff --git a/.travis.yml b/.travis.yml index f15ed451d92..0a7ec8e9088 100644 --- a/.travis.yml +++ b/.travis.yml @@ -80,6 +80,11 @@ matrix: - make check-cargotoml - make check-whitespaces - make check-dirty-rpc-doc + - name: Security Audit + if: 'tag IS NOT present AND (type = pull_request OR branch in (master, staging, trying) OR repo != nervosnetwork/ckb)' + os: linux + rust: nightly + script: make security-audit - name: Test benchmarks on Linux env: CACHE_NAME=bench diff --git a/Makefile b/Makefile index f58ec2f5b82..b199bb380b1 100644 --- a/Makefile +++ b/Makefile @@ -107,8 +107,8 @@ clippy: setup-ckb-test ## Run linter to examine Rust source codes. .PHONY: security-audit security-audit: ## Use cargo-audit to audit Cargo.lock for crates with security vulnerabilities. - @cargo audit --version || cargo install cargo-audit - @cargo audit + @cargo +nightly install cargo-audit -Z install-upgrade + cargo audit # expecting to see "Success No vulnerable packages found" .PHONY: bench-test diff --git a/README.md b/README.md index ef0e3253cf0..597f73db732 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ TBD. ## Mining -Mining on testnet Rylai is for testing purpose only, the mining algorithm **WILL BE CHANGED SOON**. +Testnet Rylai uses the [Eaglesong](https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0010-eaglesong/0010-eaglesong.md) mining algorithm, which the mainnet is going to use too. Mining on testnet is for testing purpose only. At this time Rylai will be **RESET** every two weeks. diff --git a/rpc/README.md b/rpc/README.md index 311a57679ac..1014c52d912 100644 --- a/rpc/README.md +++ b/rpc/README.md @@ -1533,10 +1533,10 @@ http://localhost:8114 }, "hash": "0x076049e2cc6b9f1ed4bb27b2337c55071dabfaf0183b1b17a4965bd0372d8dec" }, + "compact_target": "0x100", "current_time": "0x16d6269e84f", "cycles_limit": "0x2540be400", "dao": "0x004fb9e277860700b2f80165348723003d1862ec960000000028eb3d7e7a0100", - "difficulty": "0x100", "epoch": "0x3e80001000000", "number": "0x1", "parent_hash": "0xd5c495b7dd4d9d066a6a4d4356bc31955ad3199e0d856f34cfbe159c46ee335b", diff --git a/rpc/json/rpc.json b/rpc/json/rpc.json index 1401a6bf6d5..2fed776e35a 100644 --- a/rpc/json/rpc.json +++ b/rpc/json/rpc.json @@ -1304,7 +1304,7 @@ "current_time": "0x16d6269e84f", "cycles_limit": "0x2540be400", "dao": "0x004fb9e277860700b2f80165348723003d1862ec960000000028eb3d7e7a0100", - "difficulty": "0x100", + "compact_target": "0x100", "epoch": "0x3e80001000000", "number": "0x1", "parent_hash": "0xd5c495b7dd4d9d066a6a4d4356bc31955ad3199e0d856f34cfbe159c46ee335b", diff --git a/spec/src/consensus.rs b/spec/src/consensus.rs index 90ac1daff13..91b55e5217d 100644 --- a/spec/src/consensus.rs +++ b/spec/src/consensus.rs @@ -24,8 +24,9 @@ use ckb_types::{ use std::cmp; use std::sync::Arc; -// TODO: add secondary reward for miner +// 1.344 billion per year pub(crate) const DEFAULT_SECONDARY_EPOCH_REWARD: Capacity = Capacity::shannons(613_698_63013698); +// 4.2 billion per year pub(crate) const INITIAL_PRIMARY_EPOCH_REWARD: Capacity = Capacity::shannons(1_917_808_21917808); const MAX_UNCLE_NUM: usize = 2; pub(crate) const TX_PROPOSAL_WINDOW: ProposalWindow = ProposalWindow(2, 10); @@ -34,7 +35,7 @@ pub(crate) const TX_PROPOSAL_WINDOW: ProposalWindow = ProposalWindow(2, 10); // This is to reduce the risk of later txs being reversed if a chain reorganization occurs. pub(crate) const CELLBASE_MATURITY: EpochNumberWithFraction = EpochNumberWithFraction::new_unchecked(4, 0, 1); -// TODO: should adjust this value based on CKB average block time + const MEDIAN_TIME_BLOCK_COUNT: usize = 37; // dampening factor diff --git a/test/src/main.rs b/test/src/main.rs index 745d6ec03fe..fa4f4c620bb 100644 --- a/test/src/main.rs +++ b/test/src/main.rs @@ -286,6 +286,7 @@ fn all_specs() -> SpecMap { Box::new(ProposeButNotCommit), Box::new(ProposeDuplicated), Box::new(ForkedTransaction), + Box::new(MissingUncleRequest), ]; specs.into_iter().map(|spec| (spec.name(), spec)).collect() } diff --git a/test/src/node.rs b/test/src/node.rs index 95209235dc5..b75cff5ce39 100644 --- a/test/src/node.rs +++ b/test/src/node.rs @@ -461,11 +461,6 @@ impl Node { message: Default::default(), }); - if ::std::env::var("CI").is_ok() { - ckb_config.logger.filter = - Some(::std::env::var("CKB_LOG").unwrap_or_else(|_| "info".to_string())); - } - modify_ckb_config(&mut ckb_config); fs::write( &ckb_config_path, diff --git a/test/src/specs/relay/get_block_transactions_process.rs b/test/src/specs/relay/get_block_transactions_process.rs new file mode 100644 index 00000000000..65334d30549 --- /dev/null +++ b/test/src/specs/relay/get_block_transactions_process.rs @@ -0,0 +1,77 @@ +use crate::{Net, Spec, TestProtocol}; +use ckb_sync::NetworkProtocol; +use ckb_types::{ + core::UncleBlockView, + packed::{self, RelayMessage}, + prelude::*, +}; + +pub struct MissingUncleRequest; + +impl Spec for MissingUncleRequest { + crate::name!("missing_uncle_request"); + + crate::setup!(protocols: vec![TestProtocol::sync(), TestProtocol::relay()]); + + // Case: Send to node GetBlockTransactions with missing uncle index, node should response BlockTransactions with uncles + fn run(&self, net: &mut Net) { + net.exit_ibd_mode(); + let node = &net.nodes[0]; + net.connect(node); + let (peer_id, _, _) = net.receive(); + + node.generate_block(); + let _ = net.receive(); + + let builder = node.new_block_builder(None, None, None); + let block1 = builder.clone().nonce(0.pack()).build(); + let block2 = builder.clone().nonce(1.pack()).build(); + node.submit_block(&block1.data()); + node.submit_block(&block2.data()); + + let builder = node.new_block_builder(None, None, None); + let block = builder + .clone() + .set_uncles(vec![block2.as_uncle()]) + .nonce(0.pack()) + .build(); + node.submit_block(&block.data()); + + let content = packed::GetBlockTransactions::new_builder() + .block_hash(block.hash()) + .uncle_indexes(vec![0u32].pack()) + .build(); + let message = packed::RelayMessage::new_builder().set(content).build(); + + (0..3).for_each(|_| { + net.receive(); // ignore three new block announce + }); + + net.send( + NetworkProtocol::RELAY.into(), + peer_id, + message.as_slice().into(), + ); + + let (_, _, data) = net.receive(); + let message = RelayMessage::from_slice(&data).unwrap(); + + assert_eq!( + message.to_enum().item_name(), + packed::BlockTransactions::NAME, + "Node should reponse BlockTransactions message", + ); + + if let packed::RelayMessageUnionReader::BlockTransactions(reader) = + message.to_enum().as_reader() + { + let block_transactions = reader.to_entity(); + let received_uncles: Vec = block_transactions + .uncles() + .into_iter() + .map(|uncle| uncle.into_view()) + .collect(); + assert_eq!(received_uncles[0], block2.as_uncle()); + } + } +} diff --git a/test/src/specs/relay/mod.rs b/test/src/specs/relay/mod.rs index 2f47d792f8b..a07082d0b6c 100644 --- a/test/src/specs/relay/mod.rs +++ b/test/src/specs/relay/mod.rs @@ -1,7 +1,9 @@ mod block_relay; mod compact_block; +mod get_block_transactions_process; mod transaction_relay; pub use block_relay::*; pub use compact_block::*; +pub use get_block_transactions_process::*; pub use transaction_relay::*; diff --git a/test/src/specs/sync/ibd_process.rs b/test/src/specs/sync/ibd_process.rs index ee2b02c7c59..a5176c9dca7 100644 --- a/test/src/specs/sync/ibd_process.rs +++ b/test/src/specs/sync/ibd_process.rs @@ -139,6 +139,17 @@ impl Spec for IBDProcessWithWhiteList { } node6.disconnect(node0); + + // Make sure both sides are disconnected + let is_disconnect_already = wait_until(10, || { + let peers = rpc_client0.get_peers(); + peers.iter().any(|peer| peer.node_id == node6.node_id()) + }); + + if is_disconnect_already { + panic!("node6 can't disconnect with node0"); + } + node6.generate_blocks(2); let generate_res = wait_until(10, || net.nodes[6].get_tip_block_number() == 2); @@ -147,7 +158,8 @@ impl Spec for IBDProcessWithWhiteList { panic!("node6 can't generate blocks to 2"); } - node0.connect_uncheck(node6); + // Make sure node0 re-connect with node6 + node0.connect(node6); // IBD only with outbound/whitelist node let rpc_client1 = node1.rpc_client(); diff --git a/test/src/specs/tx_pool/reference_header_maturity.rs b/test/src/specs/tx_pool/reference_header_maturity.rs index b4f6e5d509d..2da401da6fe 100644 --- a/test/src/specs/tx_pool/reference_header_maturity.rs +++ b/test/src/specs/tx_pool/reference_header_maturity.rs @@ -108,6 +108,8 @@ impl Spec for ReferenceHeaderMaturity { fn modify_chain_spec(&self) -> Box ()> { Box::new(|spec_config| { spec_config.params.cellbase_maturity = CELLBASE_MATURITY_VALUE; + spec_config.params.epoch_duration_target = 30; + spec_config.params.genesis_epoch_length = 5; }) } }