Skip to content

refactor: use constant values as default values#1320

Merged
KaoImin merged 1 commit intomainfrom
yangby/refactor/unify-default-roots
Aug 16, 2023
Merged

refactor: use constant values as default values#1320
KaoImin merged 1 commit intomainfrom
yangby/refactor/unify-default-roots

Conversation

@chaoticlonghair
Copy link
Copy Markdown
Contributor

@chaoticlonghair chaoticlonghair 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

@chaoticlonghair chaoticlonghair 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
Copy Markdown
Contributor

KaoImin commented Aug 15, 2023

This PR should be refactor rather than perf.

@chaoticlonghair chaoticlonghair dismissed stale reviews from KaoImin and blckngm via 885aea6 August 15, 2023 08:01
@chaoticlonghair chaoticlonghair force-pushed the yangby/refactor/unify-default-roots branch 2 times, most recently from 885aea6 to 60bd51b Compare August 15, 2023 08:02
@chaoticlonghair chaoticlonghair 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.

@chaoticlonghair
Copy link
Copy Markdown
Contributor Author

@KaoImin There is no break changes.

@chaoticlonghair chaoticlonghair 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 Flouse and blckngm and removed request for Simon-Tl and wenyuanhust August 15, 2023 09:47
@KaoImin
Copy link
Copy Markdown
Contributor

KaoImin commented Aug 15, 2023

@yangby-cryptape need to rebase

@KaoImin

This comment was marked as off-topic.

@axon-bot
Copy link
Copy Markdown

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
@chaoticlonghair chaoticlonghair 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