Skip to content

Create UtxoData and check coinbase maturity #440

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

Merged
merged 1 commit into from
Apr 10, 2025

Conversation

JoseSK999
Copy link
Contributor

What is the purpose of this pull request?

  • Bug fix
  • Documentation update
  • New feature
  • Test
  • Other: Refactor

Which crates are being modified?

  • floresta-chain
  • floresta-cli
  • floresta-common
  • floresta-compact-filters
  • floresta-electrum
  • floresta-watch-only
  • floresta-wire
  • floresta
  • florestad
  • Other: Benches

Description

I have added the same UtxoData struct from PR #300, but with an additional is_coinbase flag. We get the flag from the utreexo leaf header code, just like the utxo creation height. The utxo creation unix time is not computed nor used anywhere (covered at #300).

The Consensus::verify_transaction now checks the spent coinbase tx outputs maturity. ChainParams has a constant for the maturity period but it's always 100 regardless of the network.

Notes to the reviewers

Most of this diff is refactoring TxOut to UtxoData in functions. I'm generally not using a UtxoMap type alias in order to keep the map types explicit on a first look.

This PR should should make #300 more focused on the timelock checks and unix time computation, and less so on refactors.

I have added the same `UtxoData` struct from PR vinteumorg#300, but with an additional `is_coinbase` flag. We get the flag from the utreexo leaf header code, just like the utxo creation height. The utxo creation unix time is not computed nor used anywhere (covered at vinteumorg#300).

Most of this diff is refactoring `TxOut` to `UtxoData` in functions. I'm generally not using a `UtxoMap` type alias in order to keep the map types explicit on a first look.

The `Consensus::verify_transaction` now checks the spent coinbase tx outputs maturity. `ChainParams` has a constant for the maturity period but it's always 100 regardless of the network.
@jaoleal
Copy link
Contributor

jaoleal commented Apr 8, 2025

cACK cc022a0

I'm generally not using a UtxoMap type alias in order to keep the map types explicit on a first look.

The reason to create UtxoMap in #300 is just for better organization and code reading.

This PR should should make #300 more focused on the timelock checks and unix time computation, and less so on refactors.

I`m considerating a total refactor of #300 instead of dealing with conflicts.

@JoseSK999
Copy link
Contributor Author

The reason to create UtxoMap in #300 is just for better organization and code reading.

Yeah, in this case I would prefer the explicitness of HashMap<OutPoint, UtxoData> unless we have a complex signature (e.g. process_proof)

@jaoleal
Copy link
Contributor

jaoleal commented Apr 8, 2025

The reason to create UtxoMap in #300 is just for better organization and code reading.

Yeah, in this case I would prefer the explicitness of HashMap<OutPoint, UtxoData> unless we have a complex signature (e.g. process_proof)

Im totally neutral about it because i had to reimplement some funcs just because it was a type alias, so im not sure if its worth the change...

BTW, Tested locally and everything runs fine. have you done some blocks validation to certify this ?

@JoseSK999
Copy link
Contributor Author

The sync must work since the only consensus change is:

// A coinbase output created at height n can only be spent at height >= n + 100
if utxo.is_coinbase && (height < utxo.creation_height + 100) {
    return Err(tx_err!(txid, CoinbaseNotMatured))?;
}

@jaoleal
Copy link
Contributor

jaoleal commented Apr 9, 2025

The sync must work since the only consensus change is:

// A coinbase output created at height n can only be spent at height >= n + 100
if utxo.is_coinbase && (height < utxo.creation_height + 100) {
    return Err(tx_err!(txid, CoinbaseNotMatured))?;
}

Checked the code for this rule:

https://github.com/bitcoin/bitcoin/blob/874da961d015620ffcdac91af76b90aaee823926/src/consensus/tx_verify.cpp#L179

It looks the exactly same so:

ACK cc022a0

Copy link
Collaborator

@Davidson-Souza Davidson-Souza left a comment

Choose a reason for hiding this comment

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

I've successfully completed IBD on this branch. But a nice follow up would be some tests for the negative case (i.e. invalid spents)

ACK cc022a0

@Davidson-Souza Davidson-Souza merged commit a6c0ea3 into vinteumorg:master Apr 10, 2025
8 checks passed
@JoseSK999 JoseSK999 deleted the cb-maturity-check branch April 10, 2025 15:35
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.

3 participants