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

Remove TxIn::BASE_WEIGHT and fix docs on effective_value() #2345

Closed

Conversation

tcharding
Copy link
Member

BASE_WEIGHT is misnamed and the docs are wrong. Please see commit logs for full explanations.

The term "base weight" is already defined in the codebase, in the
`TxIn`, by the `base_weight` function. Recently we added a const
`BASE_WEIGHT` that contradicts this meaning because it does not include
the script sig.

Remove `BASE_WEIGHT` and just use the already available consts instead.
Copy link
Collaborator

@Kixunil Kixunil left a comment

Choose a reason for hiding this comment

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

ACK the first commit.

///
/// Note: the effective value of a [`Transaction`] may increase less than the effective value of
/// Note: the effective value of a [`Transaction`] may increase more than the effective value of
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nope, this was correct. (It originally wasn't until I pointed it out in my review BTW; it's subtle.)

The logic is inverted - the more bytes transaction has the more you spend on fees thus the value is lower.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, that is subtle, I'll improve the docs - thanks.

Copy link
Member Author

Choose a reason for hiding this comment

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

The docs refer to TxOut but we are calculating the effective value of in input, I didn't notice that before.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Well, each input is an output of previous transaction (except for coinbase) so it's often hard to communicate when we kinda mean both.

@@ -1170,10 +1170,10 @@ impl From<&Transaction> for Wtxid {

/// Computes the value of an output accounting for the cost of spending it.
///
/// The effective value is the value of an output value minus the amount to spend it. That is, the
/// effective_value can be calculated as: value - (fee_rate * weight).
/// The effective value is the value of an output minus the cost to spend it. That is, the
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't it say "cost of spending it"?

Copy link
Member Author

Choose a reason for hiding this comment

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

Both are grammatically correct. "of" goes with "spending" and "to" goes with "spend" - English, I know.

Copy link
Collaborator

Choose a reason for hiding this comment

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

"spending" somehow feels more natural here but I don't know why. But I don't really care unless there's an actual difference in meaning.

The change to effective value of transaction when adding an input is

While we are at it improve the first paragraph, stylistic only.
@tcharding
Copy link
Member Author

Changes in force push:

  • Patch 2 is different, made another attempt at better describing the input addition's effect on effective value of the transaction.

@yancyribbens
Copy link
Contributor

I could go either way on the first commit since effective_value works the same really. We also could have discussed this on the just merged PR to add effective_value.

let weight = satisfaction_weight.checked_add(TxIn::BASE_WEIGHT)?;
let previous_output_weight = Weight::from_vb_unwrap(OutPoint::SIZE as u64);
let sequence_weight = Weight::from_vb_unwrap(Sequence::SIZE as u64);
let weight = satisfaction_weight.checked_add(previous_output_weight)?.checked_add(sequence_weight)?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just realized, the original was more efficient because it had one-less overflow check. Maybe the compiler can remove it but I wouldn't bet on it here.

I suggest you add the constants together without check.

/// Note: the effective value of a [`Transaction`] may increase less than the effective value of
/// a [`TxOut`] when adding another [`TxOut`] to the transaction. This happens when the new
/// [`TxOut`] added causes the output length `VarInt` to increase its encoding length.
/// Note: adding an input to a [`Transaction`] the effective value of the transaction may increase
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't this say "when adding" ?

@Kixunil Kixunil dismissed their stale review January 16, 2024 21:45

Mistake was fIxed

@tcharding
Copy link
Member Author

Closing, I'm going to PR to revert #2230.

@tcharding tcharding closed this Jan 16, 2024
@tcharding
Copy link
Member Author

tcharding commented Jan 16, 2024

I'm not investing any more time into this. Let it be on record that IMO #2230 is not of a standard that can be released in the 1.0 release and that BASE_ is objectively the wrong identifier - as it was when I originally came back and removed all the other usages of it in the past. I did not follow the original PR because I viewed it as a bad use of my time.

@tcharding tcharding mentioned this pull request Jan 16, 2024
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.

None yet

3 participants