Skip to content

Commit

Permalink
refactor: rename structure fields
Browse files Browse the repository at this point in the history
Molecule:

- `CustodianLockArgs#deposit_block_timepoint` -> `deposit_finalized_timepoint`
- `WithdrawalLockArgs#withdrawal_block_timepoint` -> `withdrawal_finalized_timepoint`
- `StakeLockArgs#stake_block_timepoint` -> `stake_finalized_timepoint`

JronRPC:

- `WithdrawalLockArgs#withdrawal_block_timepoint` -> `withdrawal_finalized_timepoint`
  • Loading branch information
jjyr committed Dec 19, 2022
1 parent 3b1b08f commit a657ec5
Show file tree
Hide file tree
Showing 27 changed files with 188 additions and 184 deletions.
2 changes: 1 addition & 1 deletion crates/block-producer/src/custodian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ async fn query_mergeable_ckb_custodians(
};
if !compatible_finalized_timepoint.is_finalized(&Timepoint::from_full_value(
custodian_lock_args_reader
.deposit_block_timepoint()
.deposit_finalized_timepoint()
.unpack(),
)) {
continue;
Expand Down
6 changes: 3 additions & 3 deletions crates/block-producer/src/stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub async fn generate(
local_cells_manager: &LocalCellsManager,
) -> Result<GeneratedStake> {
let owner_lock_hash = lock_script.hash();
let stake_block_timepoint = finalized_timepoint(
let stake_finalized_timepoint = finalized_timepoint(
&rollup_context.rollup_config,
&rollup_context.fork_config,
block.raw().number().unpack(),
Expand All @@ -48,7 +48,7 @@ pub async fn generate(
let lock_args: Bytes = {
let stake_lock_args = StakeLockArgs::new_builder()
.owner_lock_hash(owner_lock_hash.pack())
.stake_block_timepoint(stake_block_timepoint.full_value().pack())
.stake_finalized_timepoint(stake_finalized_timepoint.full_value().pack())
.build();
let rollup_type_hash = rollup_context.rollup_script_hash.as_slice().iter();
rollup_type_hash
Expand Down Expand Up @@ -180,7 +180,7 @@ pub async fn query_stake(
match &compatible_finalize_timepoint_opt {
Some(compatible_finalized_timepoint) => {
compatible_finalized_timepoint.is_finalized(&Timepoint::from_full_value(
stake_lock_args.stake_block_timepoint().unpack(),
stake_lock_args.stake_finalized_timepoint().unpack(),
)) && stake_lock_args.owner_lock_hash().as_slice() == owner_lock_hash
}
None => stake_lock_args.owner_lock_hash().as_slice() == owner_lock_hash,
Expand Down
36 changes: 18 additions & 18 deletions crates/block-producer/src/withdrawal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ pub fn unlock_to_owner(
rollup_config.finality_blocks().unpack(),
);
let l1_sudt_script_hash = rollup_config.l1_sudt_script_type_hash();
let mut if_exist_v1_withdrawal_cells = false;
let mut if_exist_legacy_withdrawal_cells = false;
for withdrawal_cell in withdrawal_cells {
// Double check
if let Err(err) = gw_rpc_client::withdrawal::verify_unlockable_to_owner(
Expand All @@ -245,8 +245,8 @@ pub fn unlock_to_owner(
continue;
}

if !if_exist_v1_withdrawal_cells {
if_exist_v1_withdrawal_cells = is_v1_withdrawal_cell(&withdrawal_cell);
if !if_exist_legacy_withdrawal_cells {
if_exist_legacy_withdrawal_cells = is_legacy_finality_withdrawal_cell(&withdrawal_cell);
}

let owner_lock = {
Expand Down Expand Up @@ -292,8 +292,8 @@ pub fn unlock_to_owner(
let withdrawal_lock_dep = contracts_dep.withdrawal_cell_lock.clone();
let sudt_type_dep = contracts_dep.l1_sudt_type.clone();

let mut cell_deps = if if_exist_v1_withdrawal_cells {
// Some withdrawal cells were born at v1, withdrawal_lock_script checks finality of withdrawal
let mut cell_deps = if if_exist_legacy_withdrawal_cells {
// Some withdrawal cells were born at legacy version, withdrawal_lock_script checks finality of withdrawal
// cells by comparing with GlobalState.last_finalized_timepoint, so rollup_dep and
// rollup_config_dep are required
vec![
Expand Down Expand Up @@ -322,13 +322,13 @@ pub fn unlock_to_owner(
}))
}

fn is_v1_withdrawal_cell(withdrawal_cell: &CellInfo) -> bool {
fn is_legacy_finality_withdrawal_cell(withdrawal_cell: &CellInfo) -> bool {
let withdrawal_lock_args = parse_lock_args(&withdrawal_cell.output.lock().args().raw_data())
.expect("parse withdrawal lock args");
match Timepoint::from_full_value(
withdrawal_lock_args
.lock_args
.withdrawal_block_timepoint()
.withdrawal_finalized_timepoint()
.unpack(),
) {
Timepoint::BlockNumber(_) => true,
Expand Down Expand Up @@ -530,7 +530,7 @@ mod test {
let withdrawal_without_owner_lock = {
let lock_args = WithdrawalLockArgs::new_builder()
.owner_lock_hash(owner_lock.hash().pack())
.withdrawal_block_timepoint(last_finalized_timepoint.full_value().pack())
.withdrawal_finalized_timepoint(last_finalized_timepoint.full_value().pack())
.build();

let mut args = rollup_type.hash().to_vec();
Expand All @@ -546,7 +546,7 @@ mod test {
let withdrawal_with_owner_lock = {
let lock_args = WithdrawalLockArgs::new_builder()
.owner_lock_hash(owner_lock.hash().pack())
.withdrawal_block_timepoint(last_finalized_timepoint.full_value().pack())
.withdrawal_finalized_timepoint(last_finalized_timepoint.full_value().pack())
.build();

let mut args = rollup_type.hash().to_vec();
Expand Down Expand Up @@ -665,7 +665,7 @@ mod test {
upgrade_global_state_version_to_v2: UPGRADE_GLOBAL_STATE_VERSION_TO_V2,
block_timestamp: BLOCK_TIMESTAMP,
block_number: UPGRADE_GLOBAL_STATE_VERSION_TO_V2 - 1,
withdrawal_block_timepoint: Timepoint::BlockNumber(
withdrawal_finalized_timepoint: Timepoint::BlockNumber(
UPGRADE_GLOBAL_STATE_VERSION_TO_V2 - FINALITY_BLOCKS,
),
expected_result: Err(()),
Expand All @@ -677,7 +677,7 @@ mod test {
upgrade_global_state_version_to_v2: UPGRADE_GLOBAL_STATE_VERSION_TO_V2,
block_timestamp: BLOCK_TIMESTAMP,
block_number: UPGRADE_GLOBAL_STATE_VERSION_TO_V2 - 1,
withdrawal_block_timepoint: Timepoint::BlockNumber(
withdrawal_finalized_timepoint: Timepoint::BlockNumber(
UPGRADE_GLOBAL_STATE_VERSION_TO_V2 - 1 - FINALITY_BLOCKS,
),
expected_result: Ok(()),
Expand All @@ -689,7 +689,7 @@ mod test {
upgrade_global_state_version_to_v2: UPGRADE_GLOBAL_STATE_VERSION_TO_V2,
block_timestamp: BLOCK_TIMESTAMP,
block_number: UPGRADE_GLOBAL_STATE_VERSION_TO_V2,
withdrawal_block_timepoint: Timepoint::BlockNumber(
withdrawal_finalized_timepoint: Timepoint::BlockNumber(
UPGRADE_GLOBAL_STATE_VERSION_TO_V2 + 1 - FINALITY_BLOCKS,
),
expected_result: Err(()),
Expand All @@ -701,7 +701,7 @@ mod test {
upgrade_global_state_version_to_v2: UPGRADE_GLOBAL_STATE_VERSION_TO_V2,
block_timestamp: BLOCK_TIMESTAMP,
block_number: UPGRADE_GLOBAL_STATE_VERSION_TO_V2,
withdrawal_block_timepoint: Timepoint::BlockNumber(
withdrawal_finalized_timepoint: Timepoint::BlockNumber(
UPGRADE_GLOBAL_STATE_VERSION_TO_V2 - FINALITY_BLOCKS,
),
expected_result: Ok(()),
Expand All @@ -713,7 +713,7 @@ mod test {
upgrade_global_state_version_to_v2: UPGRADE_GLOBAL_STATE_VERSION_TO_V2,
block_timestamp: BLOCK_TIMESTAMP,
block_number: UPGRADE_GLOBAL_STATE_VERSION_TO_V2,
withdrawal_block_timepoint: Timepoint::Timestamp(BLOCK_TIMESTAMP + 1),
withdrawal_finalized_timepoint: Timepoint::Timestamp(BLOCK_TIMESTAMP + 1),
expected_result: Err(()),
},
CaseParam {
Expand All @@ -723,7 +723,7 @@ mod test {
upgrade_global_state_version_to_v2: UPGRADE_GLOBAL_STATE_VERSION_TO_V2,
block_timestamp: BLOCK_TIMESTAMP,
block_number: UPGRADE_GLOBAL_STATE_VERSION_TO_V2,
withdrawal_block_timepoint: Timepoint::Timestamp(BLOCK_TIMESTAMP),
withdrawal_finalized_timepoint: Timepoint::Timestamp(BLOCK_TIMESTAMP),
expected_result: Ok(()),
},
];
Expand All @@ -739,7 +739,7 @@ mod test {
upgrade_global_state_version_to_v2: u64,
block_timestamp: u64,
block_number: u64,
withdrawal_block_timepoint: Timepoint,
withdrawal_finalized_timepoint: Timepoint,
expected_result: Result<(), ()>,
}

Expand All @@ -751,7 +751,7 @@ mod test {
upgrade_global_state_version_to_v2,
block_number,
block_timestamp,
withdrawal_block_timepoint,
withdrawal_finalized_timepoint,
expected_result,
} = case_param;

Expand Down Expand Up @@ -833,7 +833,7 @@ mod test {
.build();
let withdrawal_lock_args = WithdrawalLockArgs::new_builder()
.owner_lock_hash(owner_lock_script.hash().pack())
.withdrawal_block_timepoint(withdrawal_block_timepoint.full_value().pack())
.withdrawal_finalized_timepoint(withdrawal_finalized_timepoint.full_value().pack())
.build();
let withdrawal_cell = CellInfo {
output: CellOutput::new_builder()
Expand Down
6 changes: 3 additions & 3 deletions crates/generator/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ pub fn build_withdrawal_cell_output(
rollup_context: &RollupContext,
req: &WithdrawalRequestExtra,
block_hash: &H256,
block_timepoint: &Timepoint,
finalized_timepoint: &Timepoint,
opt_asset_script: Option<Script>,
) -> Result<(CellOutput, Bytes), WithdrawalCellError> {
let withdrawal_capacity: u64 = req.raw().capacity().unpack();
let lock_args: Bytes = {
let withdrawal_lock_args = WithdrawalLockArgs::new_builder()
.account_script_hash(req.raw().account_script_hash())
.withdrawal_block_hash(Into::<[u8; 32]>::into(*block_hash).pack())
.withdrawal_block_timepoint(block_timepoint.full_value().pack())
.withdrawal_finalized_timepoint(finalized_timepoint.full_value().pack())
.owner_lock_hash(req.raw().owner_lock_hash())
.build();

Expand Down Expand Up @@ -234,7 +234,7 @@ mod test {
);
assert_eq!(lock_args.withdrawal_block_hash(), block_hash.pack());
assert_eq!(
lock_args.withdrawal_block_timepoint().unpack(),
lock_args.withdrawal_finalized_timepoint().unpack(),
block_timepoint.full_value()
);
assert_eq!(lock_args.owner_lock_hash(), owner_lock.hash().pack());
Expand Down
44 changes: 22 additions & 22 deletions crates/jsonrpc-types/src/godwoken.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1371,12 +1371,12 @@ pub struct WithdrawalLockArgs {
// block timestamp.

// Before switching to v2, `withdrawal_block_number` should be `Some(block_number)` and
// `withdrawal_block_timestamp` should be `None`; afterwards, `withdrawal_block_number` will
// become `None` and `withdrawal_block_timestamp` will become `Some(block_timestamp)`.
// `withdrawal_finalized_timestamp` should be `None`; afterwards, `withdrawal_block_number` will
// become `None` and `withdrawal_finalized_timestamp` will become `Some(finalized_timestamp)`.
#[serde(skip_serializing_if = "Option::is_none")]
pub withdrawal_block_number: Option<Uint64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub withdrawal_block_timestamp: Option<Uint64>,
pub withdrawal_finalized_timestamp: Option<Uint64>,

// layer1 lock to withdraw after challenge period
pub owner_lock_hash: H256,
Expand All @@ -1390,46 +1390,46 @@ impl TryFrom<WithdrawalLockArgs> for packed::WithdrawalLockArgs {
account_script_hash,
withdrawal_block_hash,
withdrawal_block_number,
withdrawal_block_timestamp,
withdrawal_finalized_timestamp,
owner_lock_hash,
} = json;
let withdrawal_block_timepoint = match (withdrawal_block_number, withdrawal_block_timestamp)
{
(Some(block_number), None) => Timepoint::from_block_number(block_number.value()),
(None, Some(timestamp)) => Timepoint::from_timestamp(timestamp.value()),
(bn, bt) => {
return Err(anyhow!(
"conflict withdrawal_block_number {:?} and withdrawal_block_timestamp {:?}",
let withdrawal_finalized_timepoint =
match (withdrawal_block_number, withdrawal_finalized_timestamp) {
(Some(block_number), None) => Timepoint::from_block_number(block_number.value()),
(None, Some(timestamp)) => Timepoint::from_timestamp(timestamp.value()),
(bn, bt) => {
return Err(anyhow!(
"conflict withdrawal_block_number {:?} and withdrawal_finalized_timestamp {:?}",
bn,
bt
));
}
};
}
};

Ok(packed::WithdrawalLockArgs::new_builder()
.account_script_hash(account_script_hash.pack())
.withdrawal_block_hash(withdrawal_block_hash.pack())
.withdrawal_block_timepoint(withdrawal_block_timepoint.full_value().pack())
.withdrawal_finalized_timepoint(withdrawal_finalized_timepoint.full_value().pack())
.owner_lock_hash(owner_lock_hash.pack())
.build())
}
}

impl From<packed::WithdrawalLockArgs> for WithdrawalLockArgs {
fn from(data: packed::WithdrawalLockArgs) -> WithdrawalLockArgs {
let withdrawal_block_timepoint =
Timepoint::from_full_value(data.withdrawal_block_timepoint().unpack());
let (withdrawal_block_number, withdrawal_block_timestamp) = match withdrawal_block_timepoint
{
Timepoint::BlockNumber(block_number) => (Some(block_number), None),
Timepoint::Timestamp(timestamp) => (None, Some(timestamp)),
};
let withdrawal_finalized_timepoint =
Timepoint::from_full_value(data.withdrawal_finalized_timepoint().unpack());
let (withdrawal_block_number, withdrawal_finalized_timestamp) =
match withdrawal_finalized_timepoint {
Timepoint::BlockNumber(block_number) => (Some(block_number), None),
Timepoint::Timestamp(timestamp) => (None, Some(timestamp)),
};
Self {
account_script_hash: data.account_script_hash().unpack(),
owner_lock_hash: data.owner_lock_hash().unpack(),
withdrawal_block_hash: data.withdrawal_block_hash().unpack(),
withdrawal_block_number: withdrawal_block_number.map(Into::into),
withdrawal_block_timestamp: withdrawal_block_timestamp.map(Into::into),
withdrawal_finalized_timestamp: withdrawal_finalized_timestamp.map(Into::into),
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions crates/mem-pool/src/custodian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use crate::constants::MAX_CUSTODIANS;
pub fn to_custodian_cell(
rollup_context: &RollupContext,
block_hash: &H256,
block_timepoint: &Timepoint,
finalized_timepoint: &Timepoint,
deposit_info: &DepositInfo,
) -> Result<(CellOutput, Bytes), u128> {
let lock_args: Bytes = {
Expand All @@ -43,7 +43,7 @@ pub fn to_custodian_cell(

let custodian_lock_args = CustodianLockArgs::new_builder()
.deposit_block_hash(Into::<[u8; 32]>::into(*block_hash).pack())
.deposit_block_timepoint(block_timepoint.full_value().pack())
.deposit_finalized_timepoint(finalized_timepoint.full_value().pack())
.deposit_lock_args(deposit_lock_args)
.build();

Expand Down Expand Up @@ -298,7 +298,7 @@ async fn query_finalized_custodian_cells(
};

if !compatible_finalized_timepoint.is_finalized(&Timepoint::from_full_value(
custodian_lock_args.deposit_block_timepoint().unpack(),
custodian_lock_args.deposit_finalized_timepoint().unpack(),
)) {
continue;
}
Expand Down Expand Up @@ -464,7 +464,7 @@ mod tests {
) -> Vec<CellInfo> {
let args = {
let custodian_lock_args = CustodianLockArgs::new_builder()
.deposit_block_timepoint(last_finalized_timepoint.full_value().pack())
.deposit_finalized_timepoint(last_finalized_timepoint.full_value().pack())
.build();

let mut args = rollup_context.rollup_script_hash.as_slice().to_vec();
Expand Down
2 changes: 1 addition & 1 deletion crates/rpc-client/src/indexer_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ impl CKBIndexerClient {
let args = cell.output.lock.args.into_bytes();
let args = CustodianLockArgs::from_slice(&args[32..]).unwrap();
compatible_finalized_timepoint.is_finalized(&Timepoint::from_full_value(
args.deposit_block_timepoint().unpack(),
args.deposit_finalized_timepoint().unpack(),
))
};
if is_finalized {
Expand Down
4 changes: 2 additions & 2 deletions crates/rpc-client/src/rpc_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1132,7 +1132,7 @@ impl RPCClient {
Err(_) => continue,
};
if !compatible_finalized_timepoint.is_finalized(&Timepoint::from_full_value(
custodian_lock_args.deposit_block_timepoint().unpack(),
custodian_lock_args.deposit_finalized_timepoint().unpack(),
)) {
continue;
}
Expand Down Expand Up @@ -1231,7 +1231,7 @@ impl RPCClient {
};

if !compatible_finalized_timepoint.is_finalized(&Timepoint::from_full_value(
custodian_lock_args.deposit_block_timepoint().unpack(),
custodian_lock_args.deposit_finalized_timepoint().unpack(),
)) {
continue;
}
Expand Down
8 changes: 4 additions & 4 deletions crates/rpc-client/src/withdrawal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fn verify_finalized_owner_lock(
};

if !compatible_finalized_timepoint.is_finalized(&Timepoint::from_full_value(
lock_args.withdrawal_block_timepoint().unpack(),
lock_args.withdrawal_finalized_timepoint().unpack(),
)) {
bail!("unfinalized withdrawal");
}
Expand Down Expand Up @@ -101,7 +101,7 @@ mod test {
CompatibleFinalizedTimepoint::from_block_number(finalized_block_number, 0);
let lock_args = WithdrawalLockArgs::new_builder()
.owner_lock_hash(owner_lock.hash().pack())
.withdrawal_block_timepoint(last_finalized_timepoint.full_value().pack())
.withdrawal_finalized_timepoint(last_finalized_timepoint.full_value().pack())
.build();

let mut args = rollup_type_hash.to_vec();
Expand Down Expand Up @@ -137,7 +137,7 @@ mod test {
let err_lock_args = lock_args
.clone()
.as_builder()
.withdrawal_block_timepoint((last_finalized_timepoint.full_value() + 1).pack())
.withdrawal_finalized_timepoint((last_finalized_timepoint.full_value() + 1).pack())
.build();

let mut args = rollup_type_hash.to_vec();
Expand Down Expand Up @@ -219,7 +219,7 @@ mod test {
let last_finalized_timepoint = Timepoint::from_block_number(100);
let lock_args = WithdrawalLockArgs::new_builder()
.owner_lock_hash(owner_lock.hash().pack())
.withdrawal_block_timepoint(last_finalized_timepoint.full_value().pack())
.withdrawal_finalized_timepoint(last_finalized_timepoint.full_value().pack())
.build();

let mut args = rollup_type_hash.to_vec();
Expand Down
Loading

0 comments on commit a657ec5

Please sign in to comment.