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

Create RawBitcoinTx wrapper type for Transaction #605

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

prajwolrg
Copy link
Contributor

@prajwolrg prajwolrg commented Jan 9, 2025

Description

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature/Enhancement (non-breaking change which adds functionality or enhances an existing one)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactor
  • New or updated tests
  • Dependency Update

Notes to Reviewers

Checklist

  • I have performed a self-review of my code.
  • I have commented my code where necessary.
  • I have updated the documentation if needed.
  • My changes do not introduce new warnings.
  • I have added tests that prove my changes are effective or that my feature works.
  • New and existing tests pass with my changes.

Related Issues

@prajwolrg prajwolrg force-pushed the refactor/l1tx branch 2 times, most recently from 38589c9 to 00c4308 Compare January 9, 2025 15:31
@prajwolrg prajwolrg changed the title Refactor/l1tx Creates BitcoinTx wrapper type for Transaction Jan 9, 2025
Copy link
Contributor

github-actions bot commented Jan 9, 2025

Commit: ca87374

SP1 Performance Test Results

program cycles success
BTC_BLOCKSPACE 7,240,308
EL_BLOCK 100,508
CL_BLOCK 57,784
L1_BATCH 7,270,290
L2_BATCH 5,448
CHECKPOINT 15,941

@prajwolrg prajwolrg marked this pull request as ready for review January 9, 2025 15:54
@prajwolrg prajwolrg requested review from a team as code owners January 9, 2025 15:54
Copy link

codecov bot commented Jan 9, 2025

Codecov Report

Attention: Patch coverage is 87.05882% with 11 lines in your changes missing coverage. Please review.

Project coverage is 56.63%. Comparing base (c527f70) to head (670e539).

Files with missing lines Patch % Lines
bin/strata-client/src/extractor.rs 55.00% 9 Missing ⚠️
crates/primitives/src/l1/btc.rs 98.21% 1 Missing ⚠️
crates/state/src/l1/utils.rs 0.00% 1 Missing ⚠️
@@            Coverage Diff             @@
##             main     #605      +/-   ##
==========================================
- Coverage   56.68%   56.63%   -0.05%     
==========================================
  Files         313      313              
  Lines       32505    32540      +35     
==========================================
+ Hits        18425    18429       +4     
- Misses      14080    14111      +31     
Files with missing lines Coverage Δ
crates/chaintsn/src/transition.rs 82.86% <100.00%> (ø)
crates/consensus-logic/src/csm/state_tracker.rs 45.60% <100.00%> (ø)
crates/rocksdb-store/src/l1/db.rs 97.29% <100.00%> (ø)
crates/rocksdb-store/src/l2/db.rs 99.42% <100.00%> (-0.01%) ⬇️
crates/state/src/l1/tx.rs 67.64% <100.00%> (+2.94%) ⬆️
crates/test-utils/src/l2.rs 99.09% <100.00%> (ø)
crates/primitives/src/l1/btc.rs 83.08% <98.21%> (+1.15%) ⬆️
crates/state/src/l1/utils.rs 58.33% <0.00%> (+2.33%) ⬆️
bin/strata-client/src/extractor.rs 94.57% <55.00%> (-1.95%) ⬇️

... and 4 files with indirect coverage changes

Copy link
Contributor

@bewakes bewakes left a comment

Choose a reason for hiding this comment

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

Looks good, but I want to confirm this with @delbonis. There must have been a reason why Vec<u8> was previously chosen for L1Tx.tx.

@storopoli
Copy link
Member

@prajwolrg prajwolrg requested a review from delbonis January 10, 2025 15:46
@delbonis
Copy link
Contributor

I'm soft against putting nontrivial structural checks which we "don't own" close to the database like this. The database layer should be concerned with just ensuring that the general shape of the data is sane, not that it's semantically correct.

bin/strata-client/src/extractor.rs Show resolved Hide resolved
crates/primitives/src/l1.rs Outdated Show resolved Hide resolved
@prajwolrg prajwolrg requested a review from delbonis January 14, 2025 15:22
@prajwolrg prajwolrg changed the title Creates BitcoinTx wrapper type for Transaction Creates RawBitcoinTx wrapper type for Transaction Jan 14, 2025
delbonis
delbonis previously approved these changes Jan 14, 2025
crates/primitives/src/l1.rs Outdated Show resolved Hide resolved
crates/primitives/src/l1.rs Outdated Show resolved Hide resolved
crates/primitives/src/l1.rs Outdated Show resolved Hide resolved
crates/primitives/src/l1.rs Outdated Show resolved Hide resolved
@prajwolrg prajwolrg requested a review from storopoli January 15, 2025 11:12
@prajwolrg prajwolrg changed the title Creates RawBitcoinTx wrapper type for Transaction Create RawBitcoinTx wrapper type for Transaction Jan 15, 2025
Comment on lines +825 to +828
/// Represents a raw, byte-encoded Bitcoin transaction with custom [`Arbitrary`] support.
/// Provides conversions (via [`TryFrom`]) to and from [`Transaction`].
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, BorshSerialize, BorshDeserialize)]
pub struct RawBitcoinTx(Vec<u8>);
Copy link
Member

Choose a reason for hiding this comment

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

This should come before the impls. Can you move it up?

Comment on lines +750 to +762
impl TryFrom<RawBitcoinTx> for Transaction {
type Error = encode::Error;
fn try_from(value: RawBitcoinTx) -> Result<Self, Self::Error> {
deserialize(&value.0)
}
}

impl TryFrom<&RawBitcoinTx> for Transaction {
type Error = encode::Error;
fn try_from(value: &RawBitcoinTx) -> Result<Self, Self::Error> {
deserialize(&value.0)
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Can you add trivial tests:

  • case when the transaction is valid in bytes and the TryFrom succeeds
  • case when the transaction is invalid in bytes and the TryFrom fails

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.

4 participants