How to do iterative steemd development on a local testnet

in #utopian-io7 years ago (edited)

I've mentioned tintoy in the past. It's a tool that lets you test various scenarios using a tiny blockchain. If you take all of the defaults, you can use it to test your API clients or applications as if you're using the mainnet.

But we can do more even more.

The purpose of this tutorial is to set up our tiny blockchain so you can test your local changes to steemd. Our tiny blockchain runs as a testnet, so you need to build it before sending it over to tintoy (the default Dockerfile for steemd happens to already do this). Once it's up and running, you'll have about 2,000 accounts and even get a trickle of transactions coming in, automatically.

No need to spin up a full sized testnet!


TL;DR: Dockerize your local steemd development branch, then run it in tintoy.


For this tutorial, I'll be using Docker Desktop, but the general steps should work with any docker provisioning.



First, we get a copy of of the steemd from the official repo and do the Docker build method:

mkdir -p ~/src
cd ~/src
git clone https://github.com/steemit/steem
cd steem

Note: If you have skipped git clone because you want to rebuild a pre-existing branch you're already developing on, don't forget to delete build from here because it will interfere with docker build.

Optional: Next, we can modify a few things like edit libraries/protocol/include/steem/protocol/config.hpp and set a STEEM_INIT_SUPPLY.

Now we can work on the project and add features or fix bugs, whatever. Before we commit/push our changes and do a pull request, we can take our modified version of steemd for a spin:

docker build --build-arg BUILD_STEP=2 -t steemit/steem:mybranch .

Don't forget to add a period (.) to the end of the above command.

Note: For compiling, the default size of your Docker Engine might need some fiddling. If your build fails, check these defaults and set Memory and/or Swap to something higher. Setting them both to 4.0 GiB is usually sufficient, for doing builds.



Once it's done building, we can get a copy of tintoy.

cd ~/src
git clone https://gist.github.com/b88e7bfff8862858e54c59392e2bce20.git tintoy
cd tintoy

Modify Dockerfile in tintoy and change the first line so it matches the previous docker build we used for steemd (above), e.g.:

FROM steemit/steem:mybranch

Next, build and run tintoy:

docker build -t myname/tintoy:mybranch .
docker run -d -P myname/tintoy:mybranch

Now you can shell in or get the ports and attach your favorite JSON-RPC explorer to see how well your changes perform.

Or, instead of running on ephemeral ports (-P), you can bind to the API, e.g.:

docker run -d -p 8090:8090 myname/tintoy:mybranch

Either way, once tintoy has finished starting up, you'll see in the logs:

[√] testnet: true
[√] head block time: within 3 seconds
[√] scheduled witnesses: 21
[√] majority version: 0.21.0

This means the node has fully bootstrapped and synced. You can now access your blockchain (the following assumes we ran with bound ports as -p 8090:8090):

curl -s --data '{"jsonrpc":"2.0", "method":"condenser_api.get_account_count", "params":[], "id":1}' http://localhost:8090

Which returns:

{
  "jsonrpc": "2.0",
  "result": 2037,
  "id": 1
}

Our toy blockchain has successfully launched using a modified version of steemd with 2037 accounts to play with.

Sort:  

I thank you for your contribution. Here are my thoughts. Note that, my thoughts are my personal ideas on your post and they are not directly related to the review and scoring unlike the answers I gave in the questionnaire;

  • Structure

    • Structure of your post is superb!
  • Language

    • The language of your post is also superb. There are some first persons but it's not a big deal. After all, I'm not the person who can judge about it! :P
  • Content

    • Normally, I like complex tutorials like "how to create a blockchain" in tutorials category. But, I liked your simplicity on this. It is very straight and this makes it very efficient. Thanks for posting!

Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

Thanks for your comments. There's a certain level of "know your audience" I'm trying to leverage here, and I think you might have picked up on it. I suspect certain developers already heavily use some kind of docker strategy to speed up iterative development. But those developers also rarely use iterative cycles for most of their daily work. In other words, they know exactly what they want and fast-turn-around-per-line-of-code isn't important.

But when it is important, getting that code to execute when there's nothing in the blockchain is a huge (or just expensive) roadblock. I happen to know that one of the design goals of tinman was to allow deploying a testnet with a sample account list. But that requires a good amount of time to prepare. Thus, the only real bottleneck in this strategy is how long it takes to compile because the 2,000 sample accounts are delivered as part of the tintoy docker image.

Thank you for your review, @yokunjon! Keep up the good work!

Pretty cool I have to say, some time booked to look at this very soon. Thanks!

Have you worked on steemd very much? I've only ever tweaked it here and there just to make sure I could if I wanted to.

Same, but I'd really like to change that.

Hey, @inertia!

Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Get higher incentives and support Utopian.io!
Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via SteemPlus or Steeditor).

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

Hi @inertia!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your UA account score is currently 6.469 which ranks you at #165 across all Steem accounts.
Your rank has not changed in the last three days.

In our last Algorithmic Curation Round, consisting of 185 contributions, your post is ranked at #24.

Evaluation of your UA score:
  • You've built up a nice network.
  • The readers appreciate your great work!
  • You have already shown user engagement, try to improve it further.

Feel free to join our @steem-ua Discord server