Skip to content

Commit

Permalink
Merge #3134
Browse files Browse the repository at this point in the history
3134: ckb2021 on rust2021 r=yangby-cryptape,quake a=zhangsoledad

<!--
Thank you for contributing to nervosnetwork/ckb!

If you haven't already, please read [CONTRIBUTING](https://github.com/nervosnetwork/ckb/blob/develop/CONTRIBUTING.md) document.

If you're unsure about anything, just ask; somebody should be along to answer within a day or two.

PR Title Format:
1. module [, module2, module3]: what's changed
2. *: what's changed
-->

### What is changed and how it works?

Upgrate rust toolchain to 1.56.1, and switch to 2021 edition.

### Check List <!--REMOVE the items that are not applicable-->

Tests <!-- At least one of them must be included. -->

- Unit test
- Integration test


### Release note <!-- Choose from None, Title Only and Note. Bugfixes or new features need a release note. -->

```release-note
Title Only: Include only the PR title in the release note.
```



Co-authored-by: zhangsoledad <787953403@qq.com>
  • Loading branch information
bors[bot] and zhangsoledad committed Dec 15, 2021
2 parents 25732ad + 162d029 commit e0c4900
Show file tree
Hide file tree
Showing 228 changed files with 931 additions and 809 deletions.
2 changes: 1 addition & 1 deletion .cargo/config
@@ -1,7 +1,7 @@
[cargo-new]
name = "Nervos Core Dev"
email = "dev@nervos.org"
edition = "2018"
edition = "2021"

[target.aarch64-unknown-linux-gnu]
linker = "aarch64-linux-gnu-gcc"
4 changes: 2 additions & 2 deletions Cargo.toml
Expand Up @@ -3,12 +3,12 @@ name = "ckb"
version = "0.102.0-pre"
license = "MIT"
authors = ["Nervos Core Dev <dev@nervos.org>"]
edition = "2018"
edition = "2021"
build = "build.rs"
description = "CKB is the layer 1 of Nervos Network, a public/permissionless blockchain."
homepage = "https://github.com/nervosnetwork/ckb"
repository = "https://github.com/nervosnetwork/ckb"
resolver = "2"
rust-version = "1.56.1"

[build-dependencies]
ckb-build-info = { path = "util/build-info", version = "= 0.102.0-pre" }
Expand Down
5 changes: 0 additions & 5 deletions README.md
Expand Up @@ -52,11 +52,6 @@ The `master` branch is regularly built and tested. It is considered already prod

