Author

Topic: Confirmations in the source code (Read 220 times)

legendary
Activity: 1946
Merit: 1137
March 04, 2019, 01:33:57 AM
#13
I agree that the fact that this part of the transaction process is located in the qt/ directory is somehow confusing, since as you mentionned, we can compile without the wallet. This means that a node running without the wallet would not have the code to change the transaction status.
it is not confusing, if you read what everyone else was trying to tell you then you can realize that there is no such thing as number of confirmation in source code. your wallet can choose to make it easier for the user and show them some kind of easy graphical signal that their transaction is deeper than a certain threshold. so you hardcode some values like that.
the fact is, 6 is not even a fixed amount. it depends on network status. for example if we have a fork going on and there is a risk of split (like August 2017 with all the UASF, MASF, BCASH, SegWit,... going on) this number should go up.

Quote
As for a mature coin, of course 6+ confirmation is as you demonstrated a bare minimum to insure the security of the blockchain. But when you are playing with the core, it is a pita to have 6 node running   Tongue
it has nothing to do with "maturity" of a coin. it is about the PoW algorithm and the difficulty which would translate into how many blocks are being created in a certain time frame, how much is the risk of orphans, and how hard it is to double spend an already confirmed transaction with X number of confirmation.
with bitcoin's setting it is 6, with litecoin setting it is higher, with others can be different.
full member
Activity: 615
Merit: 154
CEO of Metaisland.gg and W.O.K Corp
March 04, 2019, 01:19:01 AM
#12
I agree that the fact that this part of the transaction process is located in the qt/ directory is somehow confusing, since as you mentionned, we can compile without the wallet. This means that a node running without the wallet would not have the code to change the transaction status.

Two more interesting bit of code are located in /primitives/ and are worth reading and understanding. They are small but essential.

/primitives/block.cpp is what creates the block, block.h has the block structure header, which is one of the most important part of the blockchain, less than 200 lines of code, but very interesting.
/primitives/transactions.cpp is even more critical, it is where the transactions are serialized and broacasted to the network.

I would point out that there is almost no comments in these source and that's is lacking to to their abstract nature.

The transactions, and transaction NumConfirmations = 6; is located in src/qt/transaction.cpp for a long time, Bitcoin 14.0 has it, and even Dash version 10 (first version have it in the same place). I guess it is there forever.

When you are doing an altcoin or playing with the Bitcoin source, it is essential to change this value to something like 1 or 2, otherwise the transactions never change status.

As for a mature coin, of course 6+ confirmation is as you demonstrated a bare minimum to insure the security of the blockchain. But when you are playing with the core, it is a pita to have 6 node running   Tongue



The number of confirmation is coded in /src/qt/transactionrecord.h
I am completely unaware of this, anyway thanks for pointing it out. I am confused right now!

Is qt code related to the bitcoin network? What is the use of coding number of confirmations in the wallet code? AFAIK, we can create our own bitcoin client which is not at all related to qt wallet! I believe this code is like a safe limit for accepting transactions and has nothing to do with confirmations.

We also need to note that, satoshi in his whitepaper has clearly said that these 6 confirmations are enough to prevent the double spending, that's the reason why this isn't present in the main code and wouldn't make sense if it is present so. Let me quote the lines from his paper

Quote from: satoshi
P < 0.001
q=0.10 z=5
q=0.15 z=8
q=0.20 z=11
q=0.25 z=15
q=0.30 z=24
q=0.35 z=41
q=0.40 z=89
q=0.45 z=340

Here

p is the chance of an attacker leading the longest chain and trying to double spend.
q is the hashing power that a miner controls
z is the number of blocks required by miner to overtake the chain and double spend the tx.

When a miner for instance controls 10% of total hashing power, he needs to overtake 5 blocks for him to reverse. Even though he passes then the probability is just 0.1%

So for safe terms, the 6 confirmations should be coded in the qt client. It has nothing to do with bitcoin network as far as I know.
legendary
Activity: 1584
Merit: 1280
Heisenberg Design Services
March 04, 2019, 12:21:07 AM
#11
The number of confirmation is coded in /src/qt/transactionrecord.h
I am completely unaware of this, anyway thanks for pointing it out. I am confused right now!

