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

Separate all bitcoinconsensus validation stuff in module #330

Closed
wants to merge 4 commits into from

Conversation

stevenroose
Copy link
Collaborator

@stevenroose stevenroose commented Sep 13, 2019

Includes #327.

Not sure if it's the right place to put the module, but I think it makes
more sense to have all validation stuff inside the same module and have
a validation::Error type for validation methods.

@tamasblummer
Copy link
Contributor

if you are fancy this could also have functions

  • to do locktime check, asking if a transaction is valid to be included into a block with given height or under assumption of an block time average.
  • to check if the transaction has no output less than DUST limit
  • pays at least x sats/vByte

@elichai
Copy link
Member

elichai commented Sep 13, 2019

I think you forgot to commit the validation.rs file. :)

@stevenroose
Copy link
Collaborator Author

Haha, of course I did! Fixed.

@stevenroose stevenroose force-pushed the mod-validation branch 2 times, most recently from 9a92599 to cd23159 Compare September 13, 2019 20:57
@tamasblummer
Copy link
Contributor

@stevenroose this does not compile, please fix or close

@stevenroose
Copy link
Collaborator Author

updated

@codecov-io
Copy link

codecov-io commented Sep 27, 2019

Codecov Report

Merging #330 into master will increase coverage by 0.39%.
The diff coverage is 78.63%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #330      +/-   ##
==========================================
+ Coverage   82.17%   82.56%   +0.39%     
==========================================
  Files          38       39       +1     
  Lines        7063     7510     +447     
==========================================
+ Hits         5804     6201     +397     
- Misses       1259     1309      +50
Impacted Files Coverage Δ
src/blockdata/script.rs 81.67% <ø> (+3.08%) ⬆️
src/lib.rs 100% <ø> (ø) ⬆️
src/blockdata/transaction.rs 94.12% <ø> (+0.64%) ⬆️
src/consensus/validation.rs 78.63% <78.63%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4b1d4ed...25fbea0. Read the comment docs.

tamasblummer
tamasblummer previously approved these changes Sep 28, 2019
@apoelstra
Copy link
Member

Needs rebase.

concept ACK.

@stevenroose one thing I like about this is that it removes #[cfg(...)] markers on enum variants. I think these are problematic because it makes it a breaking change to enable/disable features, for users who are matching on these enums. Because of how cargo resolves features, it means that a user might find their build breaks when they add an unrelated dep.

In #413 you add some new instances of feature-gated enum variants. I wonder if we should change that too?

@stevenroose
Copy link
Collaborator Author

Rebased and updated this PR.

apoelstra
apoelstra previously approved these changes Oct 26, 2020
Copy link
Member

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

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

ack 310f9926049cd379675c242154f7d37f3cda0fc4

@JeremyRubin
Copy link
Contributor

I think it might be a superior approach for compatibility to implement the functions in the validation module on the type rather than as standalone funcs.

e.g.

pub struct Foo;
 impl Foo {
     pub fn foo(){
         println!("foo");
 
     }
 }
 
 mod extend {
     impl super::Foo {
         pub fn bar() {
             println!("bar");
 
         }
     }
 }
 fn main() {
     Foo::bar();
     Foo::foo();
 }

@stevenroose
Copy link
Collaborator Author

Hmm, in what way do you mean "for compatibility"?

@JeremyRubin
Copy link
Contributor

the method names do not change, nor does how you call them. less impact on the crate's current users.

@stevenroose
Copy link
Collaborator Author

stevenroose commented Oct 31, 2020 via email

@JeremyRubin
Copy link
Contributor

not sure what you're suggesting -- it's fine that this is a breaking change w.r.t. a feature flag on the crate, I'm more pointing out that you can just move the impls to a split out feature module and not rename or remove any exisiting method.

I think it makes more sense for the verify method to keep track of
double-spending itself instead of requiring the closure to do that.
When internally keeping track of double-spending, the closure can just
be a simple inspector closure and doesn't need to mutate any state,
making it a lot simpler and potentially more efficient.

Also, OutPoint is Copy, so doesn't need to be referenced.
@stevenroose
Copy link
Collaborator Author

@JeremyRubin I added the methods you suggested. Now they're duplicated with the raw module functions though. I somehow feel that it makes sense to bundle validation in one module and just have it there as module functions. Perhaps I should mark the type methods as deprecated? Thoughts? @apoelstra @elichai @sgeisler ?

Not sure if it's the right place to put the module, but I think it makes
more sense to have all validation stuff inside the same module and have
a validation::Error type for validation methods.
@elichai
Copy link
Member

elichai commented Nov 4, 2020

Concept ACK for splitting,
I don't really like that now impl Transaction and others are scattered in multiple modules, I'd rather have a Trait Validation if we really want to have methods on the objects themselved

@JeremyRubin
Copy link
Contributor

The issue with trait Validation is there isn't a consistent API on the methods -- you could do trait TransactionValidation though?

@stevenroose I guess I was saying that I don't see a reason to introduce the non type methods at all? Is this a general direction we're going or is there a plan to make this a separate crate?

@tcharding
Copy link
Member

Hey @stevenroose I like the purpose of this PR, do you want me to redo it? Just offering because it will be way easier for me to do it from scratch knowing whats changed in the codebase since you originally did this than you trying to rebase.

@stevenroose
Copy link
Collaborator Author

Yeah sure, go ahead use whatever I put here.

Davidson-Souza pushed a commit to Davidson-Souza/rust-bitcoin that referenced this pull request Jul 12, 2023
eb453b8 Add global context API (Tobin Harding)
3ecb5e4 Refactor from_secret_key definition (Tobin Harding)
e2d47a2 Remove unnecessary import statement (Tobin Harding)
d79989b Remove erroneous duplicate feature (Tobin Harding)

Pull request description:

  Our API often involves a `Secp256k1` parameter, when users enable the `global-context` feature they must then pass `SECP256K1` into these functions. This is kind of clunky since the global is by definition available everywhere.

  Make the API more ergonomic for `global-context` builds by adding various API functions/methods that use the global context implicitly.

  The first 3 patches are clean up.

  Resolves: rust-bitcoin#330

ACKs for top commit:
  apoelstra:
    ACK eb453b8

Tree-SHA512: 21d89a6688c24a7920d48ea92d923889bec2bbe9dc5ed5e33639405be45a50f50022a28dc1f235b8bea850ac39013c7dd24b5aed086ed40f5b259dd44c06433d
@tcharding
Copy link
Member

Done in #1912

@tcharding tcharding closed this Aug 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API break This PR requires a version bump for the next release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants