Bitcoin Forum
April 23, 2024, 04:29:23 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: « 1 2 [3]  All
  Print  
Author Topic: Easiest way to accept BTC and test  (Read 3471 times)
jlp (OP)
Sr. Member
****
Offline Offline

Activity: 266
Merit: 264


View Profile
January 18, 2014, 05:55:24 PM
 #41

We solve the wallet backup problem by keeping a copy of the private keys in the database.  For now, we're using the account system with thousands of accounts and tens-of-thousands of transactions without issue.  We have a secondary ledger than uses walletnotify and blocknotify to stay in sync.  We still use the bitcoin account system as the place of record, but our side-by-side tests have been perfect so far.  We could move off of the built-in account system if we needed to.  But you asked the easiest way to do some testing - not the most robust  Smiley
FWIW, this is also our cold-storage strategy.  When a user logs in, we push funds from the holding account into their account so they can play.  When they logout, we move it back to the holding account.  Then, we only keep a percentage of the total funds in teh holding account to support the numebr of people on the site at any given time.  This means if we got a rush of users, we would need to turn some away.  If only that would happen  Smiley

You're right that I should worry only about the minimum viable product and the easiest way to process bitcoins.  Just out of curiosity though, what do you plan to do when you get thousands of customers?

When you get a rush of users, then I assume that this becomes an issue only if they all want to withdraw bitcoins.  I assume that if your holding account runs out of bitcoins, then you can tell your users to wait as you manually move some bitcoins from your cold (which I assume is the same as offline) storage?

That sounds about right.  Note that you can do all of that without writing any software.  *notify can just be echos to a text file.  Also, bitcoind is a commandline version of the api, so you can do bitcoind getinfo, or bitcoind listtransactions, etc. to test out the api.

That's good to know.

We user sendFrom so they funds are removed from the users account, rather than the wallet.

According to tgerring's posting at https://bitcointalk.org/index.php?topic=300632.0:
Quote
Use Gavin's contrib/spendfrom script, never the `sendfrom` command

I don't know why he wrote the above.  I assume that you haven't had any problems with sendfrom.

Pretty close.  We create a new account for the user, then use walletnotify to watch for deposits.  When a deposit comes in, it's "unverified".
We then use blocknotify to watch for new blocks.  When a block comes in, we check the balance of the users account with 0 confirmations, then again with 4 confirmations.  The delta is their "unconfirmed" balance.
We don't do the sweep currently on the live site, but that's how we handle cold storage.

I don't understand what you mean by:  "We don't do the sweep currently on the live site".  Can you explain or elaborate?

It's not obvious. 
You can call getbalance and pass in the number of confirmations you want.  So if a user has 10 confirmations on their first 1btc deposit, and 2 confirmations on their second 5btc deposit:
getbalance 0 confirmations = 6btc
getbalance 4 confirmations = 1btc
From that, we can calculate that they have a balance of 1btc, and an additional 5btc unconfirmed.

So then blocknotify is only used to say, "A new block was received, and users' confirmations may have changed." 
We just use it to trigger a re-check of the users that have unconfirmed funds.  If the confirmed and unconfirmed balances are the same, we can stop checking their account with each new block.

Let me reiterate what you wrote above to fully understand what you are doing.  You keep track of users (in your database) who have unconfirmed funds.  When a blocknotify comes in, you call getbalance for each and every one of your users who have unconfirmed funds, to find out if these users still have or no longer have unconfirmed funds.  For users who no longer have unconfirmed funds, you write into your application database to indicate this, so that your application can tell your user that he has more bitcoins to play with.  Do I have this right?

Don't the blocknotify come in quite often, especially if you have thousands of users?  I'm assuming that blocknotify will run every time there is a confirmation on each and every transaction for every one of your users.  There could eventually be thousands of confirmations on a transaction.  Here's a possible number of blocknotifies:
1,000 confirmations X 5 deposits X 1,000 users = 5,000,000 blocknotifies.  For each of these blocknotifies, you are checking all of your users with unconfirmed funds.  This means you can be running getbalance 2,500,000,000 times (5m X 500) if you have 500 users with unconfirmed funds.  This seems like a lot of processing.  Do I have this wrong?

Only run on testnet.  There's no need to run on mainNet until you're getting close to launch. 
I'm happy to answer questions.  Just know that you're only getting one team's opinion.  There are a million ways to do things  Smiley

When we launch, do we need to run SSL on mainNet (assuming mainNet refers to regular bitcoins)?  Why is SSL needed?  What data needs to be encrypted?