Is qt code related to the bitcoin network? What is the use of coding number of confirmations in the wallet code? AFAIK, we can create our own bitcoin client which is not at all related to qt wallet! I believe this code is like a safe limit for accepting transactions and has nothing to do with confirmations.

We also need to note that, satoshi in his whitepaper has clearly said that these 6 confirmations are enough to prevent the double spending, that's the reason why this isn't present in the main code and wouldn't make sense if it is present so. Let me quote the lines from his paper

Quote from: satoshi
P < 0.001
q=0.10 z=5
q=0.15 z=8
q=0.20 z=11
q=0.25 z=15
q=0.30 z=24
q=0.35 z=41
q=0.40 z=89
q=0.45 z=340

Here

p is the chance of an attacker leading the longest chain and trying to double spend.
q is the hashing power that a miner controls
z is the number of blocks required by miner to overtake the chain and double spend the tx.

When a miner for instance controls 10% of total hashing power, he needs to overtake 5 blocks for him to reverse. Even though he passes then the probability is just 0.1%

So for safe terms, the 6 confirmations should be coded in the qt client. It has nothing to do with bitcoin network as far as I know.
full member
Activity: 615
Merit: 154
CEO of Metaisland.gg and W.O.K Corp
March 03, 2019, 01:23:08 AM
#10
I am giving the answer of my own question, if someone with programing knowledge get stuck as I was (which is a mendatory step toward doing an altcoin) here are the answers.

The number of confirmation is coded in /src/qt/transactionrecord.h

Code:
   /** Number of confirmation recommended for accepting a transaction */
    static const int RecommendedNumConfirmations = 6;

Where the confirmation process is taking place is in /src/qt/transactionrecord.cpp

Code:
void TransactionRecord::updateStatus(const interfaces::WalletTxStatus& wtx, int numBlocks, int64_t adjustedTime)

It is quite surprising to find this piece of code inside the qt directory since it is not related to qt at all and should be in the main directory.
copper member
Activity: 140
Merit: 0
WWW.BLOCKCHAIN021.COM
March 01, 2019, 12:28:13 AM
#9
This question is for the developers. I know that you need 1 confirmation for small amount and up to six for larger amount, but where in the source code this is programmed? I mean where in the source code the pending transactions are moved from pending to available (condirmation = confirmation +1)
In my case, I have the transaction stuck in my altcoin wallet, but the transactions never get confirmed, they are staying in pending stage. I want to know where is the code and understand how the confirmation process is done in programming.

There must be some kind of validation (but I do not find that in validation.cpp or in mining.cpp). The problem I have is that the transactions are not confirmed regardless of what fees I apply, and there is no warning or error messages, so I have no choice than studying how the confirmation is programmed to find what is incompatible with my modifications.


Thanks

 Huh

I think the program or the exact code is not really needed, I remember when I've visited a website before that will boost your transaction in the blockchain wherein you need to copy the transaction ID and they are the one who will going to act about it in the market in order to speed up your transaction.
full member
Activity: 615
Merit: 154
CEO of Metaisland.gg and W.O.K Corp
February 28, 2019, 11:33:17 PM
#8
I need the source code because I want to modify it. I am not asking how it works, I know that, I am asking where in the Bitcoin core source code it is programmed.
The answer I am expecting is a .cpp file and a line where to search for.

Thanks for your help

You don't need the source code to know how confirmation process is being done in the blockchain all you need to do is to read about it online i guess that's why you have the internet.

Anyways, your transaction has to be included in a block by a miner, including your transaction in a block is called confirmation, the first block it is included gives you one confirmation and so on. This inclusion is actually based on the fee you used in carrying out that transaction, lower fee will take slower process, and higher fee will take faster process. This is just the simple explanation.
hero member
Activity: 1470
Merit: 655
February 28, 2019, 01:21:02 AM
#7
since this topic is currently in altcoin board (moved?) i am going to give you an altcoin oriented answer since everyone is focusing on bitcoin so far.

first of all your question has little to do with source code.
secondly the number of confirmation is not something you  put in source code, the only relationship is when difficulty comes in and determines when blocks are going to be mined and how the whole algorithm works.
so for example with PoW coins based on bitcoin the number is determined based on how easy it is to perform a 51% attack and reverse the already confirmed transactions by orphanning the current blocks. for bitcoin it is near impossible so 1 confirmation is safe. with altcoins with lower hashrate it is much easier which is why higher number is recommended. additionally with altcoins with faster blocks, orphans happen more naturally so again a higher number is advised.

however, other algorithms are very different. so you have to study them on a case by case basis. for example in DAG coins (i believe) 1 confirmation is final as long as there are enough witness nodes and they are decentralized.
hero member
Activity: 2730
Merit: 585
Leading Crypto Sports Betting & Casino Platform
February 28, 2019, 12:53:22 AM
#6
You don't need the source code to know how confirmation process is being done in the blockchain all you need to do is to read about it online i guess that's why you have the internet.

Anyways, your transaction has to be included in a block by a miner, including your transaction in a block is called confirmation, the first block it is included gives you one confirmation and so on. This inclusion is actually based on the fee you used in carrying out that transaction, lower fee will take slower process, and higher fee will take faster process. This is just the simple explanation.
full member
Activity: 615
Merit: 154
CEO of Metaisland.gg and W.O.K Corp
February 27, 2019, 05:21:53 PM
#5
That's what I was looking for! Thanks for the detailed answer, it is a good start for me to investigate  Grin Grin Grin
Sorry if the question was a bit confused, I was really looking for the location in the Bitcoin source code where the transactions are confirmed (where confirmations++ is done). So that I can study why my transactions are not passing through.
I have made a lot of modifications in the source by now, so I don't think it is a transaction fee issue, if it was, I would have a warning in the logs.


Your question is pretty vague to be answered and doesn't seem to make sense actually. For the qt wallet to show the balances, you need to configure minconf option in the configuration file since those are the options which makes the wallet to show the balances. If you set the minconf=1 then the wallet will show the transaction which has got 1 confirmation from the network in the balances. If you set it to 0, you will see transactions with 0 confirmations. Unconfirmed transactions cannot be spent by qt wallet. If your transaction is a coinbase tx, then you need 100 confirmations from the network and here is the relevant code for that present in consensus.h

Code:
/** Coinbase transaction outputs can only be spent after this number of new blocks (network rule) */
static const int COINBASE_MATURITY = 100;

I have read somewhere an attacker can build a raw transaction for unconfirmed transactions, but if you do so and other nodes find that out, your node's IP address will get banned from using the network (in simple terms it would be blacklisted). I assume This code is present in the validations.cpp and can be seen here.

Code:
for (CTxMemPool::txiter ancestorIt : setAncestors)
        {
            const uint256 &hashAncestor = ancestorIt->GetTx().GetHash();
            if (setConflicts.count(hashAncestor))
            {
                return state.DoS(10, false,

                     strprintf("%s spends conflicting transaction %s",
                                           hash.ToString(),
                                           hashAncestor.ToString()));
            }
        }

Here the double spend transaction will be included in setConflict and the node which relayed them will be banned.

In my case, I have the transaction stuck in my altcoin wallet, but the transactions never get confirmed, they are staying in pending stage.

If you didn't specify enough higher fees, the transaction should be staying in the mempool which would be picked up by miner later to add to the block.

Also, move this thread to altcoin section to get better answer here https://bitcointalk.org/index.php?board=67.0
Pretty much bad idea. Do you think this would be answered in the Altcoin board? The spammers present there doesn't even know what a confirmation is! A single question present there about pre-mining is solely being answered by me for past 2 days and there isn't even one guy jumped in to learn what the OP is saying. Also I believe the question is based on a bitcoin fork, so asking questions here is probably right in my opinion.
full member
Activity: 615
Merit: 154
CEO of Metaisland.gg and W.O.K Corp
February 27, 2019, 05:18:28 PM
#4
I need to know where these tasks are handled (sorry I am French). I know how to build a transaction, but I need to find where this is done in C++ in the Bitcoin source code. Thanks for your answer though.

Why you need the source code?
I think you just need here is the transaction ID and use that transaction ID to check your transaction if it's under being process or to check if the transaction is confirmed.
You don't need to program or become a coder to solve or confirm the transaction it depends on the network and it can be confirm if the miners found the blocks that includes your transaction.

Can you put your transaction ID here and let me know what altcoin you are talking about?

Also, move this thread to altcoin section to get better answer here https://bitcointalk.org/index.php?board=67.0
legendary
Activity: 1584
Merit: 1280
Heisenberg Design Services
February 27, 2019, 01:25:13 PM
#3
Your question is pretty vague to be answered and doesn't seem to make sense actually. For the qt wallet to show the balances, you need to configure minconf option in the configuration file since those are the options which makes the wallet to show the balances. If you set the minconf=1 then the wallet will show the transaction which has got 1 confirmation from the network in the balances. If you set it to 0, you will see transactions with 0 confirmations. Unconfirmed transactions cannot be spent by qt wallet. If your transaction is a coinbase tx, then you need 100 confirmations from the network and here is the relevant code for that present in consensus.h

Code:
/** Coinbase transaction outputs can only be spent after this number of new blocks (network rule) */
static const int COINBASE_MATURITY = 100;

I have read somewhere an attacker can build a raw transaction for unconfirmed transactions, but if you do so and other nodes find that out, your node's IP address will get banned from using the network (in simple terms it would be blacklisted). I assume This code is present in the validations.cpp and can be seen here.

Code:
for (CTxMemPool::txiter ancestorIt : setAncestors)
        {
            const uint256 &hashAncestor = ancestorIt->GetTx().GetHash();
            if (setConflicts.count(hashAncestor))
            {
                return state.DoS(10, false,

                     strprintf("%s spends conflicting transaction %s",
                                           hash.ToString(),
                                           hashAncestor.ToString()));
            }
        }

Here the double spend transaction will be included in setConflict and the node which relayed them will be banned.

In my case, I have the transaction stuck in my altcoin wallet, but the transactions never get confirmed, they are staying in pending stage.

If you didn't specify enough higher fees, the transaction should be staying in the mempool which would be picked up by miner later to add to the block.

Also, move this thread to altcoin section to get better answer here https://bitcointalk.org/index.php?board=67.0
Pretty much bad idea. Do you think this would be answered in the Altcoin board? The spammers present there doesn't even know what a confirmation is! A single question present there about pre-mining is solely being answered by me for past 2 days and there isn't even one guy jumped in to learn what the OP is saying. Also I believe the question is based on a bitcoin fork, so asking questions here is probably right in my opinion.
legendary
Activity: 2058
Merit: 1030
I'm looking for free spin.
February 27, 2019, 12:00:53 PM
#2
Why you need the source code?
I think you just need here is the transaction ID and use that transaction ID to check your transaction if it's under being process or to check if the transaction is confirmed.
You don't need to program or become a coder to solve or confirm the transaction it depends on the network and it can be confirm if the miners found the blocks that includes your transaction.

Can you put your transaction ID here and let me know what altcoin you are talking about?

Also, move this thread to altcoin section to get better answer here https://bitcointalk.org/index.php?board=67.0
full member
Activity: 615
Merit: 154
CEO of Metaisland.gg and W.O.K Corp
February 27, 2019, 11:04:24 AM
#1
This question is for the developers. I know that you need 1 confirmation for small amount and up to six for larger amount, but where in the source code this is programmed? I mean where in the source code the pending transactions are moved from pending to available (condirmation = confirmation +1)
In my case, I have the transaction stuck in my altcoin wallet, but the transactions never get confirmed, they are staying in pending stage. I want to know where is the code and understand how the confirmation process is done in programming.

There must be some kind of validation (but I do not find that in validation.cpp or in mining.cpp). The problem I have is that the transactions are not confirmed regardless of what fees I apply, and there is no warning or error messages, so I have no choice than studying how the confirmation is programmed to find what is incompatible with my modifications.


Thanks

 Huh
Jump to: