Skip to content

Commit

Permalink
Merge branch 'develop' into rc/v0.112.x
Browse files Browse the repository at this point in the history
  • Loading branch information
doitian committed Oct 13, 2023
2 parents 94f4ee3 + afc7402 commit 4b7a23f
Show file tree
Hide file tree
Showing 15 changed files with 146 additions and 177 deletions.
4 changes: 2 additions & 2 deletions rpc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1654,7 +1654,7 @@ Response
"result": {
"block_version": "0x0",
"cellbase_maturity": "0x10000000000",
"dao_type_hash": null,
"dao_type_hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"epoch_duration_target": "0x3840",
"genesis_hash": "0x7978ec7ce5b507cfb52e149e36b1a23f6062ed150503c85bbf825da3599095ed",
"hardfork_features": [
Expand Down Expand Up @@ -5703,7 +5703,7 @@ Consensus defines various parameters that influence chain consensus

* `genesis_hash`: [`H256`](#type-h256) - The genesis block hash

* `dao_type_hash`: [`H256`](#type-h256) `|` `null` - The dao type hash
* `dao_type_hash`: [`H256`](#type-h256) - The dao type hash

* `secp256k1_blake160_sighash_all_type_hash`: [`H256`](#type-h256) `|` `null` - The secp256k1_blake160_sighash_all_type_hash

Expand Down
2 changes: 1 addition & 1 deletion rpc/src/module/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1336,7 +1336,7 @@ pub trait ChainRpc {
/// "result": {
/// "block_version": "0x0",
/// "cellbase_maturity": "0x10000000000",
/// "dao_type_hash": null,
/// "dao_type_hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
/// "epoch_duration_target": "0x3840",
/// "genesis_hash": "0x7978ec7ce5b507cfb52e149e36b1a23f6062ed150503c85bbf825da3599095ed",
/// "hardfork_features": [
Expand Down
4 changes: 1 addition & 3 deletions rpc/src/module/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -616,9 +616,7 @@ impl<'a> WellKnownScriptsOnlyValidator<'a> {
Some(script) => {
if !script.is_hash_type_type() {
Err(DefaultOutputsValidatorError::HashType)
} else if script.code_hash()
!= self.consensus.dao_type_hash().expect("No dao system cell")
{
} else if script.code_hash() != self.consensus.dao_type_hash() {
Err(DefaultOutputsValidatorError::CodeHash)
} else if output.lock().args().len() == BLAKE160_LEN + SINCE_LEN {
// https://github.com/nervosnetwork/ckb/wiki/Common-Gotchas#nervos-dao
Expand Down
4 changes: 2 additions & 2 deletions rpc/src/tests/module/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn test_default_outputs_validator() {

// invalid code hash
let tx = build_tx(
&consensus.dao_type_hash().unwrap(),
&consensus.dao_type_hash(),
core::ScriptHashType::Type,
vec![1; 20],
);
Expand Down Expand Up @@ -76,7 +76,7 @@ fn test_default_outputs_validator() {
let lock_type_hash = consensus
.secp256k1_blake160_multisig_all_type_hash()
.unwrap();
let type_type_hash = consensus.dao_type_hash().unwrap();
let type_type_hash = consensus.dao_type_hash();
// valid output lock
let tx = build_tx_with_type(
&lock_type_hash,
Expand Down
10 changes: 5 additions & 5 deletions spec/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ impl ConsensusBuilder {
median_time_block_count: MEDIAN_TIME_BLOCK_COUNT,
max_block_cycles: MAX_BLOCK_CYCLES,
max_block_bytes: MAX_BLOCK_BYTES,
dao_type_hash: None,
dao_type_hash: Byte32::default(),
secp256k1_blake160_sighash_all_type_hash: None,
secp256k1_blake160_multisig_all_type_hash: None,
genesis_epoch_ext,
Expand Down Expand Up @@ -347,7 +347,7 @@ impl ConsensusBuilder {
"genesis block must contain the witness for cellbase"
);

self.inner.dao_type_hash = self.get_type_hash(OUTPUT_INDEX_DAO);
self.inner.dao_type_hash = self.get_type_hash(OUTPUT_INDEX_DAO).unwrap_or_default();
self.inner.secp256k1_blake160_sighash_all_type_hash =
self.get_type_hash(OUTPUT_INDEX_SECP256K1_BLAKE160_SIGHASH_ALL);
self.inner.secp256k1_blake160_multisig_all_type_hash =
Expand Down Expand Up @@ -514,7 +514,7 @@ pub struct Consensus {
/// The dao type hash
///
/// [nervos-dao](https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0024-ckb-genesis-script-list/0024-ckb-genesis-script-list.md#nervos-dao)
pub dao_type_hash: Option<Byte32>,
pub dao_type_hash: Byte32,
/// The secp256k1_blake160_sighash_all_type_hash
///
/// [SECP256K1/blake160](https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0024-ckb-genesis-script-list/0024-ckb-genesis-script-list.md#secp256k1blake160)
Expand Down Expand Up @@ -626,7 +626,7 @@ impl Consensus {
/// The dao type hash
///
/// [nervos-dao](https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0024-ckb-genesis-script-list/0024-ckb-genesis-script-list.md#nervos-dao)
pub fn dao_type_hash(&self) -> Option<Byte32> {
pub fn dao_type_hash(&self) -> Byte32 {
self.dao_type_hash.clone()
}

Expand Down Expand Up @@ -1111,7 +1111,7 @@ impl From<Consensus> for ckb_jsonrpc_types::Consensus {
Self {
id: consensus.id,
genesis_hash: consensus.genesis_hash.unpack(),
dao_type_hash: consensus.dao_type_hash.map(|h| h.unpack()),
dao_type_hash: consensus.dao_type_hash.unpack(),
secp256k1_blake160_sighash_all_type_hash: consensus
.secp256k1_blake160_sighash_all_type_hash
.map(|h| h.unpack()),
Expand Down
2 changes: 1 addition & 1 deletion test/src/specs/dao/dao_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ impl<'a> DAOUser<'a> {

pub fn dao_type_script(&self) -> Script {
Script::new_builder()
.code_hash(self.node.consensus().dao_type_hash().unwrap())
.code_hash(self.node.consensus().dao_type_hash())
.hash_type(ScriptHashType::Type.into())
.build()
}
Expand Down
2 changes: 1 addition & 1 deletion test/src/specs/dao/dao_verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ impl DAOVerifier {
return false;
}

let dao_type_hash = self.consensus.dao_type_hash().unwrap();
let dao_type_hash = self.consensus.dao_type_hash();
self.get_output(out_point)
.type_()
.to_opt()
Expand Down
39 changes: 31 additions & 8 deletions test/src/specs/tx_pool/replace.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{Node, Spec};
use crate::{utils::wait_until, Node, Spec};
use ckb_jsonrpc_types::Status;
use ckb_logger::info;
use ckb_types::{
Expand Down Expand Up @@ -465,18 +465,21 @@ impl Spec for RbfRejectReplaceProposed {
assert!(ret.is_ok());
}

node0.mine_with_blocking(|template| template.proposals.len() != max_count);
let proposed = node0.mine_with_blocking(|template| template.proposals.len() != max_count);
let ret = node0.rpc_client().get_transaction(txs[2].hash());
assert!(
matches!(ret.tx_status.status, Status::Pending),
"tx1 should be pending"
);
node0.mine(1);
let ret = node0.rpc_client().get_transaction(txs[2].hash());
assert!(
matches!(ret.tx_status.status, Status::Proposed),
"tx1 should be proposed"
);

node0.mine_with_blocking(|template| template.number.value() != (proposed + 1));

let rpc_client0 = node0.rpc_client();
let ret = wait_until(20, || {
let res = rpc_client0.get_transaction(txs[2].hash());
res.tx_status.status == Status::Proposed
});
assert!(ret, "tx1 should be proposed");

let clone_tx = txs[2].clone();
// Set tx2 fee to a higher value
Expand All @@ -498,6 +501,26 @@ impl Spec for RbfRejectReplaceProposed {
.unwrap()
.to_string()
.contains("all conflict Txs should be in Pending status"));

// when tx1 was confirmed, tx2 should be rejected
let window_count = node0.consensus().tx_proposal_window().closest();
node0.mine(window_count);
let ret = wait_until(20, || {
let res = rpc_client0.get_transaction(txs[2].hash());
res.tx_status.status == Status::Committed
});
assert!(ret, "tx1 should be committed");
let res = node0
.rpc_client()
.send_transaction_result(tx2.data().into());
assert!(res.is_err(), "tx2 should be rejected");

// resolve tx2 failed with `unknown` when resolve inputs used by tx1
assert!(res
.err()
.unwrap()
.to_string()
.contains("TransactionFailedToResolve: Resolve failed Unknown"));
}

fn modify_app_config(&self, config: &mut ckb_app_config::CKBAppConfig) {
Expand Down
3 changes: 1 addition & 2 deletions util/dao/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,7 @@ impl<'a, DL: CellDataProvider + EpochProvider + HeaderProvider> DaoCalculator<'a
let is_dao_type_script = |type_script: Script| {
Into::<u8>::into(type_script.hash_type())
== Into::<u8>::into(ScriptHashType::Type)
&& type_script.code_hash()
== self.consensus.dao_type_hash().expect("No dao system cell")
&& type_script.code_hash() == self.consensus.dao_type_hash()
};
let is_withdrawing_input =
|cell_meta: &CellMeta| match self.data_loader.load_cell_data(cell_meta) {
Expand Down
2 changes: 1 addition & 1 deletion util/jsonrpc-types/src/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1339,7 +1339,7 @@ pub struct Consensus {
/// The genesis block hash
pub genesis_hash: H256,
/// The dao type hash
pub dao_type_hash: Option<H256>,
pub dao_type_hash: H256,
/// The secp256k1_blake160_sighash_all_type_hash
pub secp256k1_blake160_sighash_all_type_hash: Option<H256>,
/// The secp256k1_blake160_multisig_all_type_hash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,15 @@ impl<'a> GetBlocksProofProcess<'a> {

let snapshot = self.protocol.shared.snapshot();

let last_hash = self.message.last_hash().to_entity();
let last_block = if let Some(block) = snapshot.get_block(&last_hash) {
block
} else {
let last_block_hash = self.message.last_hash().to_entity();
if !snapshot.is_main_chain(&last_block_hash) {
return self
.protocol
.reply_tip_state::<packed::SendBlocksProof>(self.peer, self.nc);
};
}
let last_block = snapshot
.get_block(&last_block_hash)
.expect("block should be in store");

let block_hashes: Vec<_> = self
.message
Expand All @@ -59,42 +60,30 @@ impl<'a> GetBlocksProofProcess<'a> {
let mut uniq = HashSet::new();
if !block_hashes
.iter()
.chain([last_hash.clone()].iter())
.chain([last_block_hash].iter())
.all(|hash| uniq.insert(hash))
{
return StatusCode::MalformedProtocolMessage
.with_context("duplicate block hash exists");
}

let (positions, block_headers, missing_blocks) = block_hashes
let (found, missing): (Vec<_>, Vec<_>) = block_hashes
.into_iter()
.map(|block_hash| {
snapshot
.get_block_header(&block_hash)
.map(|header| header.number())
.filter(|number| *number != last_block.number())
.and_then(|number| snapshot.get_ancestor(&last_hash, number))
.filter(|header| header.hash() == block_hash)
.ok_or(block_hash)
})
.fold(
(Vec::new(), Vec::new(), Vec::new()),
|(mut positions, mut block_headers, mut missing_blocks), result| {
match result {
Ok(header) => {
positions.push(leaf_index_to_pos(header.number()));
block_headers.push(header);
}
Err(block_hash) => {
missing_blocks.push(block_hash);
}
}
(positions, block_headers, missing_blocks)
},
);
.partition(|block_hash| snapshot.is_main_chain(block_hash));

let mut positions = Vec::with_capacity(found.len());
let mut block_headers = Vec::with_capacity(found.len());

for block_hash in found {
let header = snapshot
.get_block_header(&block_hash)
.expect("header should be in store");
positions.push(leaf_index_to_pos(header.number()));
block_headers.push(header.data());
}

let proved_items = block_headers.into_iter().map(|view| view.data()).pack();
let missing_items = missing_blocks.pack();
let proved_items = block_headers.pack();
let missing_items = missing.pack();

self.protocol.reply_proof::<packed::SendBlocksProof>(
self.peer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,18 +204,14 @@ impl<'a> GetLastStateProofProcess<'a> {
let snapshot = self.protocol.shared.snapshot();

let last_block_hash = self.message.last_hash().to_entity();
let last_block = if !snapshot.is_main_chain(&last_block_hash) {
if !snapshot.is_main_chain(&last_block_hash) {
return self
.protocol
.reply_tip_state::<packed::SendLastStateProof>(self.peer, self.nc);
} else if let Some(block) = snapshot.get_block(&last_block_hash) {
block
} else {
let errmsg = format!(
"the block is in the main chain but not found, its hash is {last_block_hash:#x}"
);
return StatusCode::InternalError.with_context(errmsg);
};
}
let last_block = snapshot
.get_block(&last_block_hash)
.expect("block should be in store");

let start_block_hash = self.message.start_hash().to_entity();
let start_block_number: BlockNumber = self.message.start_number().unpack();
Expand Down
Loading

0 comments on commit 4b7a23f

Please sign in to comment.