When and how to spam scalenet

13 1329
Avatar for jtoomim
3 years ago

Most of this article will be a step-by-step guide on how to generate spam on scalenet. But before we get to that, I would like to discuss the purpose of scalenet, and what kinds of behavior are appropriate and inappropriate on scalenet.

When to spam

There is a right way and a wrong way to use scalenet; a path of light, and a path of darkness. The purpose of this section is to describe the straight and narrow path of light, and the mysterious path of darkness.

Scalenet is intended to be a public sandbox for testing performance-related aspects of Bitcoin Cash. It is intended to be a proving ground for new technologies, a place where people can try out weird and unexpected things and make a mess of the blockchain in an attempt to stress the limits of technology. It's the Wild West of blockchains. Here are some behaviors that are considered acceptable on scalenet:

  1. Testing your own software that you are running to see if you can break it

  2. Testing other people's software to see if you can break it

  3. Testing your hardware to see if you can break it

  4. Testing other people's hardware to see if you can break it

  5. Seeing how quickly you can generate spam because why not

  6. Leaving that spam around for other miners to clean up

  7. Screwing around and having fun

  8. Intentionally bloating the UTXO set to tens or hundreds of gigabytes

  9. Trying out worst-case scenarios and exploiting O(n^2) vulnerabilities

  10. Attempting 51% attack shenanigans

  11. Doing CPU mining

  12. Doing ASIC mining

  13. Forking scalenet to test new protocol upgrade code

  14. Forking scalenet because you were bored

  15. Forking scalenet because there is no spoon

  16. Using bitcoin-cli to generate a million transactions because the infinite scroll of TXIDs in terminal windows with a green font makes you feel like The Matrix

  17. Trying to trick your boss into thinking that you're being productive when you just want to have fun

Scalenet is a pretty open an permissive environment. However, there are four important guidelines that everyone ought to follow in order to make sure that scalenet works well for everyone. The following behaviors are explicitly discouraged on scalenet:

  1. Asking for permission to use scalenet

  2. Not using scalenet because you don't want to disturb others

  3. Staying off of scalenet because you think you're not smart enough to participate

  4. Failing to learn because you were afraid to experiment

The path of light leads to places we've already been. The path of darkness leads into the unknown. We must keep our project safe from monsters; and if we are to succeed at that, we must learn how to become monsters ourselves. Stare into the abyss and explore its depths until eventually the abyss stares back at you.

How to spam

Method 1: Using BCHN, bitcoin-cli, and bash

  1. Download BCHN.

  2. Unpack and/or install BCHN. For the rest of this guide, I will assume that you are running a Linux/Unix terminal from the folder containing your BCHN binaries.

  3. Run BCHN on scalenet:

    ./bitcoind -daemon -scalenet -blockmaxsize=256000000 -debug=bench
  4. Optionally, in a separate terminal window, watch the debug.log file:

    tail -f ~/.bitcoin/scalenet/debug.log
  5. Get money. You can either ask someone else (e.g. me) to give you some coins, or you can try mining a block or two with https://github.com/pooler/cpuminer. To do either, you'll first need to get a scalenet tBCH address:

    ./bitcoin-cli -scalenet getnewaddress

    should return something likebchtest:qrfeyt384f6a29aw5uf4g5cteaumup99gqx8nmwu2j

    Use that address to beg for coins, or try setting up the cpuminer to mine to that address. (I might add CPU mining instructions later.)

  6. You should now have money in your wallet. Verify that you're no longer poor:

    ./bitcoin-cli -scalenet getunconfirmedbalance or getbalance should return something like 50.00000000

  7. Wait until it confirms and shows up in getbalance, then store that amount into a BASH variable:

    bb=$(./bitcoin-cli -scalenet getbestblockhash)
    while [ $(./bitcoin-cli -scalenet getbestblockhash) == $bb ]; do sleep 1; done
    rootamt=$(./bitcoin-cli -scalenet getbalance)

    These lines of BASH will run the command encapsulated in the $(), and replace the $(...) text with the output of that command. That output then gets stored into the variables bb and rootamt. Check that it worked: echo $rootamt should show something like 50.00000000.

  8. Now we're going to start generating UTXOs in a fan-out process. BCH is currently limited to 50 unconfirmed transactions in a chain. In order to make more than 50 transactions per block, you will need to be able to start with more than one UTXO in your wallet at the start of each block interval. We can do this with a fan-out process using the sendmany RPC call, which generates a single transaction with multiple specified outputs.

    Because we're sending money from our own wallet to our own wallet, if we make multiple transactions, there's a chance that the wallet might consume the UTXOs that the previous transaction created, so we're going to be careful to decrease the amount output in each transaction each round in order to discourage the wallet coin selection code from spending more than one input per transaction.

    Let's craft a transaction that sends 1/100th of our rootamt to 99 different addresses which we'll generate, with the remainder going to a change address that our wallet generates:

    outputcnt=100
    outputamt=$(echo $rootamt | awk '{printf "%0.8f", $1 / $outputcnt}')
    echo $outputamt
    # make a json dictionary of {"address":"amount", ...} pairings
    outputs=$(for i in $(seq 1 99); do 
        echo "\"$(./bitcoin-cli -scalenet getnewaddress)\":\"$outputamt\", "
      done)
    outputs=${outputs%??}     # trim off the last comma and space
    outputs={$outputs}        # Make outputs a valid json dictionary
    
    # Generate the sendmany transaction
    ./bitcoin-cli -scalenet sendmany "" "$outputs"
  9. Wait for that transaction to confirm, then we'll do another round to multiply our number of UTXOs by 100. To save time:

    bb=$(./bitcoin-cli -scalenet getbestblockhash);
    while [ $(./bitcoin-cli -scalenet getbestblockhash) == $bb ]; do 
        sleep 1;
      done; echo Block found!
    
    outputcnt=$((outputcnt * 100))
    outputamt=$(echo $rootamt $outputcnt | awk '{printf "%0.8f", $1 / $2}')
    echo $outputamt
    # make a json dictionary of {"address":"amount", ...} pairings
    outputs=$(for i in $(seq 1 99); do 
        echo "\"$(./bitcoin-cli -scalenet getnewaddress)\":\"$outputamt\", "
     done)
    outputs=${outputs%??}     # trim off the last comma and space
    outputs={$outputs}        # Make outputs a valid json dictionary
    
    # Generate the sendmany transactions
    for i in $(seq 1 $((outputcnt/100 - 1))); do
        echo -n "$i "
        ./bitcoin-cli -scalenet sendmany "" "$outputs"
    done
  10. You should now have 10,000 UTXOs in your wallet. If you want more, you can repeat step 9 as many times as you want. But 10k should be enough for most mortals.

  11. You are now ready to start spamming. If you want to make 1000 transactions as quickly as you can, using a freshly generated address each time, and sending 546 satoshis (the dust limit) to each address, you can use the following command:

    for i in $(seq 1 1000); do 
        echo -n "$i "
        ./bitcoin-cli -scalenet sendtoaddress "$(./bitcoin-cli -scalenet getnewaddress)" 0.00000546 "" "" false 2
    done
  12. If you wish to improve performance you can try some of the following:

    1. Make sure your wallet.dat file (usually at ~/.bitcoin/scalenet/wallet.dat) is stored on fast media like an SSD or a ramdisk. You can use the ./bitcoind -walletdir=<path> ... command-line option to specify where you want the wallet to go. Keep in mind that if you use a ramdisk, you will lose your wallet and many of your coins when you reboot unless you copy your wallet back to permanent storage. An HDD or SD card will likely limit you to a generation rate of about 10 tx/sec; a SSD can get you up to around 100 tx/sec, and a RAM disk (sudo mkdir /tmpfs; sudo mount -t tmpfs -size 4G /tmpfs) can sometimes get you past that, especially if you:

    2. Use MR !830 and compile from source, if you know how. MR !830 with a RAM disk can usually sustain around 300 tx/sec on a decent x86 CPU.

    3. Reuse the same output address:

      address=$(./bitcoin-cli -scalenet getnewaddress)
      for i in $(seq 1 1000); do 
          echo -n "$i "
          ./bitcoin-cli -scalenet sendtoaddress "$address" 0.00000546 "" "" false 2
      done
    4. Use more computers, or run multiple nodes on the same computer to get access to multiple CPU cores.

  13. To see how your spamming is coming along, you can run ./bitcoin-cli -scalenet getmempoolinfo or check https://sbch.loping.net/.

  14. If you've had enough, you can shut down scalenet with

    ./bitcoin-cli -scalenet stop
  15. ...

  16. Profit!

Method 2: txVulcano

txVulcano (from Flowee) might be able to work with scalenet, but I haven't tried it yet.

Method 3: Txunami

Andrew Stone of Bitcoin Unlimited has developed the Txunami tool for multithreaded spam generation. It does not save the output UTXOs, so any coins you use with Txunami will eventually be lost.

I have not used this tool, so I do not know how hard it would be to get it to work on scalenet. If anyone is able to get this to work, please write down how you did it.

Scalenet is a fountain of chaos. May its waters remain forever turbulent.

55
$ 28.34
$ 11.84 from @TheRandomRewarder
$ 5.50 from @mtrycz
$ 5.00 from @codevalley
+ 13
Avatar for jtoomim
3 years ago

Comments

Good. Please support my profile and articles. Thankyou.

$ 0.00
3 years ago

Never beg for others to support you. Please work hard to get them by writing creatibe content and engaging in a convo with sense in the comment section.

$ 0.00
3 years ago

this is over my head, but super cool project idea! I freaking love the crypto communities

$ 0.00
3 years ago

Awesome post, and I'm indeed very happy to see Scalenet happen. We got a MR last month and it is supported in Flowee the Hub.

Flowee TxVulcano is likely a really fun way to generate transactions. It has its own wallet, which it saves, and is multi-threaded. Multi-threaded is useless if your full node isn't accepting them into the mempool the same, so it works in tandem with a Flowee the Hub. Using the latest master it was pretty darn fast. (about half a minute to fill up a 50MB block, IIRC)

The only problem towards using it on scalenet is that the method of funding is currently to call 'generate'. Which won't work there. So a little update would be needed to make it accept a deposit address instead.

More hardcoded numbers could be made configurable, for instance the code uses a spread-out strategy (more outputs than inputs) until a certain number of UTXOs is reached. To try and create a massive UTXO-DB this needs to be made configurable.

Patches more than welcome, its code is probably a bit more messy than you'd expect, but at least its standalone and nobody will mind if stuff breaks.

$ 1.00
3 years ago

Thanks, Justin Holmes! I think it's awesome that I have absolutely no idea who that is.

$ 0.00
3 years ago

So what's the best thing about scalenet again? So people spam it for a good cause.

$ 0.00
3 years ago

Scalenet is a BCH testnet with (currently) a 256 MB blocksize limit. It's intended as a place where people can test the performance limits of their software or hardware without needing to worry about annoying any users. Testing the software in stressful conditions helps developers learn what needs to be improved.

$ 0.00
3 years ago

First of all, what is scalenet?

$ 0.00
3 years ago

Scalenet is a BCH testnet intended for stress-testing BCH software in high-throughput conditions.

$ 0.00
3 years ago

love your post is rich with info

$ 0.00
3 years ago

The great

$ 0.00
3 years ago