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: use constant values as default values #1320

Merged
merged 1 commit into from
Aug 16, 2023

Conversation

yangby-cryptape
Copy link
Collaborator

@yangby-cryptape yangby-cryptape commented Aug 15, 2023

What this PR does / why we need it:

Before this PR, some values use constant values to set the default values, and some are not.

Click for example.

let txs_root = if !txs.hashes.is_empty() {
TrieMerkle::from_iter(txs.hashes.iter().enumerate())
.root_hash()
.unwrap_or_else(|err| {
panic!("failed to calculate trie root hash for transactions since {err}")
})
} else {
RLP_NULL
};

In fact, the above code is the same as

let txs_root = { 
    TrieMerkle::from_iter(txs.hashes.iter().enumerate()) 
        .root_hash() 
        .unwrap_or_else(|err| { 
            panic!("failed to calculate trie root hash for transactions since {err}") 
        })
}; 

The only difference is avoiding some computations, so that improve a little performance.


In this PR:

  • Unify the value assignments of those roots.
  • Add documentation how these constant value come.

Which issue(s) this PR fixes:

Fixes #

Which docs this PR relation:

Ref #1318

Which toolchain this PR adaption:

No Breaking Change

Special notes for your reviewer:

NIL

CI Description

CI Name Description
Chaos CI Test the liveness and robustness of Axon under terrible network condition
Cargo Clippy Run cargo clippy --all --all-targets --all-features
Coverage Test Get the unit test coverage report
E2E Test Run end-to-end test to check interfaces
Code Format Run cargo +nightly fmt --all -- --check and cargo sort -gwc
Web3 Compatible Test Test the Web3 compatibility of Axon
v3 Core Test Run the compatibility tests provided by Uniswap V3
OCT 1-5 | 6-10 | 11 | 12-15 | 16-19 Run the compatibility tests provided by OpenZeppelin

CI Usage

Check the CI you want to run below, and then comment /run-ci.

CI Switch

  • Chaos CI
  • Cargo Clippy
  • Coverage Test
  • E2E Tests
  • Code Format
  • Unit Tests
  • Web3 Compatible Tests
  • OCT 1-5 And 12-15
  • OCT 6-10
  • OCT 11
  • OCT 16-19
  • v3 Core Tests

@yangby-cryptape yangby-cryptape requested a review from a team as a code owner August 15, 2023 02:19
@github-actions github-actions bot added the enhancement New feature or request label Aug 15, 2023
blckngm
blckngm previously approved these changes Aug 15, 2023
KaoImin
KaoImin previously approved these changes Aug 15, 2023
@KaoImin KaoImin added this pull request to the merge queue Aug 15, 2023
@KaoImin KaoImin removed this pull request from the merge queue due to a manual request Aug 15, 2023
@KaoImin

This comment was marked as off-topic.

@axon-bot

This comment was marked as outdated.

@KaoImin KaoImin changed the title perf: use constant values as default values perf!: use constant values as default values Aug 15, 2023
@KaoImin
Copy link
Contributor

KaoImin commented Aug 15, 2023

This PR should be refactor rather than perf.

@yangby-cryptape yangby-cryptape dismissed stale reviews from KaoImin and blckngm via 885aea6 August 15, 2023 08:01
@yangby-cryptape yangby-cryptape force-pushed the yangby/refactor/unify-default-roots branch 2 times, most recently from 885aea6 to 60bd51b Compare August 15, 2023 08:02
@yangby-cryptape yangby-cryptape changed the title perf!: use constant values as default values refactor: use constant values as default values Aug 15, 2023
KaoImin
KaoImin previously approved these changes Aug 15, 2023
@KaoImin KaoImin changed the title refactor: use constant values as default values refactor!: use constant values as default values Aug 15, 2023
@KaoImin

This comment was marked as off-topic.

@axon-bot

This comment was marked as outdated.

@yangby-cryptape
Copy link
Collaborator Author

@KaoImin There is no break changes.

@yangby-cryptape yangby-cryptape removed the enhancement New feature or request label Aug 15, 2023
@KaoImin KaoImin changed the title refactor!: use constant values as default values refactor: use constant values as default values Aug 15, 2023
@KaoImin KaoImin requested review from blckngm and Flouse and removed request for wenyuanhust and Simon-Tl August 15, 2023 09:47
@KaoImin
Copy link
Contributor

KaoImin commented Aug 15, 2023

@yangby-cryptape need to rebase

@KaoImin

This comment was marked as off-topic.

@axon-bot
Copy link

axon-bot bot commented Aug 16, 2023

CI tests run on commit:

CI test list:

  • Code Format
  • Cargo Clippy
  • E2E Tests
  • Unit Tests
  • Web3 Compatible Tests

Please check ci test results later.

@KaoImin KaoImin added this pull request to the merge queue Aug 16, 2023
@KaoImin KaoImin removed this pull request from the merge queue due to a manual request Aug 16, 2023
@KaoImin KaoImin added this pull request to the merge queue Aug 16, 2023
Merged via the queue into main with commit f29d8b0 Aug 16, 2023
@yangby-cryptape yangby-cryptape deleted the yangby/refactor/unify-default-roots branch August 16, 2023 02:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants