Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: change timepoint interpretation #897

Merged

Conversation

keroro520
Copy link
Contributor

@keroro520 keroro520 commented Dec 12, 2022

The PR brings two major changes:

  • The interpretation of both the block timepoint change from occurance block timestamp to future finalized timestamp, as well the global state last finalized timepoint change from last finalized timestamp to current timestamp.

    You can see the differences via diff:

let block_timepoint = {
    if fork_config.use_timestamp_as_timepoint(block_number) {
-       Timepoint::from_timestamp(block_timestamp)
+       let finality_time_in_ms = rollup_config.finality_time_in_ms();
+       Timepoint::from_timestamp(block_timestamp + finality_time_in_ms)
    } else {
        Timepoint::from_block_number(block_number)
    }
};
let last_finalized_timepoint = if fork_config.use_timestamp_as_timepoint(block_number) {
-   let finality_time_in_ms = rollup_context.rollup_config.finality_time_in_ms();
-   Timepoint::from_timestamp(block_timestamp.saturating_sub(finality_time_in_ms))
+   Timepoint::from_timestamp(block_timestamp)
} else {
    let finality_as_blocks = rollup_config.finality_blocks();
    Timepoint::from_block_number(block_number.saturating_sub(finality_as_blocks))
};

Note that WithdrawalLockArgs.withdrawal_block_timepoint, CustodianLockArgs.deposit_block_timepoint and StakeLockArgs.stake_block_timepoint is also block timepoint.

  • Check v2 withdrawal cell finality based on input since.

    Without replying GlobalState, or say rollup_state_cell, we still can check a v2 withdrawal cell finality based on input since, so that avoid celldep-race issue.


Proposal for further changes:

  • Rename Timepoint::BlockNumber to Timepoint::Lagecy, Timepoint::Timestamp to Timepoint::New
  • Consider to rename GlobalState.lats_finalized_timepoint, WithdrawalLockArgs.withdrawal_block_timepoint, CustodianLockArgs.deposit_block_timepoint and StakeLockArgs.stake_block_timepoint.

This PR will not make these changes, since I am having some problems bumping gw-types in the "develop" branch.

Adapting block.timepoint to the new form also adapts
withdrawal_block_timepoint, deposit_block_timepoint, and stake_block_timepoint,
which must all be equal to block.timepoint.
The global state should have the last_finalized_timepoint equal to the
input.since, do not add the finality_time_in_ms.
@keroro520 keroro520 force-pushed the feat-new-interpretation-of-timepoint branch from 3719abe to 24624ad Compare December 12, 2022 03:08
@@ -303,6 +321,20 @@ pub fn unlock_to_owner(
}))
}

fn is_v1_withdrawal_cell(withdrawal_cell: &CellInfo) -> bool {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fn is_v1_withdrawal_cell(withdrawal_cell: &CellInfo) -> bool {
fn is_block_finalized_withdrawal_cell(withdrawal_cell: &CellInfo) -> bool {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"is_block_finalized_withdrawal_cell" is more confusing for me. How about "is_legacy_withdrawal_cell"?

crates/block-producer/src/utils.rs Show resolved Hide resolved
use gw_types::packed::RollupConfig;
use gw_types::prelude::*;

pub fn block_timepoint(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub fn block_timepoint(
pub fn finalized_timepoint(

@jjyr
Copy link
Collaborator

jjyr commented Dec 12, 2022

@zeroqn @sopium I will send another PR to rename structures after merging this PR.

@jjyr jjyr merged commit beafdab into godwokenrises:develop Dec 13, 2022
@jjyr jjyr mentioned this pull request Dec 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants