Skip to content

Commit 4b7a23f

Browse files
committed
Merge branch 'develop' into rc/v0.112.x
2 parents 94f4ee3 + afc7402 commit 4b7a23f

File tree

15 files changed

+146
-177
lines changed

15 files changed

+146
-177
lines changed

rpc/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1654,7 +1654,7 @@ Response
16541654
"result": {
16551655
"block_version": "0x0",
16561656
"cellbase_maturity": "0x10000000000",
1657-
"dao_type_hash": null,
1657+
"dao_type_hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
16581658
"epoch_duration_target": "0x3840",
16591659
"genesis_hash": "0x7978ec7ce5b507cfb52e149e36b1a23f6062ed150503c85bbf825da3599095ed",
16601660
"hardfork_features": [
@@ -5703,7 +5703,7 @@ Consensus defines various parameters that influence chain consensus
57035703

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

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

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

rpc/src/module/chain.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1336,7 +1336,7 @@ pub trait ChainRpc {
13361336
/// "result": {
13371337
/// "block_version": "0x0",
13381338
/// "cellbase_maturity": "0x10000000000",
1339-
/// "dao_type_hash": null,
1339+
/// "dao_type_hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
13401340
/// "epoch_duration_target": "0x3840",
13411341
/// "genesis_hash": "0x7978ec7ce5b507cfb52e149e36b1a23f6062ed150503c85bbf825da3599095ed",
13421342
/// "hardfork_features": [

rpc/src/module/pool.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -616,9 +616,7 @@ impl<'a> WellKnownScriptsOnlyValidator<'a> {
616616
Some(script) => {
617617
if !script.is_hash_type_type() {
618618
Err(DefaultOutputsValidatorError::HashType)
619-
} else if script.code_hash()
620-
!= self.consensus.dao_type_hash().expect("No dao system cell")
621-
{
619+
} else if script.code_hash() != self.consensus.dao_type_hash() {
622620
Err(DefaultOutputsValidatorError::CodeHash)
623621
} else if output.lock().args().len() == BLAKE160_LEN + SINCE_LEN {
624622
// https://github.com/nervosnetwork/ckb/wiki/Common-Gotchas#nervos-dao

rpc/src/tests/module/pool.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ fn test_default_outputs_validator() {
3737

3838
// invalid code hash
3939
let tx = build_tx(
40-
&consensus.dao_type_hash().unwrap(),
40+
&consensus.dao_type_hash(),
4141
core::ScriptHashType::Type,
4242
vec![1; 20],
4343
);
@@ -76,7 +76,7 @@ fn test_default_outputs_validator() {
7676
let lock_type_hash = consensus
7777
.secp256k1_blake160_multisig_all_type_hash()
7878
.unwrap();
79-
let type_type_hash = consensus.dao_type_hash().unwrap();
79+
let type_type_hash = consensus.dao_type_hash();
8080
// valid output lock
8181
let tx = build_tx_with_type(
8282
&lock_type_hash,

spec/src/consensus.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ impl ConsensusBuilder {
276276
median_time_block_count: MEDIAN_TIME_BLOCK_COUNT,
277277
max_block_cycles: MAX_BLOCK_CYCLES,
278278
max_block_bytes: MAX_BLOCK_BYTES,
279-
dao_type_hash: None,
279+
dao_type_hash: Byte32::default(),
280280
secp256k1_blake160_sighash_all_type_hash: None,
281281
secp256k1_blake160_multisig_all_type_hash: None,
282282
genesis_epoch_ext,
@@ -347,7 +347,7 @@ impl ConsensusBuilder {
347347
"genesis block must contain the witness for cellbase"
348348
);
349349

350-
self.inner.dao_type_hash = self.get_type_hash(OUTPUT_INDEX_DAO);
350+
self.inner.dao_type_hash = self.get_type_hash(OUTPUT_INDEX_DAO).unwrap_or_default();
351351
self.inner.secp256k1_blake160_sighash_all_type_hash =
352352
self.get_type_hash(OUTPUT_INDEX_SECP256K1_BLAKE160_SIGHASH_ALL);
353353
self.inner.secp256k1_blake160_multisig_all_type_hash =
@@ -514,7 +514,7 @@ pub struct Consensus {
514514
/// The dao type hash
515515
///
516516
/// [nervos-dao](https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0024-ckb-genesis-script-list/0024-ckb-genesis-script-list.md#nervos-dao)
517-
pub dao_type_hash: Option<Byte32>,
517+
pub dao_type_hash: Byte32,
518518
/// The secp256k1_blake160_sighash_all_type_hash
519519
///
520520
/// [SECP256K1/blake160](https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0024-ckb-genesis-script-list/0024-ckb-genesis-script-list.md#secp256k1blake160)
@@ -626,7 +626,7 @@ impl Consensus {
626626
/// The dao type hash
627627
///
628628
/// [nervos-dao](https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0024-ckb-genesis-script-list/0024-ckb-genesis-script-list.md#nervos-dao)
629-
pub fn dao_type_hash(&self) -> Option<Byte32> {
629+
pub fn dao_type_hash(&self) -> Byte32 {
630630
self.dao_type_hash.clone()
631631
}
632632

@@ -1111,7 +1111,7 @@ impl From<Consensus> for ckb_jsonrpc_types::Consensus {
11111111
Self {
11121112
id: consensus.id,
11131113
genesis_hash: consensus.genesis_hash.unpack(),
1114-
dao_type_hash: consensus.dao_type_hash.map(|h| h.unpack()),
1114+
dao_type_hash: consensus.dao_type_hash.unpack(),
11151115
secp256k1_blake160_sighash_all_type_hash: consensus
11161116
.secp256k1_blake160_sighash_all_type_hash
11171117
.map(|h| h.unpack()),

test/src/specs/dao/dao_user.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ impl<'a> DAOUser<'a> {
187187

188188
pub fn dao_type_script(&self) -> Script {
189189
Script::new_builder()
190-
.code_hash(self.node.consensus().dao_type_hash().unwrap())
190+
.code_hash(self.node.consensus().dao_type_hash())
191191
.hash_type(ScriptHashType::Type.into())
192192
.build()
193193
}

test/src/specs/dao/dao_verifier.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ impl DAOVerifier {
257257
return false;
258258
}
259259

260-
let dao_type_hash = self.consensus.dao_type_hash().unwrap();
260+
let dao_type_hash = self.consensus.dao_type_hash();
261261
self.get_output(out_point)
262262
.type_()
263263
.to_opt()

test/src/specs/tx_pool/replace.rs

+31-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{Node, Spec};
1+
use crate::{utils::wait_until, Node, Spec};
22
use ckb_jsonrpc_types::Status;
33
use ckb_logger::info;
44
use ckb_types::{
@@ -465,18 +465,21 @@ impl Spec for RbfRejectReplaceProposed {
465465
assert!(ret.is_ok());
466466
}
467467

468-
node0.mine_with_blocking(|template| template.proposals.len() != max_count);
468+
let proposed = node0.mine_with_blocking(|template| template.proposals.len() != max_count);
469469
let ret = node0.rpc_client().get_transaction(txs[2].hash());
470470
assert!(
471471
matches!(ret.tx_status.status, Status::Pending),
472472
"tx1 should be pending"
473473
);
474-
node0.mine(1);
475-
let ret = node0.rpc_client().get_transaction(txs[2].hash());
476-
assert!(
477-
matches!(ret.tx_status.status, Status::Proposed),
478-
"tx1 should be proposed"
479-
);
474+
475+
node0.mine_with_blocking(|template| template.number.value() != (proposed + 1));
476+
477+
let rpc_client0 = node0.rpc_client();
478+
let ret = wait_until(20, || {
479+
let res = rpc_client0.get_transaction(txs[2].hash());
480+
res.tx_status.status == Status::Proposed
481+
});
482+
assert!(ret, "tx1 should be proposed");
480483

481484
let clone_tx = txs[2].clone();
482485
// Set tx2 fee to a higher value
@@ -498,6 +501,26 @@ impl Spec for RbfRejectReplaceProposed {
498501
.unwrap()
499502
.to_string()
500503
.contains("all conflict Txs should be in Pending status"));
504+
505+
// when tx1 was confirmed, tx2 should be rejected
506+
let window_count = node0.consensus().tx_proposal_window().closest();
507+
node0.mine(window_count);
508+
let ret = wait_until(20, || {
509+
let res = rpc_client0.get_transaction(txs[2].hash());
510+
res.tx_status.status == Status::Committed
511+
});
512+
assert!(ret, "tx1 should be committed");
513+
let res = node0
514+
.rpc_client()
515+
.send_transaction_result(tx2.data().into());
516+
assert!(res.is_err(), "tx2 should be rejected");
517+
518+
// resolve tx2 failed with `unknown` when resolve inputs used by tx1
519+
assert!(res
520+
.err()
521+
.unwrap()
522+
.to_string()
523+
.contains("TransactionFailedToResolve: Resolve failed Unknown"));
501524
}
502525

503526
fn modify_app_config(&self, config: &mut ckb_app_config::CKBAppConfig) {

util/dao/src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,7 @@ impl<'a, DL: CellDataProvider + EpochProvider + HeaderProvider> DaoCalculator<'a
221221
let is_dao_type_script = |type_script: Script| {
222222
Into::<u8>::into(type_script.hash_type())
223223
== Into::<u8>::into(ScriptHashType::Type)
224-
&& type_script.code_hash()
225-
== self.consensus.dao_type_hash().expect("No dao system cell")
224+
&& type_script.code_hash() == self.consensus.dao_type_hash()
226225
};
227226
let is_withdrawing_input =
228227
|cell_meta: &CellMeta| match self.data_loader.load_cell_data(cell_meta) {

util/jsonrpc-types/src/blockchain.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1339,7 +1339,7 @@ pub struct Consensus {
13391339
/// The genesis block hash
13401340
pub genesis_hash: H256,
13411341
/// The dao type hash
1342-
pub dao_type_hash: Option<H256>,
1342+
pub dao_type_hash: H256,
13431343
/// The secp256k1_blake160_sighash_all_type_hash
13441344
pub secp256k1_blake160_sighash_all_type_hash: Option<H256>,
13451345
/// The secp256k1_blake160_multisig_all_type_hash

util/light-client-protocol-server/src/components/get_blocks_proof.rs

+22-33
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,15 @@ impl<'a> GetBlocksProofProcess<'a> {
4040

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

43-
let last_hash = self.message.last_hash().to_entity();
44-
let last_block = if let Some(block) = snapshot.get_block(&last_hash) {
45-
block
46-
} else {
43+
let last_block_hash = self.message.last_hash().to_entity();
44+
if !snapshot.is_main_chain(&last_block_hash) {
4745
return self
4846
.protocol
4947
.reply_tip_state::<packed::SendBlocksProof>(self.peer, self.nc);
50-
};
48+
}
49+
let last_block = snapshot
50+
.get_block(&last_block_hash)
51+
.expect("block should be in store");
5152

5253
let block_hashes: Vec<_> = self
5354
.message
@@ -59,42 +60,30 @@ impl<'a> GetBlocksProofProcess<'a> {
5960
let mut uniq = HashSet::new();
6061
if !block_hashes
6162
.iter()
62-
.chain([last_hash.clone()].iter())
63+
.chain([last_block_hash].iter())
6364
.all(|hash| uniq.insert(hash))
6465
{
6566
return StatusCode::MalformedProtocolMessage
6667
.with_context("duplicate block hash exists");
6768
}
6869

69-
let (positions, block_headers, missing_blocks) = block_hashes
70+
let (found, missing): (Vec<_>, Vec<_>) = block_hashes
7071
.into_iter()
71-
.map(|block_hash| {
72-
snapshot
73-
.get_block_header(&block_hash)
74-
.map(|header| header.number())
75-
.filter(|number| *number != last_block.number())
76-
.and_then(|number| snapshot.get_ancestor(&last_hash, number))
77-
.filter(|header| header.hash() == block_hash)
78-
.ok_or(block_hash)
79-
})
80-
.fold(
81-
(Vec::new(), Vec::new(), Vec::new()),
82-
|(mut positions, mut block_headers, mut missing_blocks), result| {
83-
match result {
84-
Ok(header) => {
85-
positions.push(leaf_index_to_pos(header.number()));
86-
block_headers.push(header);
87-
}
88-
Err(block_hash) => {
89-
missing_blocks.push(block_hash);
90-
}
91-
}
92-
(positions, block_headers, missing_blocks)
93-
},
94-
);
72+
.partition(|block_hash| snapshot.is_main_chain(block_hash));
73+
74+
let mut positions = Vec::with_capacity(found.len());
75+
let mut block_headers = Vec::with_capacity(found.len());
76+
77+
for block_hash in found {
78+
let header = snapshot
79+
.get_block_header(&block_hash)
80+
.expect("header should be in store");
81+
positions.push(leaf_index_to_pos(header.number()));
82+
block_headers.push(header.data());
83+
}
9584

96-
let proved_items = block_headers.into_iter().map(|view| view.data()).pack();
97-
let missing_items = missing_blocks.pack();
85+
let proved_items = block_headers.pack();
86+
let missing_items = missing.pack();
9887

9988
self.protocol.reply_proof::<packed::SendBlocksProof>(
10089
self.peer,

util/light-client-protocol-server/src/components/get_last_state_proof.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -204,18 +204,14 @@ impl<'a> GetLastStateProofProcess<'a> {
204204
let snapshot = self.protocol.shared.snapshot();
205205

206206
let last_block_hash = self.message.last_hash().to_entity();
207-
let last_block = if !snapshot.is_main_chain(&last_block_hash) {
207+
if !snapshot.is_main_chain(&last_block_hash) {
208208
return self
209209
.protocol
210210
.reply_tip_state::<packed::SendLastStateProof>(self.peer, self.nc);
211-
} else if let Some(block) = snapshot.get_block(&last_block_hash) {
212-
block
213-
} else {
214-
let errmsg = format!(
215-
"the block is in the main chain but not found, its hash is {last_block_hash:#x}"
216-
);
217-
return StatusCode::InternalError.with_context(errmsg);
218-
};
211+
}
212+
let last_block = snapshot
213+
.get_block(&last_block_hash)
214+
.expect("block should be in store");
219215

220216
let start_block_hash = self.message.start_hash().to_entity();
221217
let start_block_number: BlockNumber = self.message.start_number().unpack();

0 commit comments

Comments
 (0)