How to re-sync c-lightning with mainnet blockchain? - bitcoin

I am playing around with the lightning implementation from https://github.com/ElementsProject/lightning and after the following steps the cli-client cannot list funds which I deposited at the generated address from the internal wallet
I installed bitcoind-0.16 and fully synced the mainnet-blockchain
I installed c-lightning and synced with the local full node
I generated a new address with ./lightning-cli newaddr
I funded this address from my Electrum wallet (not from the local node wallet) and saw the incoming transaction with ./lightning-cli listfunds
Then I accidentally deleted the file .lightning/lightningd.sqlite3
After restart the lightningd recreated the file but now ./lightning-cli listfunds is showing empty results but the funds have to be there because the funding transaction is visible in the blockchain.
I investigated ./lightning-cli dev-listaddrs which shows all addresses of the internal wallet and there is my funding address. So I think I need to re-sync the lightningd with the bitcoin blockchain, but a ./lightning-cli dev-rescan-outputs had no success.
What can I do to be able to see and spend the funds again? Or, how can I get the seed/private key of the internal (lightning) wallet?

A perfect answer was given from a c-lightning member here: https://github.com/ElementsProject/lightning/issues/1170
In case the link dies:
Well, the short answer is do not delete the db, that will end up losing funds, just like deleting the wallet.dat would in bitcoind.
The long answer is, use newaddr to regenerate all addresses you had (it's ok to call it a few times too many). Then stop lightningd, open lightningd.sqlite3 and tell it to scan from an earlier block:
sqlite3 $HOME/.lightning/lightningd.sqlite3 "UPDATE vars SET val= 500000 WHERE name='last_processed_block';"
Then restart lightningd and it should start scanning the blocks from height 500'000 (which will take quite some time).
Notice that this only works as long as you don't have channels open, since in that case you're no longer the sole owner of the funds. So never delete the DB!

Related

I have deployed smart contract successfully, after copying the transaction hash to check info of the token created i found nothing on bscscan

I have changed the contract from the drop down menu whether I deploy wrong contract unfortunately its still not showing. I also increased the gas fees. I have tried severally by using different browser and I also used http and https all to no avail
This is one of the transaction hash of the token I created below:
0xbe8e45ca80fae1de52f60addeae7dbdf0ae75778a3e29f185aa628b7faa0bd7f
The transaction shows up correctly on the testnet BSCScan: https://testnet.bscscan.com/tx/0xbe8e45ca80fae1de52f60addeae7dbdf0ae75778a3e29f185aa628b7faa0bd7f
BSCScan distinguishes between the testnet and the mainnet. So a transaction that exists only on testnet, will not show on the mainnet explorer.

Adding a manually generated private key on bitcoin node

We are hosting a bitcoin node to handle deposits on our website. Now, we generate new addresses on the node via RPC call. The problem is that the client is afraid of losing the private keys in case of server failure for example.
So what I purposed is that we can have a master key and an increment counter to generate any number of private keys from that. With this, we just have to back up the master key and we can re-generate all the private keys again in case we lose data on the server.
The issue here is that the bitcoin node will only notify us about new transactions when the address is generated on the node itself and we cannot modify the way the node generates new addresses.
I have 2 questions:
Am I on the right path?
How can I add the manually generated private keys on the node so that the node will notify me when a new transaction is received on those keys?
Thank you.
bitcoind's wallet already does the "generate keys from a single seed" thing for you. So you could simply make multiple backups of the wallet (see the "backupwallet" RPC method).
However, bitcoins should really not be stored on a website, and if you are handling withdrawls, you really need a much more secure setup in general or you will be robbed.
If you are only taking payments/deposits and not doing withdrawls, it is still inadvisable to allow your website to access the private keys. Instead, maintain a wallet offline, and use the "importaddress" RPC method to maintain a watch-only copy of your "wallet" on the webserver. Be sure before you ship products, that you verify payments with a full node independent of the webserver as well.
Note that no matter where you store your wallet, you should make at least several backups initially, and don't forget to also backup any metadata you need to properly deliver your products/services and minimise your tax liabilities.

Can full nodes confirm bitcoin transactions, or only verify?

I have searched and searched and can't find the answer. If you are running a full node, can you confirm transactions. Or do you just verify/relay transactions? Or is it only miners that can confirm transactions? When I say confirm, I mean, when you spend some bitcoin, you need X confirmations (usually 6) for it to go through. Who does the confirmations? Can it be full nodes? Or is it only miners?
What I mean is, in the wallet, you see X confirmations. Who makes that number go up? (Say, for example, from 0 to 1). Is it miners, full nodes, or both. Realizing that miners run full nodes. But I mean, full nodes that are not miners. Can they add a confirmation? Or does it have to be a miner?
Transactions are confirmed by blocks being added to the blockchain. A transaction's first confirmation is when it is included in a block and that block is mined (added to the blockchain). Each subsequent block added to the blockchain on top of that transaction's block means another confirmation. So a transaction has a number of confirmations equal to its depth in the blockchain.
Confirmations happen because of blocks being added to the blockchain through the process of mining, so per your question, only miners can confirm transactions. Once a block is added, full nodes verify and relay that block, but only miners do the work of actually confirming the transaction.

PayPal API transaction final status

I am using PayPalAPIInterfaceClient (soap service) to get information about transaction (method GetTransactionDetails()) and need to be absolutely sure about transaction status (it means - money has been sent no matter in which direction).
When the transaction is really completed and when is still "on the road"?
For example: I assume, Processed will be followed by InProgress and finally changed to Completed or something like this. On the other hand, Denied or - I don't know - Voided will not change in future.
Can you help me please to decide, which status can be accepted as ultimate (like Completed, but may be even Completed must not mean final money transfer) and which ones are still in one of its sub-state?
I would expect simple "Money finally transferred" & "Money finally not transferred" result, but reality is different.
Shortly, to mirror transaction result into database and manage automatic transactions (from and to client) I need to know this.
I am using the PaymentStatusCodeType enumeration values and my service iterates transaction history to check if the money was transferred or not.
Completed means it's done. You may also want to look into Instant Payment Notification (IPN). It sends real-time updates when transactions hit your PayPal account so you can automate post-transaction tasks accordingly. This includes handling e-checks or other pending payments which won't complete for a few days, refunds, disputes, etc.

Canceling a Bitcoin transaction

I am writing a bitcoin app and looking to implement a 'cancel' feature. All over reddit are references that if under 3 confirmation have occurred, technically a payment can be stopped. Maybe only a minute or 2 available, but still.
I cannot find any reference in the bitcoin api docs to demonstrate how this would be done.
I know that one altcoin uses an intentional 60 min gap to confirm for this very reason.
Anyone know how this is done?
Is it possible to cancel a Bitcoin transaction ...
... which was not yet broadcasted?
Yes, obviously it is possible. I'd propose you choose this method in your Bitcoin app by showing the user a confirmation screen for some seconds with information about the transaction and some buttons saying cancel and confirm. #nahtnam proposed a 60 minute delay which is too much, considering you may lose internet access or want the transaction to appear in the blockchain as soon as possible.
... which was already broadcasted?
Maybe... To cancel such a transaction, you'd need to create a block yourself which moves the inputs of the original transaction to one of your own addresses. (Effectively invalidating the original transaction.) However, creating a block costs several thousand dollars as of now and finding a block is not guaranteed.
Another possibility would be to broadcast another transaction taking the same inputs as the original one and targeting the outputs at one of your own addresses/wallets. To motivate miners to include this transaction instead of the original one, you increase the transaction fee. However, some clients may not relay such double spent transaction to the miners and some miners may reject the double spent transaction and include the original one (the one they received first), instead. (c.f. Bitpay encountered zero double spent in the first 10000 transactions. and Cancelling an unconfirmed transaction by #theymos (bitcoin.stackexchange))
There are some tricks to hide your initial transaction from miners by creating a so-called "non-standard" transaction. Alternatively, the transaction could include a very low fee to make miners reject it for economic reasons. (c.f. Significant losses by double-spending unconfirmed transactions (bitcoin-dev mailing list) and Double-spending by #petertodd (Reddit)) However, this makes your transaction look suspicious to the receiver if they look closer at it and they will most likely ask you to wait until it has one or more confirmations.
Finally, it is also possible if you set a flag on the original transaction to indicate replaceability. You can then replace the original transaction with another one by including the same (one or more) inputs in the replacement transaction. Also, you must pay a higher fee. However, not all miners honour this flag and some might still include your initial transaction. (c.f. Reference to BIP 125: Opt-in Full Replace-by-Fee Signaling)
... which is included in one or more blocks?
No, very unlikely to impossible. You'd need to control a substantial amount of hashing power to create a fork by rebuilding the blockchain starting at the block before the original transaction happened and ending at the block with height = (current public blockchain height) + 1. Therefore, "the more confirmations you have, the more difficult, expensive, and unreliable an attack like this is."
Source: #DannyHamilton (Bitcointalk)
The bitcoin paper by Satoshi Nakamoto explains that this is always possible when you control more than 50% of the hashing power, and possible with a probability less than 1, but greater than 0, if you control less than 50% hashing power. See Bitcoin: A Peer-to-Peer Electronic Cash System.
Though, if you control a substantial amount of hashing power, you are likely incentivised to not undermine the trust in bitcoin by undoing transactions and indirectly hurting your revenue stream from mining.
No. It is impossible to stop a bitcoin transaction. Thats what makes bitcoin so different. There is no way to reverse a transaction except for getting the receiver to send it back to you.
On another note, you could still have a cancel feature. You could set a delay of 60 minutes before you send a transaction and in that gap, someone can cancel but as I mentioned before there is no way to stop a transaction that has already reached the blockchain.
Work out the strategy before making a bitcoin payment. Check that both bitcoin addresses for payer and recipient are correct (use the copy and paste facility). Check that details of the product/service and $ amount are correct. Check that you have the correct private key details. Expect to wait at least 24 hours for confirmation. This allows time for the miners to validate the transaction. Then check your bitcoin account to ensure that the transaction is completed correctly by inserting your private key details into Google search, or check your bitcoin software for the transaction details.
It is complicated and expensive to cancel a transaction. So before you make payment, check, check and check again before sending.