Skip to content

Conversation

@Ataraxia009
Copy link

@Ataraxia009 Ataraxia009 commented Oct 27, 2025

When debugging and trying to print the details of a CTxIn using the ToString, we get the scriptSig, but would also help to get the witness.

@DrahtBot
Copy link
Contributor

DrahtBot commented Oct 27, 2025

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Code Coverage & Benchmarks

For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/33711.

Reviews

See the guideline for information on the review process.

Type Reviewers
Stale ACK optout21

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #33771 (refactor: C++20 operators by purpleKarrot)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@optout21
Copy link
Contributor

optout21 commented Nov 1, 2025

Concept ACK 61cd0e53ca45684cd5ef9084829ecc6d59154595

I notice that CTransaction::ToString() prints the inputs and the input script witnesses additionally, with that change script witnesses will be included duplicated. The order there is first all inputs, then all witnesses. Please consider removing the duplication.
Options:

  • keep the duplication
  • remove duplication, change the order
  • remove the duplication and keep the order -- there should be a version of CTxIn::ToString() without witness?

https://github.com/bitcoin/bitcoin/blob/master/src/primitives/transaction.cpp#L126

    for (const auto& tx_in : vin)
        str += "    " + tx_in.ToString() + "\n";
    for (const auto& tx_in : vin)
        str += "    " + tx_in.scriptWitness.ToString() + "\n";

@Ataraxia009 Ataraxia009 force-pushed the core-txIn-toString-enhancement branch from 61cd0e5 to e8b262a Compare November 7, 2025 06:18
@Ataraxia009
Copy link
Author

I notice that CTransaction::ToString() prints the inputs and the input script witnesses additionally, with that change script witnesses will be included duplicated. The order there is first all inputs, then all witnesses. Please consider removing the duplication.

Hey, good call out. Updated to remove duplicate. Think this makes the most sense.

Copy link
Contributor

@frankomosh frankomosh left a comment

Choose a reason for hiding this comment

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

I think the goal for this is reasonable, but doesn't it remove witness data from CTransaction::ToString() and break existing debug output?

str += strprintf(", scriptSig=%s", HexStr(scriptSig).substr(0, 24));
str += strprintf(", scriptWitness=%s", scriptWitness.ToString());
Copy link
Contributor

Choose a reason for hiding this comment

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

I think there might be an inconsistency in formatting here. scriptWitness.ToString() is called directly, while scriptSig uses HexStr().substr(0, 24). Shouldn't there be some symmetry ?

Copy link
Author

Choose a reason for hiding this comment

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

I see your point, but the underlying structures are different for ScriptSig and ScriptWitness: simple byte vector for script sig ScriptSig and vector of byte vectors for the ScriptWitness. So these are more accurate representatives of what is happening under the hood imo. Its also standard to print script sig like this from what i can see.

@@ -123,8 +125,6 @@ std::string CTransaction::ToString() const
nLockTime);
for (const auto& tx_in : vin)
str += " " + tx_in.ToString() + "\n";
for (const auto& tx_in : vin)
Copy link
Contributor

Choose a reason for hiding this comment

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

Though I have not done a thorough test, I think that completely removing this might affect debug workflow. Before removing it, Ctransaction::ToString() is able to print all inputs, then a separate block with all witnesses, then all outputs. I don’t think this is possible anymore.

Copy link
Author

Choose a reason for hiding this comment

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

yes but its better to roll up responsibility to the object that holds it? Can you point out exactly where maybe? so we can see? if not, this seems like a better approach to me.

Copy link
Contributor

Choose a reason for hiding this comment

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

To be safe, I suggest keeping the output here as it was, as I have no idea what was the rationale for it: just so happened, or to reflect that segwit segregation.
A way to do it is to have a version of Tx tostring that omits the witness, and use that here, and print the witnesses separately as before.
I think this is less intrusive change and higher change of positive review.

Copy link
Contributor

Choose a reason for hiding this comment

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

yes but its better to roll up responsibility to the object that holds it? Can you point out exactly where maybe? so we can see? if not, this seems like a better approach to me.

I think rolling the witness into CTxIn::ToString() is fine only if you keep the old separate witness block in CTransaction::ToString() (or try adding a flag to suppress it). Right now you’ve deleted that block, so every existing log, test and user script would lose the witness section.

Copy link
Author

Choose a reason for hiding this comment

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

It wouldn't lose the witness section @frankomosh it would just be rolled up. It would still print, it would just print in the txIn instead. However i can breaking such a fundamental log would be a problem so I'm okay with making the change less intrusive

Copy link
Author

Choose a reason for hiding this comment

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

@frankomosh should be addressed

Copy link
Author

Choose a reason for hiding this comment

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

@optout21 for vision

Copy link
Contributor

Choose a reason for hiding this comment

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

The CTransaction::ToString() output looks the same now, my concern is addressed.

@Ataraxia009 Ataraxia009 force-pushed the core-txIn-toString-enhancement branch from e8b262a to 812495a Compare November 24, 2025 19:28
Copy link
Contributor

@optout21 optout21 left a comment

Choose a reason for hiding this comment

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

utACK 812495a426a3ea9ef15567983ff31e22d05e9f5d

Minor extension to the ToString() method of the CTxIn class. Well localized change, minimal risk of unintended impact. Thanks for the initiative.

@Ataraxia009 Ataraxia009 force-pushed the core-txIn-toString-enhancement branch from 812495a to bc02cc8 Compare December 4, 2025 04:53
@DrahtBot
Copy link
Contributor

DrahtBot commented Dec 8, 2025

🐙 This pull request conflicts with the target branch and needs rebase.

@DrahtBot
Copy link
Contributor

🚧 At least one of the CI tasks failed.
Task lint: https://github.com/bitcoin/bitcoin/actions/runs/19918111499/job/58081204709
LLM reason (✨ experimental): Lint check failed due to trailing whitespace in src/primitives/transaction.cpp:50, causing the CI to fail.

Hints

Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:

  • Possibly due to a silent merge conflict (the changes in this pull request being
    incompatible with the current code in the target branch). If so, make sure to rebase on the latest
    commit of the target branch.

  • A sanitizer issue, which can only be found by compiling with the sanitizer and running the
    affected test.

  • An intermittent issue.

Leave a comment here, if you need help tracking down a confusing failure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants