How to contribute to Bitcoin-S?

·

6 min read

Starting with working on a new codebase is always a daunting task, more so, if the codebase is vast, as it usually is for established projects. This blog post is what I would have given to my past self when starting with working on Bitcoin-S.

Learning

Scala!

Scala was a new language for me. But given how "similar" C++, Java or Python are, I felt its just a matter of syntax, so should be easy enough, right? Well, I won't say it is hard, I feel different from what I expected would be a better phrase here.

Scala allows you to write code in the functional programming paradigm. You can choose not to, but then why use Scala in the first place! A quick way to get started with the language basics would be this Tour of Scala. This, I assure you, suffices the basics you need to know.

Future[T]

Now this is where things get interesting and where I struggled with a little. Make sure you absolutely understand everything related to futures in Scala. It's not a lot to cover to be honest, but covering it thoroughly is must. Know what an Execution Context, map, flatMap, for yield etc is and you should be good to go. A little knowledge of akka particularly, Actor and Streams would be good too but you can always pick that up while working.

Managing state when everything is immutable!

Another interesting problem you would run into soon enough. I was not used to this style and my first line of thought almost always involved some mutable state. Again, nothing super hard about it, just different from what I was used to. The way to go about it is simply reading the code already present in the repository and see how the existing things are done. A little bit of reading and following the correct approach right from the start would save you a lot of time down the line!

Getting your feet wet

Setting up the dev environment

Quite a boring prerequisite, but needs to be done. Fortunately, for Bitcoin-S, and most open projects that you may happen to work on, would have well written guides on how to do so. The one for Bitcoin-S is here. A link or steps to do this is almost always present in the README of the repository.

After that it's just following the steps and you should be good to go. Try building it from source and then just playing around with it a little so you are comfortable with the process. You might also want to learn a little bit about sbt (Scala Build Tool) here. Nothing much, just what a build.sbt is like and how you would go about building different modules and running tests.

Time to work but on what?

Bitcoin-S and many other open source projects usually have issues tagged with good first issue. That would be an ideal place to start. Filter the issues based on this tag and see what catches your attention. You may want to join the developer slack too where you can ask any question you have or get help on some problem you are facing. The general rule is just to not be "that guy", try on your own first, remember google is your friend and if you still can't fix some issue, try posting about it in the appropriate slack channel along with what YOU did.

Know the difference between a question and a discussion! A question puts a burden on the next person, a discussion does not. You should discuss what you are doing, as in your approach, time and again (but again learn to read the room too) and often times the next person can put you on the right track if you are missing something or share their own experience that may he helpful.

For Bitcoin-S, I would personally suggest you to add some tests if you feel even good first issues are too tough, sometimes they actually may be, no problem in that.

  1. Any project can never have enough tests so they are always welcome. I had mostly worked on Node module and at the time of writing this blog, we sure could use a lot more tests there for various network conditions. Does the node restart if we stop it in between? Does it do so while syncing headers? What about compact filters? I hope you get the gist.
  2. They are fairly easy to write and you use some part of the project you would be working on. For Bitcoin-S, scalatest is what is used. Just read a bit on using it, again, google is your friend, and read some existing tests and you should be good to go.

Sky is the limit!

Start small but move up taking up harder and more important tasks, your goal should be to learn. Don't be hesitant of making huge changes, sometimes they are required, rather do it right once and for all, shouldn't we? But do discuss them first! At this point you are self-sufficient and don't need this blog anymore. Kudos to you!

My experience

My work has been primarily concerned with Node but this would apply to anything else too. Firstly, working on someone else's code is always tough, so take your time understanding how things are done. You can't read through the entire codebase but should try to have a rough understanding of how what you intend to change and the related parts work, mainly what the execution flow is like.

Let me give you an example that will make it clear. The first change would be simple. So suppose I want to change how a BlockMessage is handled. You know that Node module handles all this. But now what? How do you start? Use a good IDE, I recommend IntelliJ for Scala, and a bit off-topic, but try to actually use the tools the IDE provides if you are new to it, it's more than just a text editor! I would start with finding usages of BlockMessage, this would lead you to DataMessageHandler, and as the name suggests, this is what handles all data messages, BlockMessage being one of them. See how BlockMessage is processed in here. Now don't just limit yourself to just this one file. Don't go too far, but get an idea of other stuff going on. You would see that some callbacks are executed on a BlockMessage. It's header is processed too. Know what uses this DataMessageHandler and how. What are the callbacks for? How is the associated header processed? This is how you would slowly get familiar with the codebase while also making progress at a steady pace. Of course, I too found the codebase absolutely massive at first and felt making sense of it was too tough a task, but sooner than you expect, you would be doing just fine.

Well, you must be determined to have made it to the end, best of luck in that case! Hope you found this helpful.