Skip to content

fix: the default (or empty) values of genesis fields should be same as normal blocks#1468

Merged
KaoImin merged 1 commit intomainfrom
yangby/bugfix/genesis-default-fields
Oct 11, 2023
Merged

fix: the default (or empty) values of genesis fields should be same as normal blocks#1468
KaoImin merged 1 commit intomainfrom
yangby/bugfix/genesis-default-fields

Conversation

@chaoticlonghair
Copy link
Copy Markdown
Contributor

@chaoticlonghair chaoticlonghair commented Oct 10, 2023

What this PR does / why we need it?

This PR closes #1305.

Since no genesis transaction is allowed after #1454 merged:

  • transactions_root should always be the default value RLP_NULL as a normal block.

    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
    };

  • signed_txs_hash should always be the default value RLP_EMPTY_LIST as a normal block

    signed_txs_hash: digest_signed_transactions(&signed_txs),

    pub fn digest_signed_transactions(stxs: &[SignedTransaction]) -> Hash {
    if stxs.is_empty() {
    RLP_EMPTY_LIST
    } else {
    Hasher::digest(rlp::encode_list(stxs))
    }
    }

  • receipts_root should always be the default value RLP_NULL as a normal block.

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

  • log_bloom should always calculated from an empty logs vector.

    let logs = exec_resp
    .tx_resp
    .iter()
    .map(|r| Bloom::from(BloomInput::Raw(rlp::encode_list(&r.logs).as_ref())))
    .collect::<Vec<_>>();

    log_bloom: Bloom::from(BloomInput::Raw(
    rlp::encode_list(&logs).as_ref(),
    )),

    ⚠️ It's not same as Default::default().

    The Default::default() is all zeros, but for an empty logs vector, it's not.

    The difference is as following:

      0000000000000000000000000000000000000000000000000000000000000000
    - 0000000000000000000000000000000000000000000000000000000000000000
    + 0000000000000080000000000000000000000000000000000000000000000000
                    ^
    - 0000000000000000000000000000000000000000000000000000000000000000
    + 0000010000001000000000000000000000000000000000000000000000000000
           ^      ^
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
  • gas_used should always be zero.

What is the impact of this PR?

No Breaking Change

CI Settings

CI Usage

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

CI Switch

  • Web3 Compatible Tests
  • OCT 1-5 And 12-15
  • OCT 6-10
  • OCT 11
  • OCT 16-19
  • v3 Core Tests

CI Description

CI Name Description
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

@chaoticlonghair chaoticlonghair force-pushed the yangby/bugfix/genesis-default-fields branch from b46a295 to 9790514 Compare October 10, 2023 10:52
@chaoticlonghair chaoticlonghair changed the title fix: the default(empty) values of genesis fields should be same as normal blocks fix: the default (or empty) values of genesis fields should be same as normal blocks Oct 10, 2023
@chaoticlonghair chaoticlonghair force-pushed the yangby/bugfix/genesis-default-fields branch 2 times, most recently from 4ebbd9b to ae897df Compare October 10, 2023 11:03
@chaoticlonghair chaoticlonghair force-pushed the yangby/bugfix/genesis-default-fields branch from ae897df to a89018d Compare October 10, 2023 11:14
@chaoticlonghair chaoticlonghair marked this pull request as ready for review October 10, 2023 11:20
@chaoticlonghair chaoticlonghair requested a review from a team as a code owner October 10, 2023 11:20
@chaoticlonghair chaoticlonghair requested review from Flouse, driftluo, jjyr and wenyuanhust and removed request for jjyr and wenyuanhust October 10, 2023 11:20
@chaoticlonghair

This comment was marked as off-topic.

@github-actions
Copy link
Copy Markdown

CI tests run on commit:

CI test list:

  • OCT 1-5 And 12-15
  • OCT 6-10
  • OCT 11
  • OCT 16-19
  • v3 Core Tests
  • Web3 Compatible Tests

Please check ci test results later.

@KaoImin KaoImin enabled auto-merge October 10, 2023 13:45
@KaoImin KaoImin added this pull request to the merge queue Oct 11, 2023
Merged via the queue into main with commit cf935f6 Oct 11, 2023
@chaoticlonghair chaoticlonghair deleted the yangby/bugfix/genesis-default-fields branch October 11, 2023 02:36
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.

Transactions root of genesis block is incorrect

3 participants