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

refactor(relay): split compact block execute code, more readable #3244

Merged
merged 1 commit into from
Dec 29, 2021
Merged

refactor(relay): split compact block execute code, more readable #3244

merged 1 commit into from
Dec 29, 2021

Conversation

chanhsu001
Copy link
Contributor

@chanhsu001 chanhsu001 commented Dec 20, 2021

What problem does this PR solve?

  • refactor compact block execute code, split compact block pre-check code into
    non_contextual_check() and contextual_check() function
  • move post process code into missing_or_collided_post_process()
    after failed to rebuild whole block, found missing or collided transactions.
  • use header reference instead of into_view() and import PendingCompactBlockMap
  • add function comment in markdown format

i still not sure about function comments, please help.

Problem Summary:
the execute() function is about 250 lines, and contains some of pre-checks, and post-process after re-build block failed.
i tried to make it more readable and hope you guys provide suggestions about how to make refactor better.

What is changed and how it works?

What's Changed:
only split bunch of codes into 3 functions, not mean to change logic and behavior
I've run test and integration-test and passed ("Refactor Flow" should include these tests).

Related changes

Check List

Tests

  • Unit test
  • Integration test

Release note

None: Exclude this PR from the release note.

Copy link
Contributor

@keroro520 keroro520 left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines +314 to +333
pending_compact_blocks
.entry(block_hash.clone())
.or_insert_with(|| (compact_block, HashMap::default(), unix_time_as_millis()))
.1
.insert(peer, (missing_transactions.clone(), missing_uncles.clone()));

let content = packed::GetBlockTransactions::new_builder()
.block_hash(block_hash)
.indexes(missing_transactions.pack())
.uncle_indexes(missing_uncles.pack())
.build();
let message = packed::RelayMessage::new_builder().set(content).build();
let sending = send_message_to(nc.as_ref(), peer, &message);
if !sending.is_ok() {
ckb_logger::warn_target!(
crate::LOG_TARGET_RELAY,
"ignore the sending message error, error: {}",
sending
);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

let content = packed::GetBlockTransactions::new_builder()
    .block_hash(block_hash)
    .indexes(missing_transactions.pack())
    .uncle_indexes(missing_uncles.pack())
    .build();
let message = packed::RelayMessage::new_builder().set(content).build();
match send_message_to(nc.as_ref(), peer, &message) {
    Ok(_) => {
        pending_compact_blocks
            .entry(block_hash.clone())
            .or_insert_with(|| (compact_block, HashMap::default(), unix_time_as_millis()))
            .1
            .insert(peer, (missing_transactions, missing_uncles));
    }
    Err(err) => {
        ckb_logger::warn_target!(
            crate::LOG_TARGET_RELAY,
            "ignore the sending message error, error: {:?}",
            err
        );
    }
}

@chanhsu001
Copy link
Contributor Author

bors merge=driftluo,keroro520

@bors bors bot merged commit da930dc into nervosnetwork:develop Dec 29, 2021
@chanhsu001 chanhsu001 deleted the factor_compact_block_process branch December 30, 2021 02:28
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.

None yet

3 participants