Virtual Keyboard and Mouse.  A well known bitcoin casino had their data center's maintenance site hacked.  Someone put in an order to have a VKM installed.  The machine rebooted and the attackers attempted to use the vkm to get console access.  Thankfully, the casino used full-disk encryption, so reboots required a manual password step. 
Attackers in this space are really, really clever.

It's amazing how much less productive and wealthy our economies are due to all of the extra work and money we have to spend to protect ourselves from hackers, criminals, etc.  Also, the adoption of bitcoin would be much more widespread if it wasn't for these hackers and criminals.

1713889763
Hero Member
*
Offline Offline

Posts: 1713889763

View Profile Personal Message (Offline)

Ignore
1713889763
Reply with quote  #2

1713889763
Report to moderator
"Bitcoin: mining our own business since 2009" -- Pieter Wuille
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1713889763
Hero Member
*
Offline Offline

Posts: 1713889763

View Profile Personal Message (Offline)

Ignore
1713889763
Reply with quote  #2

1713889763
Report to moderator
1713889763
Hero Member
*
Offline Offline

Posts: 1713889763

View Profile Personal Message (Offline)

Ignore
1713889763
Reply with quote  #2

1713889763
Report to moderator
1713889763
Hero Member
*
Offline Offline

Posts: 1713889763

View Profile Personal Message (Offline)

Ignore
1713889763
Reply with quote  #2

1713889763
Report to moderator
moocoin
Member
**
Offline Offline

Activity: 112
Merit: 10

Do you moo?


View Profile WWW
January 23, 2014, 11:34:35 PM
 #42

When you get a rush of users, then I assume that this becomes an issue only if they all want to withdraw bitcoins.  I assume that if your holding account runs out of bitcoins, then you can tell your users to wait as you manually move some bitcoins from your cold (which I assume is the same as offline) storage?


Exactly.  We'll only hold enough in the hot wallet to cover expected withdrawls.  If we get a rush of withdrawals, users will get an error, and we'll be notified.  It's not the best customer experience but it should rarely happen, and it's better than losing a hot wallet.


I don't know why he wrote the above.  I assume that you haven't had any problems with sendfrom.

We've tested millions of sendFrom transactions and no problems at all.  Our scaling plan includes not using it, though.  Instead, we'll maintain the local ledger.


I don't understand what you mean by:  "We don't do the sweep currently on the live site".  Can you explain or elaborate?

Eventually, we'll sweep funds from the account the user deposits to, directly to the holding account and maintain their balance in the database.  Right now, we don't sweep those funds into the holding account because we're using the built-in account system with no problems.  Thousands of accounts and tens of thousands of transactions between accounts with no perceptible lag in our profiler.
We've always planned to move away from the account system because we've heard it isn't scalable.  We have most of that code written and tested, but have yet to see any scalability problems that would cause us to move away from teh account system.


Let me reiterate what you wrote above to fully understand what you are doing.  You keep track of users (in your database) who have unconfirmed funds.  When a blocknotify comes in, you call getbalance for each and every one of your users who have unconfirmed funds, to find out if these users still have or no longer have unconfirmed funds.  For users who no longer have unconfirmed funds, you write into your application database to indicate this, so that your application can tell your user that he has more bitcoins to play with.  Do I have this right?

Don't the blocknotify come in quite often, especially if you have thousands of users?  I'm assuming that blocknotify will run every time there is a confirmation on each and every transaction for every one of your users.  There could eventually be thousands of confirmations on a transaction.  Here's a possible number of blocknotifies:
1,000 confirmations X 5 deposits X 1,000 users = 5,000,000 blocknotifies.  For each of these blocknotifies, you are checking all of your users with unconfirmed funds.  This means you can be running getbalance 2,500,000,000 times (5m X 500) if you have 500 users with unconfirmed funds.  This seems like a lot of processing.  Do I have this wrong?


blocknotify happens each time a block is found on the network.  That's the only time a confirmation changes on a deposit.  A confirmation is defined as a new block found that includes the transaction.  This happens on average every 10 minutes.  So your server gets a block notify every ten minutes, and checks only the accounts that have unconfirmed funds from a recent deposit.  Once a user's account has 100% of the balance confirmed by 4 transactions, we don't have to check them again on the next blocknotify.


When we launch, do we need to run SSL on mainNet (assuming mainNet refers to regular bitcoins)?  Why is SSL needed?  What data needs to be encrypted?


Yea - that's SSL between the rpc client and the bitcoind rpc server.  If it's on the same machine, you may be able to forego ssl.  We have it enabled.



jlp (OP)
Sr. Member
****
Offline Offline

Activity: 266
Merit: 264


View Profile
January 31, 2014, 05:31:41 AM
 #43

When you get a rush of users, then I assume that this becomes an issue only if they all want to withdraw bitcoins.  I assume that if your holding account runs out of bitcoins, then you can tell your users to wait as you manually move some bitcoins from your cold (which I assume is the same as offline) storage?


Exactly.  We'll only hold enough in the hot wallet to cover expected withdrawls.  If we get a rush of withdrawals, users will get an error, and we'll be notified.  It's not the best customer experience but it should rarely happen, and it's better than losing a hot wallet.


I don't understand what you mean by:  "We don't do the sweep currently on the live site".  Can you explain or elaborate?

Eventually, we'll sweep funds from the account the user deposits to, directly to the holding account and maintain their balance in the database.  Right now, we don't sweep those funds into the holding account because we're using the built-in account system with no problems.

If you're going to hold just enough in the hot wallet to cover expected withdrawals, doesn't this imply that you are sweeping bitcoins from user accounts to your holding account and moving the bitcoins out of the holding account to your offline wallet?  If so, then I'm confused when you write that you "don't sweep those funds into the holding account..."  Can you elaborate?

blocknotify happens each time a block is found on the network.  That's the only time a confirmation changes on a deposit.  A confirmation is defined as a new block found that includes the transaction.  This happens on average every 10 minutes.  So your server gets a block notify every ten minutes, and checks only the accounts that have unconfirmed funds from a recent deposit.  Once a user's account has 100% of the balance confirmed by 4 transactions, we don't have to check them again on the next blocknotify.

I've been playing around with jsonRPCClient.php (from https://en.bitcoin.it/wiki/API_reference_(JSON-RPC)) and getblock to get the information on the block identified by the block hash sent from blocknotify.  I've been trying to find the structure of the data returned by getblock and it seems to be similar to what Luke-Jr entered in his second code box at https://bitcointalk.org/index.php?topic=89725.0.  Is this correct?  If so, then it seems that getblock can return many transaction IDs in the "tx" array.  If so, then it seems that one possible approach is to process each one of the transaction IDs to find the user accounts and number of confirmations and then update your database accordingly.  Based on what you wrote previously, it seems that you do not prefer to do it this way, but you prefer to query your database for users with unconfirmed funds and then call getbalance [account] [minconf=0] and getbalance [account] [minconf=4] on each user account and if the amount of BTCs is the same for both getbalance calls, then you update/indicate the user's BTC amount as all confirmed.  Correct?

Yea - that's SSL between the rpc client and the bitcoind rpc server.  If it's on the same machine, you may be able to forego ssl.  We have it enabled.

I'm wondering if I can get by having both the RPC client and bitcoind RPC server on the same machine.  I assume that this is less secure than having the RPC client and bitcoind RPC server on different machines.  If so, do you know how much less secure it is or what the risks are?  Am I correct to assume that when you get a *notify on the bitcoind RPC server, it runs a curl command that invokes the RPC client which processes the data by running jsonRPCClient (https://en.bitcoin.it/wiki/API_reference_(JSON-RPC))?

Do you know the syntax for the curl command for gettransaction or getblock?  I tried the following:

curl --user bituser --data-binary '{"id":"t0", "method": "gettransaction c92d655f850a0feae01d785733a74e4d610fc07d0da4d7c086f363569f550ec8", "params": [] }' http://127.0.0.1:8332/

but i get an error:

{"result":null,"error":{"code":-32601,"message":"Method not found"},"id":"t0"}
bitpop
Legendary
*
Offline Offline

Activity: 2912
Merit: 1060



View Profile WWW
January 31, 2014, 05:45:45 AM
 #44

That id might have to go in params

jlp (OP)
Sr. Member
****
Offline Offline

Activity: 266
Merit: 264


View Profile
January 31, 2014, 02:17:40 PM
 #45

That id might have to go in params

Thanks.  I had tried the following in the past, but it didn't work:

curl --user bituser --data-binary '{"id":"t0", "method": "gettransaction", "params": [c92d655f850a0feae01d785733a74e4d610fc07d0da4d7c086f363569f550ec8] }' http://127.0.0.1:8332/

I tried putting in quotes and it worked:

curl --user bituser --data-binary '{"id":"t0", "method": "gettransaction", "params": ["c92d655f850a0feae01d785733a74e4d610fc07d0da4d7c086f363569f550ec8"] }' http://127.0.0.1:8332/
Pages: « 1 2 [3]  All
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!