Skip to content

Commit

Permalink
schema: rename timepoints
Browse files Browse the repository at this point in the history
  • Loading branch information
keroro520 committed Nov 16, 2022
1 parent d4e6dc1 commit 52ab220
Show file tree
Hide file tree
Showing 24 changed files with 119 additions and 119 deletions.
4 changes: 3 additions & 1 deletion crates/block-producer/src/custodian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ async fn query_mergeable_ckb_custodians(
Err(_) => continue,
};
if !compatible_finalized_timepoint.is_finalized(&Timepoint::from_full_value(
custodian_lock_args_reader.deposit_block_number().unpack(),
custodian_lock_args_reader
.deposit_block_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_timepoint = {
let stake_block_timepoint = {
let block_number: u64 = block.raw().number().unpack();
if rollup_context.global_state_version(block_number) < 2 {
Timepoint::from_block_number(block_number)
Expand All @@ -51,7 +51,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_number(stake_timepoint.full_value().pack())
.stake_block_timepoint(stake_block_timepoint.full_value().pack())
.build();
let rollup_type_hash = rollup_context.rollup_script_hash.as_slice().iter();
rollup_type_hash
Expand Down Expand Up @@ -183,7 +183,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_number().unpack(),
stake_lock_args.stake_block_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
4 changes: 2 additions & 2 deletions crates/block-producer/src/withdrawal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ mod test {
let withdrawal_without_owner_lock = {
let lock_args = WithdrawalLockArgs::new_builder()
.owner_lock_hash(owner_lock.hash().pack())
.withdrawal_block_number(last_finalized_timepoint.full_value().pack())
.withdrawal_block_timepoint(last_finalized_timepoint.full_value().pack())
.build();

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

let mut args = rollup_type.hash().to_vec();
Expand Down
4 changes: 2 additions & 2 deletions crates/generator/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub fn build_withdrawal_cell_output(
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_number(block_timepoint.full_value().pack())
.withdrawal_block_timepoint(block_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_number().unpack(),
lock_args.withdrawal_block_timepoint().unpack(),
block_timepoint.full_value()
);
assert_eq!(lock_args.owner_lock_hash(), owner_lock.hash().pack());
Expand Down
4 changes: 2 additions & 2 deletions crates/jsonrpc-types/src/godwoken.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1339,15 +1339,15 @@ impl From<WithdrawalLockArgs> for packed::WithdrawalLockArgs {
packed::WithdrawalLockArgs::new_builder()
.account_script_hash(account_script_hash.pack())
.withdrawal_block_hash(withdrawal_block_hash.pack())
.withdrawal_block_number(withdrawal_block_number.value().pack())
.withdrawal_block_timepoint(withdrawal_block_number.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_number: u64 = data.withdrawal_block_number().unpack();
let withdrawal_block_number: u64 = data.withdrawal_block_timepoint().unpack();
Self {
account_script_hash: data.account_script_hash().unpack(),
owner_lock_hash: data.owner_lock_hash().unpack(),
Expand Down
6 changes: 3 additions & 3 deletions crates/mem-pool/src/custodian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,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_number(block_timepoint.full_value().pack())
.deposit_block_timepoint(block_timepoint.full_value().pack())
.deposit_lock_args(deposit_lock_args)
.build();

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

if !compatible_finalized_timepoint.is_finalized(&Timepoint::from_full_value(
custodian_lock_args.deposit_block_number().unpack(),
custodian_lock_args.deposit_block_timepoint().unpack(),
)) {
continue;
}
Expand Down Expand Up @@ -462,7 +462,7 @@ mod tests {
) -> Vec<CellInfo> {
let args = {
let custodian_lock_args = CustodianLockArgs::new_builder()
.deposit_block_number(last_finalized_timepoint.full_value().pack())
.deposit_block_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 @@ -144,7 +144,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_number().unpack(),
args.deposit_block_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 @@ -1135,7 +1135,7 @@ impl RPCClient {
Err(_) => continue,
};
if !compatible_finalized_timepoint.is_finalized(&Timepoint::from_full_value(
custodian_lock_args.deposit_block_number().unpack(),
custodian_lock_args.deposit_block_timepoint().unpack(),
)) {
continue;
}
Expand Down Expand Up @@ -1233,7 +1233,7 @@ impl RPCClient {
};

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

if !compatible_finalized_timepoint.is_finalized(&Timepoint::from_full_value(
lock_args.withdrawal_block_number().unpack(),
lock_args.withdrawal_block_timepoint().unpack(),
)) {
println!(
"lock_args.withdrawal_block_number: {}, compatible_finalized_timepoint: {:?}",
lock_args.withdrawal_block_number().unpack(),
compatible_finalized_timepoint,
);
bail!("unfinalized withdrawal");
}

Expand Down Expand Up @@ -107,7 +102,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_number(last_finalized_timepoint.full_value().pack())
.withdrawal_block_timepoint(last_finalized_timepoint.full_value().pack())
.build();

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

let mut args = rollup_type_hash.to_vec();
Expand Down Expand Up @@ -225,7 +220,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_number(last_finalized_timepoint.full_value().pack())
.withdrawal_block_timepoint(last_finalized_timepoint.full_value().pack())
.build();

let mut args = rollup_type_hash.to_vec();
Expand Down
26 changes: 13 additions & 13 deletions crates/tests/src/script_tests/state_validator/submit_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ async fn test_submit_block() {
};
let output_stake_cell = {
let lock_args = StakeLockArgs::new_builder()
.stake_block_number(Pack::pack(&1))
.stake_block_timepoint(Pack::pack(&1))
.build();
build_rollup_locked_cell(
&rollup_type_script.hash(),
Expand Down Expand Up @@ -208,7 +208,7 @@ async fn test_downgrade_rollup_cell() {
};
let output_stake_cell = {
let lock_args = StakeLockArgs::new_builder()
.stake_block_number(Pack::pack(&1))
.stake_block_timepoint(Pack::pack(&1))
.build();
build_rollup_locked_cell(
&rollup_type_script.hash(),
Expand Down Expand Up @@ -342,7 +342,7 @@ async fn test_v1_block_timestamp_smaller_or_equal_than_previous_block_in_submit_
};
let output_stake_cell = {
let lock_args = StakeLockArgs::new_builder()
.stake_block_number(Pack::pack(&1))
.stake_block_timepoint(Pack::pack(&1))
.build();
build_rollup_locked_cell(
&rollup_type_script.hash(),
Expand Down Expand Up @@ -552,7 +552,7 @@ async fn test_v1_block_timestamp_bigger_than_rollup_input_since_in_submit_block(
};
let output_stake_cell = {
let lock_args = StakeLockArgs::new_builder()
.stake_block_number(Pack::pack(&1))
.stake_block_timepoint(Pack::pack(&1))
.build();
build_rollup_locked_cell(
&rollup_type_script.hash(),
Expand Down Expand Up @@ -693,7 +693,7 @@ async fn test_v0_v1_wrong_global_state_tip_block_timestamp_in_submit_block() {
};
let output_stake_cell = {
let lock_args = StakeLockArgs::new_builder()
.stake_block_number(Pack::pack(&1))
.stake_block_timepoint(Pack::pack(&1))
.build();
build_rollup_locked_cell(
&rollup_type_script.hash(),
Expand Down Expand Up @@ -920,7 +920,7 @@ async fn test_check_reverted_cells_in_submit_block() {
};
let output_stake_cell = {
let lock_args = StakeLockArgs::new_builder()
.stake_block_number(Pack::pack(&1))
.stake_block_timepoint(Pack::pack(&1))
.build();
build_rollup_locked_cell(
&rollup_type_script.hash(),
Expand Down Expand Up @@ -963,7 +963,7 @@ async fn test_check_reverted_cells_in_submit_block() {
let args = CustodianLockArgs::new_builder()
.deposit_lock_args(deposit_args.clone())
.deposit_block_hash(Pack::pack(&revert_block_hash))
.deposit_block_number(Pack::pack(&revert_block_number))
.deposit_block_timepoint(Pack::pack(&revert_block_number))
.build();
let cell = build_rollup_locked_cell(
&rollup_type_script.hash(),
Expand All @@ -988,7 +988,7 @@ async fn test_check_reverted_cells_in_submit_block() {
let owner_lock = Script::default();
let lock_args = WithdrawalLockArgs::new_builder()
.withdrawal_block_hash(Pack::pack(&revert_block_hash))
.withdrawal_block_number(Pack::pack(&revert_block_number))
.withdrawal_block_timepoint(Pack::pack(&revert_block_number))
.owner_lock_hash(Pack::pack(&owner_lock.hash()))
.build();
let mut args = Vec::new();
Expand All @@ -1007,7 +1007,7 @@ async fn test_check_reverted_cells_in_submit_block() {
let output_reverted_custodian_cell = {
let args = CustodianLockArgs::new_builder()
.deposit_block_hash(Pack::pack(&[0u8; 32]))
.deposit_block_number(Pack::pack(&0))
.deposit_block_timepoint(Pack::pack(&0))
.build();
build_rollup_locked_cell(
&rollup_type_script.hash(),
Expand All @@ -1025,7 +1025,7 @@ async fn test_check_reverted_cells_in_submit_block() {
.map(|_| {
let args = CustodianLockArgs::new_builder()
.deposit_block_hash(Pack::pack(&[0u8; 32]))
.deposit_block_number(Pack::pack(&0))
.deposit_block_timepoint(Pack::pack(&0))
.build();
let cell = build_rollup_locked_cell(
&rollup_type_script.hash(),
Expand All @@ -1045,7 +1045,7 @@ async fn test_check_reverted_cells_in_submit_block() {
.map(|_| {
let args = CustodianLockArgs::new_builder()
.deposit_block_hash(Pack::pack(&[0u8; 32]))
.deposit_block_number(Pack::pack(&0))
.deposit_block_timepoint(Pack::pack(&0))
.build();
build_rollup_locked_cell(
&rollup_type_script.hash(),
Expand Down Expand Up @@ -1340,7 +1340,7 @@ async fn test_withdrawal_cell_lock_args_with_owner_lock_in_submit_block() {
let output_stake_cell = {
let block_number = block_result.block.raw().number();
let lock_args = StakeLockArgs::new_builder()
.stake_block_number(block_number)
.stake_block_timepoint(block_number)
.build();
build_rollup_locked_cell(
&rollup_type_script.hash(),
Expand Down Expand Up @@ -1381,7 +1381,7 @@ async fn test_withdrawal_cell_lock_args_with_owner_lock_in_submit_block() {
// build withdrawal output
let output_withdrawal_cell = {
let lock_args = WithdrawalLockArgs::new_builder()
.withdrawal_block_number(block_result.block.raw().number())
.withdrawal_block_timepoint(block_result.block.raw().number())
.withdrawal_block_hash(Pack::pack(&block_result.block.raw().hash()))
.account_script_hash(Pack::pack(&account_script.hash()))
.owner_lock_hash(Pack::pack(&account_script.hash()))
Expand Down
21 changes: 12 additions & 9 deletions crates/tests/src/script_tests/withdrawal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ fn test_unlock_withdrawal_via_finalize_by_input_owner_cell() {
let rollup_type_hash = rollup_type_script.hash();
let (mut verify_ctx, script_ctx) = build_verify_context();

let withdrawal_timepoint = Timepoint::from_block_number(rand::random::<u32>() as u64 + 100);
let withdrawal_block_timepoint =
Timepoint::from_block_number(rand::random::<u32>() as u64 + 100);
let (block_merkle_state, last_finalized_timepoint) =
mock_global_state_timepoint_by_finalized_timepoint(
&verify_ctx.rollup_config(),
&withdrawal_timepoint,
&withdrawal_block_timepoint,
);
let rollup_cell = {
let global_state = GlobalState::new_builder()
Expand Down Expand Up @@ -91,7 +92,7 @@ fn test_unlock_withdrawal_via_finalize_by_input_owner_cell() {
let lock_args = WithdrawalLockArgs::new_builder()
.account_script_hash(random_always_success_script().hash().pack())
.withdrawal_block_hash(random_always_success_script().hash().pack())
.withdrawal_block_number(withdrawal_timepoint.full_value().pack())
.withdrawal_block_timepoint(withdrawal_block_timepoint.full_value().pack())
.owner_lock_hash(owner_lock.hash().pack())
.build();
let mut args = Vec::new();
Expand Down Expand Up @@ -182,11 +183,12 @@ fn test_unlock_withdrawal_via_finalize_by_switch_indexed_output_to_owner_lock()
let rollup_type_hash = rollup_type_script.hash();
let (mut verify_ctx, script_ctx) = build_verify_context();

let withdrawal_timepoint = Timepoint::from_block_number(rand::random::<u32>() as u64 + 100);
let withdrawal_block_timepoint =
Timepoint::from_block_number(rand::random::<u32>() as u64 + 100);
let (block_merkle_state, last_finalized_timepoint) =
mock_global_state_timepoint_by_finalized_timepoint(
&verify_ctx.rollup_config(),
&withdrawal_timepoint,
&withdrawal_block_timepoint,
);
let rollup_cell = {
let global_state = GlobalState::new_builder()
Expand All @@ -213,7 +215,7 @@ fn test_unlock_withdrawal_via_finalize_by_switch_indexed_output_to_owner_lock()
let lock_args = WithdrawalLockArgs::new_builder()
.account_script_hash(random_always_success_script().hash().pack())
.withdrawal_block_hash(random_always_success_script().hash().pack())
.withdrawal_block_number(withdrawal_timepoint.full_value().pack())
.withdrawal_block_timepoint(withdrawal_block_timepoint.full_value().pack())
.owner_lock_hash(owner_lock.hash().pack())
.build();

Expand Down Expand Up @@ -359,11 +361,12 @@ fn test_unlock_withdrawal_via_finalize_fallback_to_input_owner_cell() {
let rollup_type_hash = rollup_type_script.hash();
let (mut verify_ctx, script_ctx) = build_verify_context();

let withdrawal_timepoint = Timepoint::from_block_number(rand::random::<u32>() as u64 + 100);
let withdrawal_block_timepoint =
Timepoint::from_block_number(rand::random::<u32>() as u64 + 100);
let (block_merkle_state, last_finalized_timepoint) =
mock_global_state_timepoint_by_finalized_timepoint(
&verify_ctx.rollup_config(),
&withdrawal_timepoint,
&withdrawal_block_timepoint,
);
let rollup_cell = {
let global_state = GlobalState::new_builder()
Expand Down Expand Up @@ -410,7 +413,7 @@ fn test_unlock_withdrawal_via_finalize_fallback_to_input_owner_cell() {
let lock_args = WithdrawalLockArgs::new_builder()
.account_script_hash(random_always_success_script().hash().pack())
.withdrawal_block_hash(random_always_success_script().hash().pack())
.withdrawal_block_number(withdrawal_timepoint.full_value().pack())
.withdrawal_block_timepoint(withdrawal_block_timepoint.full_value().pack())
.owner_lock_hash(owner_lock.hash().pack())
.build();

Expand Down
Loading

0 comments on commit 52ab220

Please sign in to comment.