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

Legacy Chain Check #2308

Closed
15 tasks
oxarbitrage opened this issue Jun 15, 2021 · 0 comments · Fixed by #2366
Closed
15 tasks

Legacy Chain Check #2308

oxarbitrage opened this issue Jun 15, 2021 · 0 comments · Fixed by #2366
Assignees
Labels
A-rust Area: Updates to Rust code C-enhancement Category: This is an improvement NU-5 Network Upgrade: NU5 specific tasks

Comments

@oxarbitrage
Copy link
Contributor

oxarbitrage commented Jun 15, 2021

Solution

Check Finalized Transaction network_upgrade field

V5 transactions have a network_upgrade field. If Zebra has followed a legacy chain, the network_upgrade field will be different to the calculated network_upgrade for that height.

In StateService::new, immediately after the new state is created:

  • get a block iterator using new_service.any_ancestor_blocks(new_service.best_tip().1)
    • if the state is empty, and the best_tip() is None, skip the legacy chain check
  • call a function that does the following checks on each block in the iterator:
    • if the block height is less than the NU5 activation height, or there is no NU5 activation height, return Ok(())
    • if you've checked 100 blocks, return an error
      • this check finds pre-NU5 legacy chains, because they don't have V5 transactions with network upgrade fields
    • if Block.check_transaction_network_upgrade (Move the Transaction network upgrade check to zebra-chain #2343) returns an error, return an error
    • if there is at least one transaction with a network_upgrade, and Block.check_transaction_network_upgrade returns success, return Ok(())

Panic and Log User Action

If the finalized tip doesn't pass validation:

Testing

Unit Tests

Test that the legacy chain function works:

If the block height is less than the NU5 activation height, or there is no NU5 activation height, return Ok(())

  • test fake v5 blocks that are less than the NU5 activation height
    let mut fake_block = original_block.clone();
    fake_block.transactions = fake_block
    .transactions
    .iter()
    .map(AsRef::as_ref)
    .map(|t| arbitrary::transaction_to_fake_v5(t, network, Height(*height)))
    .map(Into::into)
    .collect();
  • proptest a block vector containing at least 100 blocks, starting less than 100 blocks past the NU5 activation height

If you've checked 100 blocks, return an error:

If Block.check_transaction_network_upgrade returns an error, return that error:

  • proptest a block vector starting 100 blocks or more past the NU5 activation height

If there is at least one transaction with a network_upgrade, and Block.check_transaction_network_upgrade returns success, return Ok(())

  • proptest a block vector containing blocks at the NU5 activation height or higher
    • in some tests, some blocks should be lower than the NU5 activation height
    • the transactions need to be V5 and have valid network_upgrade fields, use the transaction version override and valid network upgrade overrides from Add property test strategies for V5 transactions #2347

Success Cached State Test

Check that the legacy chain check passes in the existing cached state tests:

  • search the log output to make sure that the legacy chain check runs and passes
    • add a log at info level when starting the check
    • add a log at info level when the check passes

This is part of a split of #1820

@oxarbitrage oxarbitrage added this to the 2021 Sprint 12 milestone Jun 15, 2021
@oxarbitrage oxarbitrage added A-rust Area: Updates to Rust code NU-5 Network Upgrade: NU5 specific tasks P-Medium C-enhancement Category: This is an improvement S-needs-triage Status: A bug report needs triage labels Jun 15, 2021
@mpguerra mpguerra removed the S-needs-triage Status: A bug report needs triage label Jun 17, 2021
@oxarbitrage oxarbitrage self-assigned this Jun 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rust Area: Updates to Rust code C-enhancement Category: This is an improvement NU-5 Network Upgrade: NU5 specific tasks
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants