Skip to content

Commit ba31616

Browse files
authored
Merge pull request #4186 from eval-exec/exec/remove-dao_type_hash-Option-wrapper
Remove `Consensus.dao_type_hash`'s `Option` wrapper
2 parents 385bc89 + aff040d commit ba31616

File tree

11 files changed

+24
-39
lines changed

11 files changed

+24
-39
lines changed

rpc/README.md

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 3 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 5 additions & 5 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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()

util/dao/src/lib.rs

Lines changed: 1 addition & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

verification/src/tests/transaction_verifier.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ pub fn test_capacity_outofbound() {
104104
resolved_dep_groups: vec![],
105105
});
106106
let dao_type_hash = build_genesis_type_id_script(OUTPUT_INDEX_DAO).calc_script_hash();
107-
let verifier = CapacityVerifier::new(rtx, Some(dao_type_hash));
107+
let verifier = CapacityVerifier::new(rtx, dao_type_hash);
108108

109109
assert_error_eq!(
110110
verifier.verify().unwrap_err(),
@@ -136,7 +136,7 @@ pub fn test_skip_dao_capacity_check() {
136136
resolved_inputs: vec![],
137137
resolved_dep_groups: vec![],
138138
});
139-
let verifier = CapacityVerifier::new(rtx, Some(dao_type_script.calc_script_hash()));
139+
let verifier = CapacityVerifier::new(rtx, dao_type_script.calc_script_hash());
140140

141141
assert!(verifier.verify().is_ok());
142142
}
@@ -329,7 +329,7 @@ pub fn test_capacity_invalid() {
329329
resolved_dep_groups: vec![],
330330
});
331331
let dao_type_hash = build_genesis_type_id_script(OUTPUT_INDEX_DAO).calc_script_hash();
332-
let verifier = CapacityVerifier::new(rtx, Some(dao_type_hash));
332+
let verifier = CapacityVerifier::new(rtx, dao_type_hash);
333333

334334
assert_error_eq!(
335335
verifier.verify().unwrap_err(),
@@ -808,7 +808,7 @@ fn build_consensus_with_dao_limiting_block(block_number: u64) -> (Arc<Consensus>
808808
// the dao script. For simplicity, we are hacking consensus here with
809809
// a dao_type_hash value, a proper way should be creating a proper genesis
810810
// block here, but we will leave it till we really need it.
811-
consensus.dao_type_hash = Some(dao_script.calc_script_hash());
811+
consensus.dao_type_hash = dao_script.calc_script_hash();
812812

813813
let dao_type_script = Script::new_builder()
814814
.code_hash(dao_script.calc_script_hash())

verification/src/transaction_verifier.rs

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -523,16 +523,12 @@ impl<'a> DuplicateDepsVerifier<'a> {
523523
/// Perform inputs and outputs `capacity` field related verification
524524
pub struct CapacityVerifier {
525525
resolved_transaction: Arc<ResolvedTransaction>,
526-
// It's Option because special genesis block do not have dao system cell
527-
dao_type_hash: Option<Byte32>,
526+
dao_type_hash: Byte32,
528527
}
529528

530529
impl CapacityVerifier {
531530
/// Create a new `CapacityVerifier`
532-
pub fn new(
533-
resolved_transaction: Arc<ResolvedTransaction>,
534-
dao_type_hash: Option<Byte32>,
535-
) -> Self {
531+
pub fn new(resolved_transaction: Arc<ResolvedTransaction>, dao_type_hash: Byte32) -> Self {
536532
CapacityVerifier {
537533
resolved_transaction,
538534
dao_type_hash,
@@ -584,12 +580,7 @@ impl CapacityVerifier {
584580
self.resolved_transaction
585581
.resolved_inputs
586582
.iter()
587-
.any(|cell_meta| {
588-
cell_uses_dao_type_script(
589-
&cell_meta.cell_output,
590-
self.dao_type_hash.as_ref().expect("No dao system cell"),
591-
)
592-
})
583+
.any(|cell_meta| cell_uses_dao_type_script(&cell_meta.cell_output, &self.dao_type_hash))
593584
}
594585
}
595586

@@ -990,17 +981,14 @@ impl<DL: CellDataProvider> DaoScriptSizeVerifier<DL> {
990981
}
991982
}
992983

993-
fn dao_type_hash(&self) -> Option<Byte32> {
984+
fn dao_type_hash(&self) -> Byte32 {
994985
self.consensus.dao_type_hash()
995986
}
996987

997988
/// Verifies that for all Nervos DAO transactions, withdrawing cells must use lock scripts
998989
/// of the same size as corresponding deposit cells
999990
pub fn verify(&self) -> Result<(), Error> {
1000-
if self.dao_type_hash().is_none() {
1001-
return Ok(());
1002-
}
1003-
let dao_type_hash = self.dao_type_hash().unwrap();
991+
let dao_type_hash = self.dao_type_hash();
1004992
for (i, (input_meta, cell_output)) in self
1005993
.resolved_transaction
1006994
.resolved_inputs

0 commit comments

Comments
 (0)