The contribution workflow is described in [CONTRIBUTING.md](CONTRIBUTING.md), and security policy is described in [SECURITY.md](SECURITY.md). To propose new protocol or standard for Nervos, see [Nervos RFC](https://github.com/nervosnetwork/rfcs).


## Minimum Supported Rust Version policy (MSRV)

The crate `ckb`'s minimum supported rustc version is 1.51.0.

---

## Documentations
Expand Down
2 changes: 1 addition & 1 deletion benches/Cargo.toml
Expand Up @@ -3,7 +3,7 @@ name = "ckb-benches"
version = "0.102.0-pre"
license = "MIT"
authors = ["Nervos Core Dev <dev@nervos.org>"]
edition = "2018"
edition = "2021"
description = "CKB benchmarks."
homepage = "https://github.com/nervosnetwork/ckb"
repository = "https://github.com/nervosnetwork/ckb"
Expand Down
8 changes: 4 additions & 4 deletions benches/benches/benchmarks/always_success.rs
Expand Up @@ -75,7 +75,7 @@ fn bench(c: &mut Criterion) {
.unwrap()];
let mut parent = blocks[0].clone();
(0..5).for_each(|i| {
let block = gen_always_success_block(&mut blocks, &parent, &shared2);
let block = gen_always_success_block(&mut blocks, &parent, shared2);
chain2
.internal_process_block(
Arc::new(block.clone()),
Expand All @@ -94,7 +94,7 @@ fn bench(c: &mut Criterion) {
});
let mut parent = blocks[2].clone();
(0..2).for_each(|_| {
let block = gen_always_success_block(&mut blocks, &parent, &shared3);
let block = gen_always_success_block(&mut blocks, &parent, shared3);
chain3
.internal_process_block(
Arc::new(block.clone()),
Expand Down Expand Up @@ -149,7 +149,7 @@ fn bench(c: &mut Criterion) {
.unwrap()];
let mut parent = blocks[0].clone();
(0..5).for_each(|i| {
let block = gen_always_success_block(&mut blocks, &parent, &shared2);
let block = gen_always_success_block(&mut blocks, &parent, shared2);
let arc_block = Arc::new(block.clone());
chain2
.internal_process_block(Arc::clone(&arc_block), Switch::DISABLE_ALL)
Expand All @@ -163,7 +163,7 @@ fn bench(c: &mut Criterion) {
});
let mut parent = blocks[2].clone();
(0..4).for_each(|_| {
let block = gen_always_success_block(&mut blocks, &parent, &shared3);
let block = gen_always_success_block(&mut blocks, &parent, shared3);
chain3
.internal_process_block(
Arc::new(block.clone()),
Expand Down
3 changes: 1 addition & 2 deletions benches/benches/benchmarks/overall.rs
Expand Up @@ -24,7 +24,6 @@ use ckb_verification::HeaderVerifier;
use ckb_verification_traits::Verifier;
use criterion::{criterion_group, BatchSize, BenchmarkId, Criterion};
use rand::random;
use std::convert::TryFrom;
use std::sync::Arc;

#[cfg(not(feature = "ci"))]
Expand Down Expand Up @@ -200,7 +199,7 @@ fn bench(c: &mut Criterion) {
let block = raw_block.as_builder().header(header).build().into_view();

let header_verifier =
HeaderVerifier::new(snapshot.as_ref(), &shared.consensus());
HeaderVerifier::new(snapshot.as_ref(), shared.consensus());
header_verifier
.verify(&block.header())
.expect("header verified");
Expand Down
5 changes: 2 additions & 3 deletions benches/benches/benchmarks/resolve.rs
Expand Up @@ -20,7 +20,6 @@ use ckb_types::{
};
use criterion::{criterion_group, BatchSize, BenchmarkId, Criterion};
use std::collections::HashSet;
use std::convert::TryFrom;

#[cfg(not(feature = "ci"))]
const SIZE: usize = 500;
Expand Down Expand Up @@ -127,7 +126,7 @@ fn bench(c: &mut Criterion) {
|(shared, _)| {
let mut i = 100;
let snapshot: &Snapshot = &shared.snapshot();
let txs = gen_txs_from_genesis(&shared.consensus().genesis_block());
let txs = gen_txs_from_genesis(shared.consensus().genesis_block());

while i > 0 {
let mut seen_inputs = HashSet::new();
Expand All @@ -153,7 +152,7 @@ fn bench(c: &mut Criterion) {
|(shared, _)| {
let mut i = 1;
let snapshot: &Snapshot = &shared.snapshot();
let txs = gen_txs_from_genesis(&shared.consensus().genesis_block());
let txs = gen_txs_from_genesis(shared.consensus().genesis_block());

let mut seen_inputs = HashSet::new();
let rtxs: Vec<_> = txs
Expand Down
8 changes: 4 additions & 4 deletions benches/benches/benchmarks/secp_2in2out.rs
Expand Up @@ -75,7 +75,7 @@ fn bench(c: &mut Criterion) {
.unwrap()];
let mut parent = blocks[0].clone();
(0..5).for_each(|i| {
let block = gen_secp_block(&mut blocks, &parent, &shared2);
let block = gen_secp_block(&mut blocks, &parent, shared2);
chain2
.internal_process_block(
Arc::new(block.clone()),
Expand All @@ -94,7 +94,7 @@ fn bench(c: &mut Criterion) {
});
let mut parent = blocks[2].clone();
(0..2).for_each(|_| {
let block = gen_secp_block(&mut blocks, &parent, &shared3);
let block = gen_secp_block(&mut blocks, &parent, shared3);
chain3
.internal_process_block(
Arc::new(block.clone()),
Expand Down Expand Up @@ -149,7 +149,7 @@ fn bench(c: &mut Criterion) {
.unwrap()];
let mut parent = blocks[0].clone();
(0..5).for_each(|i| {
let block = gen_secp_block(&mut blocks, &parent, &shared2);
let block = gen_secp_block(&mut blocks, &parent, shared2);
let arc_block = Arc::new(block.clone());
chain2
.internal_process_block(Arc::clone(&arc_block), Switch::DISABLE_ALL)
Expand All @@ -163,7 +163,7 @@ fn bench(c: &mut Criterion) {
});
let mut parent = blocks[2].clone();
(0..4).for_each(|_| {
let block = gen_secp_block(&mut blocks, &parent, &shared3);
let block = gen_secp_block(&mut blocks, &parent, shared3);
chain3
.internal_process_block(
Arc::new(block.clone()),
Expand Down
4 changes: 2 additions & 2 deletions benches/benches/benchmarks/util.rs
Expand Up @@ -462,7 +462,7 @@ pub fn create_2out_transaction(
for w in &non_sig_witnesses {
let len: u64 = w.len() as u64;
blake2b.update(&len.to_le_bytes());
blake2b.update(&w);
blake2b.update(w);
}
blake2b.finalize(&mut message);
let message = H256::from(message);
Expand Down Expand Up @@ -501,7 +501,7 @@ pub fn dao_data(shared: &Shared, parent: &HeaderView, txs: &[TransactionView]) -
let data_loader = snapshot.as_data_provider();
let calculator = DaoCalculator::new(snapshot.consensus(), &data_loader);
calculator
.dao_field(&rtxs, &parent)
.dao_field(&rtxs, parent)
.expect("calculator dao_field")
}

Expand Down
2 changes: 1 addition & 1 deletion chain/Cargo.toml
Expand Up @@ -3,7 +3,7 @@ name = "ckb-chain"
version = "0.102.0-pre"
license = "MIT"
authors = ["Nervos Core Dev <dev@nervos.org>"]
edition = "2018"
edition = "2021"
description = "CKB Blockchain Service, Importing Blocks"
homepage = "https://github.com/nervosnetwork/ckb"
repository = "https://github.com/nervosnetwork/ckb"
Expand Down
10 changes: 5 additions & 5 deletions chain/src/chain.rs
Expand Up @@ -295,7 +295,7 @@ impl ChainService {
db_txn.insert_current_epoch_ext(&target_epoch_ext)?;

for blk in fork.attached_blocks() {
db_txn.delete_block(&blk)?;
db_txn.delete_block(blk)?;
}
db_txn.commit()?;

Expand Down Expand Up @@ -340,13 +340,13 @@ impl ChainService {

fn non_contextual_verify(&self, block: &BlockView) -> Result<(), Error> {
let consensus = self.shared.consensus();
BlockVerifier::new(consensus).verify(&block).map_err(|e| {
BlockVerifier::new(consensus).verify(block).map_err(|e| {
debug!("[process_block] BlockVerifier error {:?}", e);
e
})?;

NonContextualBlockTxsVerifier::new(consensus)
.verify(&block)
.verify(block)
.map_err(|e| {
debug!(
"[process_block] NonContextualBlockTxsVerifier error {:?}",
Expand Down Expand Up @@ -535,7 +535,7 @@ impl ChainService {
.insert(blk.header().number(), blk.union_proposal_ids());
}

self.reload_proposal_table(&fork);
self.reload_proposal_table(fork);
}

// if rollback happen, go back check whether need reload proposal_table from block
Expand Down Expand Up @@ -771,7 +771,7 @@ impl ChainService {
&resolved,
b,
Arc::clone(&txs_verify_cache),
&async_handle,
async_handle,
switch,
) {
Ok((cycles, cache_entries)) => {
Expand Down
4 changes: 2 additions & 2 deletions chain/src/tests/basic.rs
Expand Up @@ -130,7 +130,7 @@ fn test_transaction_spend_in_same_block() {

let last_cellbase = &shared.consensus().genesis_block().transactions()[1];
let last_cellbase_hash = last_cellbase.hash();
let tx1 = create_multi_outputs_transaction(&last_cellbase, vec![0], 2, vec![1]);
let tx1 = create_multi_outputs_transaction(last_cellbase, vec![0], 2, vec![1]);
let tx1_hash = tx1.hash();
let tx2 = create_multi_outputs_transaction(&tx1, vec![0], 2, vec![2]);
let tx2_hash = tx2.hash();
Expand Down Expand Up @@ -255,7 +255,7 @@ fn test_transaction_conflict_in_different_blocks() {
chain.gen_empty_block(&mock_store);

let last_cellbase = &shared.consensus().genesis_block().transactions()[1];
let tx1 = create_multi_outputs_transaction(&last_cellbase, vec![0], 2, vec![1]);
let tx1 = create_multi_outputs_transaction(last_cellbase, vec![0], 2, vec![1]);
let tx1_hash = tx1.hash();
let tx2 = create_multi_outputs_transaction(&tx1, vec![0], 2, vec![1]);
let tx3 = create_multi_outputs_transaction(&tx1, vec![0], 2, vec![2]);
Expand Down
2 changes: 1 addition & 1 deletion chain/src/tests/block_assembler.rs
Expand Up @@ -84,7 +84,7 @@ fn test_get_block_template() {

let header_verify_result = {
let snapshot: &Snapshot = &shared.snapshot();
let header_verifier = HeaderVerifier::new(snapshot, &shared.consensus());
let header_verifier = HeaderVerifier::new(snapshot, shared.consensus());
header_verifier.verify(&header)
};
assert!(header_verify_result.is_ok());
Expand Down
2 changes: 1 addition & 1 deletion chain/src/tests/cell.rs
Expand Up @@ -58,7 +58,7 @@ pub(crate) fn gen_block(

let epoch = shared
.consensus()
.next_epoch_ext(&parent_header, &shared.store().as_data_provider())
.next_epoch_ext(parent_header, &shared.store().as_data_provider())
.unwrap()
.epoch();

Expand Down
4 changes: 2 additions & 2 deletions chain/src/tests/delay_verify.rs
Expand Up @@ -87,7 +87,7 @@ fn test_dead_cell_in_different_block() {
}

let last_cellbase = &shared.consensus().genesis_block().transactions()[1];
let tx1 = create_multi_outputs_transaction(&last_cellbase, vec![0], 2, vec![1]);
let tx1 = create_multi_outputs_transaction(last_cellbase, vec![0], 2, vec![1]);
let tx1_hash = tx1.hash();
let tx2 = create_multi_outputs_transaction(&tx1, vec![0], 2, vec![2]);
let tx3 = create_multi_outputs_transaction(&tx1, vec![0], 2, vec![3]);
Expand Down Expand Up @@ -271,7 +271,7 @@ fn test_full_dead_transaction() {
chain2.push(block.clone());
mock_store.insert_block(&block, shared.consensus().genesis_epoch_ext());
let root_tx = &shared.consensus().genesis_block().transactions()[1];
let tx1 = create_multi_outputs_transaction(&root_tx, vec![0], 1, vec![1]);
let tx1 = create_multi_outputs_transaction(root_tx, vec![0], 1, vec![1]);

parent = block.header();
for i in 2..switch_fork_number {
Expand Down
2 changes: 1 addition & 1 deletion chain/src/tests/non_contextual_block_txs_verify.rs
Expand Up @@ -65,7 +65,7 @@ pub(crate) fn gen_block(

let epoch = shared
.consensus()
.next_epoch_ext(&parent_header, &shared.store().as_data_provider())
.next_epoch_ext(parent_header, &shared.store().as_data_provider())
.unwrap()
.epoch();

Expand Down
2 changes: 1 addition & 1 deletion chain/src/tests/reward.rs
Expand Up @@ -84,7 +84,7 @@ pub(crate) fn gen_block(

let epoch = shared
.consensus()
.next_epoch_ext(&parent_header, &shared.store().as_data_provider())
.next_epoch_ext(parent_header, &shared.store().as_data_provider())
.unwrap()
.epoch();

Expand Down
2 changes: 1 addition & 1 deletion chain/src/tests/txs_verify_cache.rs
Expand Up @@ -20,7 +20,7 @@ use ckb_verification_traits::Switch;
use faketime::unix_time_as_millis;
use lazy_static::lazy_static;

use std::{convert::TryInto as _, fs::File, io::Read as _, path::Path, sync::Arc};
use std::{fs::File, io::Read as _, path::Path, sync::Arc};

use crate::{
chain::{ChainController, ChainService},
Expand Down
16 changes: 8 additions & 8 deletions chain/src/tests/util.rs
Expand Up @@ -343,7 +343,7 @@ impl<'a> MockChain<'a> {
pub fn gen_block_with_proposal_txs(&mut self, txs: Vec<TransactionView>, store: &MockStore) {
let parent = self.tip_header();
let cellbase = create_cellbase(store, self.consensus, &parent);
let dao = dao_data(&self.consensus, &parent, &[cellbase.clone()], store, false);
let dao = dao_data(self.consensus, &parent, &[cellbase.clone()], store, false);

let epoch = self
.consensus
Expand Down Expand Up @@ -372,7 +372,7 @@ impl<'a> MockChain<'a> {
) {
let parent = self.tip_header();
let cellbase = create_cellbase(store, self.consensus, &parent);
let dao = dao_data(&self.consensus, &parent, &[cellbase.clone()], store, false);
let dao = dao_data(self.consensus, &parent, &[cellbase.clone()], store, false);

let new_block = BlockBuilder::default()
.parent_hash(parent.hash())
Expand All @@ -389,7 +389,7 @@ impl<'a> MockChain<'a> {
pub fn gen_empty_block_with_diff(&mut self, difficulty: u64, store: &MockStore) {
let parent = self.tip_header();
let cellbase = create_cellbase(store, self.consensus, &parent);
let dao = dao_data(&self.consensus, &parent, &[cellbase.clone()], store, false);
let dao = dao_data(self.consensus, &parent, &[cellbase.clone()], store, false);

let new_block = BlockBuilder::default()
.parent_hash(parent.hash())
Expand All @@ -406,7 +406,7 @@ impl<'a> MockChain<'a> {
let difficulty = self.difficulty();
let parent = self.tip_header();
let cellbase = create_cellbase(store, self.consensus, &parent);
let dao = dao_data(&self.consensus, &parent, &[cellbase.clone()], store, false);
let dao = dao_data(self.consensus, &parent, &[cellbase.clone()], store, false);

let new_block = BlockBuilder::default()
.parent_hash(parent.hash())
Expand All @@ -422,7 +422,7 @@ impl<'a> MockChain<'a> {
pub fn gen_empty_block_with_nonce(&mut self, nonce: u128, store: &MockStore) {
let parent = self.tip_header();
let cellbase = create_cellbase(store, self.consensus, &parent);
let dao = dao_data(&self.consensus, &parent, &[cellbase.clone()], store, false);
let dao = dao_data(self.consensus, &parent, &[cellbase.clone()], store, false);

let epoch = self
.consensus
Expand All @@ -446,7 +446,7 @@ impl<'a> MockChain<'a> {
pub fn gen_empty_block(&mut self, store: &MockStore) {
let parent = self.tip_header();
let cellbase = create_cellbase(store, self.consensus, &parent);
let dao = dao_data(&self.consensus, &parent, &[cellbase.clone()], store, false);
let dao = dao_data(self.consensus, &parent, &[cellbase.clone()], store, false);

let epoch = self
.consensus
Expand Down Expand Up @@ -477,7 +477,7 @@ impl<'a> MockChain<'a> {
let mut txs_to_resolve = vec![cellbase.clone()];
txs_to_resolve.extend_from_slice(&txs);
let dao = dao_data(
&self.consensus,
self.consensus,
&parent,
&txs_to_resolve,
store,
Expand Down Expand Up @@ -558,5 +558,5 @@ pub fn dao_data(
};
let data_loader = store.store().as_data_provider();
let calculator = DaoCalculator::new(consensus, &data_loader);
calculator.dao_field(&rtxs, &parent).unwrap()
calculator.dao_field(&rtxs, parent).unwrap()
}
2 changes: 1 addition & 1 deletion ckb-bin/Cargo.toml
Expand Up @@ -3,7 +3,7 @@ name = "ckb-bin"
version = "0.102.0-pre"
license = "MIT"
authors = ["Nervos Core Dev <dev@nervos.org>"]
edition = "2018"
edition = "2021"
description = "CKB executable."
homepage = "https://github.com/nervosnetwork/ckb"
repository = "https://github.com/nervosnetwork/ckb"
Expand Down

1 comment on commit e0c4900

@nervos-bot-user
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sync-Mainnet Report:

Version Time(s) Speed Tip Hostname Network
0.102.0-pre (e0c4900 2021-12-15) 9:42:10 174 6084422 instance-ap-northeast-1 ckb
0.102.0-pre (e0c4900 2021-12-15) 8:59:32 187 6084422 instance-ap-southeast-1 ckb
0.102.0-pre (e0c4900 2021-12-15) 9:18:02 181 6084422 instance-us-west-1 ckb

Please sign in to comment.