Thanks to visit codestin.com
Credit goes to github.com

Skip to content

backport getrawtransaction#3847

Open
nformant1 wants to merge 12 commits intodogecoin:masterfrom
nformant1:changes
Open

backport getrawtransaction#3847
nformant1 wants to merge 12 commits intodogecoin:masterfrom
nformant1:changes

Conversation

@nformant1
Copy link
Contributor

added myblockhash argument to getrawtransaction (bitcoin backport)

nformant1 added 3 commits May 24, 2025 10:57
added syntax highlighting to code blocks
backport bitcoins getrawtransaction additional parameter "myblockhash" to query transactions without -txindex
@patricklodder patricklodder added rebase needed RPC RPC related changes and questions labels May 24, 2025
@patricklodder patricklodder moved this to 🚀 needs review in Review & merge board May 24, 2025
@patricklodder patricklodder requested a review from a team May 24, 2025 17:56
Copy link
Member

@patricklodder patricklodder left a comment

Choose a reason for hiding this comment

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

Concept ACK.

Code review inline, and additionally: please add test cases for the new functionality to qa/rpc-tests/rawtransactions.py

Also needs a rebase to remove 2 stray commits at some point.

@patricklodder patricklodder moved this from 🚀 needs review to 🔨needs rework in Review & merge board May 24, 2025
@nformant1
Copy link
Contributor Author

I did all changes that are clear to me already. What is the best practice - wait until everything is discussed and resolved and push the code again, or is an update from what I have so far also ok?

@patricklodder
Copy link
Member

is an update from what I have so far also ok?

This. Just push what commits you have when you think it solves things, even when partially. Fixed comments will be marked outdated and I'll resolve them (and if it's good I don't create a new one).

Then can simply do a good old squash at the end to clean up commits mess.

@nformant1
Copy link
Contributor Author

qa/rpc-tests/rawtransactions.py is still open, but will be fixed next.

@patricklodder
Copy link
Member

Much better now! Please don't forget to restore

result.pushKV("hex", strHex);

between line 269 and 270, I am quite sure that this is what is causing the CI to error out.

@nformant1
Copy link
Contributor Author

f4611c2 contains the test scripts. Sorry for this mess...

All test-scripts from 1 - 8 fail as well the step "No such transaction found" in test 11 fails. Maybe some can help me here again (:

@gruberlu
Copy link

gruberlu commented Jun 5, 2025

Hey there!

I think the part when actually retrieving the tx is missing:

// validation.cpp
bool GetTransaction(const uint256 &hash, CTransactionRef &txOut, const Consensus::Params& consensusParams, uint256 &hashBlock, bool fAllowSlow, CBlockIndex* blockIndex)
{
    CBlockIndex *pindexSlow = blockIndex;

    LOCK(cs_main);

    if (!blockIndex) {
        CTransactionRef ptx = mempool.get(hash);
        if (ptx) {
            txOut = ptx;
            return true;
        }
        if (fTxIndex) {
            CDiskTxPos postx;
            if (pblocktree->ReadTxIndex(hash, postx)) {
                CAutoFile file(OpenBlockFile(postx, true), SER_DISK, CLIENT_VERSION);
                if (file.IsNull())
                    return error("%s: OpenBlockFile failed", __func__);
                CBlockHeader header;
                try {
                    file >> header;
                    fseek(file.Get(), postx.nTxOffset, SEEK_CUR);
                    file >> txOut;
                } catch (const std::exception& e) {
                    return error("%s: Deserialize or I/O error - %s", __func__, e.what());
                }
                hashBlock = header.GetHash();
                if (txOut->GetHash() != hash)
                    return error("%s: txid mismatch", __func__);
                return true;
            }
        }
        if (fAllowSlow) { // use coin database to locate block that contains transaction, and scan it
            int nHeight = -1;
            {
                const CCoinsViewCache& view = *pcoinsTip;
                const CCoins* coins = view.AccessCoins(hash);
                if (coins)
                    nHeight = coins->nHeight;
            }
            if (nHeight > 0)
                pindexSlow = chainActive[nHeight];
        }
    }


    if (pindexSlow) {
        CBlock block;
        if (ReadBlockFromDisk(block, pindexSlow, consensusParams)) {
            for (const auto& tx : block.vtx) {
                if (tx->GetHash() == hash) {
                    txOut = tx;
                    hashBlock = pindexSlow->GetBlockHash();
                    return true;
                }
            }
        }
    }

    return false;
}
// validation.h
bool GetTransaction(const uint256 &hash, CTransactionRef &tx, const Consensus::Params& params, uint256 &hashBlock, bool fAllowSlow = false, CBlockIndex* blockIndex = nullptr);

@patricklodder patricklodder self-requested a review June 10, 2025 13:45
@nformant1
Copy link
Contributor Author

Hey @patricklodder is there any further to do on my side or do I only have to wait for your checks? (:

Comment on lines +145 to +146
"2. verbose (bool, optional, default=false) If false, return a string, otherwise return a json object\n"
"3. \"blockhash\" (string, optional) The block in which to look for the transaction\n"
Copy link
Member

Choose a reason for hiding this comment

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

Is it worth adding a test or two when verbose is false but blockhash is provided?

Comment on lines +211 to +214
if (hash == Params().GenesisBlock().hashMerkleRoot) {
// Special exception for the genesis block coinbase transaction
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "The genesis block coinbase is not considered an ordinary transaction and cannot be retrieved");
}
Copy link
Member

Choose a reason for hiding this comment

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

Another case where it might be worth adding a test.

Copy link
Member

Choose a reason for hiding this comment

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

Minor formatting nit: I read this wrong the first time. I recommend either indenting the result.pushKv(...) call or adding a blank line between these two lines.

@chromatic
Copy link
Member

Concept ACK from me and all tests pass.

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

Labels

rebase needed RPC RPC related changes and questions

Projects

Status: 🔨needs rework

Development

Successfully merging this pull request may close these issues.

4 participants

Comments