rust-bitcoin-indexer: How to interact with a blockchain

or: Notes on indexing blockchains

A copy of this post can be found on rust-bitcoin-indexer wiki.

Abstract: I have ventured on the quest of discovering the best way to index a blockchain. Surprisingly little has been written about it, considering that it is a common task for any organization handling blockchain-based interactions. It seems that, it is an area dominated by in-house solutions, with very little knowledge sharing. In this post, I go over the problem, ideas, discoveries, and experiences. I also describe a Bitcoin Indexer implementation that I have worked on while researching the subject: rust-bitcoin-indexer.

I expect the reader to be familiar with at least the basics of Bitcoin.

Please note that this is not scientific research and only a spare-time project. Feel free to contact me with comments: pointing out any mistakes and ideas for improvements.

2019-02-20 · 20 min · 

Smart contracts and token economy without Blockchains

or: A token (even smart one) needs a blockchain, like a fish needs a bicycle.

Tokenizing assets on a Blockchain

Image above: Tokenizing assets on a Blockchain

Abstract

In this post, I explain why I believe Blockchains are just coincidentally associated with "token economy" and smart contracts, and how in essence they are not their enablers, but actually a hindrance. Then I propose an alternative: a concept of an open, federated smart contract system, that maintains all the benefits traditionally associated with blockchain platforms like Ethereum and can practically support a global scale token-economy, without all the problems inherent to blockchain-based systems.

2019-01-30 · 9 min · 

Be warned: Tests are great calcifiers

Today, I'm going to give a contrarian view on tests and testing in software.

From my experience, the most common view on software testing is: "Tests! Tests! Always have tests! Start with a test! End with a test! More tests - good! Less tests - bad! 100% coverage! Test everything! How can you not have tests everywhere?!" ...

... or its opposite-side tween: "Tests? Why bother? Maybe later."

Before I go any further, a note for the typical distracted reader, that is going to skim over the text, misunderstand it, and go rage over social media how stupid the author of this post is: I'm not saying that tests are bad. I'm going to focus on the bad side, but that is not the only side. Go read somewhere else about the good sides.

2019-01-25 · 7 min · 

The strange case of monetary policy in Grin

I am a crypto-finance enthusiast and though I am strongly skewed toward Bitcoin maximalism, I still try to follow the space looking for promising technologies and ecosystems.

One of the coins that really caught my interest was Grin

  • It has no fishy business (pre-mine, dev-taxes),
  • is written in #Rust (which, I think, is a perfect language for #cryptofin),
  • it is based on MimbleWimble which is a very promising tech improving blockchain scalability.

It ticks all the boxes to be a reasonable altcoin.

The only problem with it is it's controversial monetary policy. Basically: one coin, every second, forever. While I don't mind the "forever" part, the problem with Grin's monetary policy is the steady and long initial inflation rate.

2019-01-12 · 5 min · 

`cargo-crev` and Rust 2019 fearless code reuse

Code reuse in Rust

In my opinion, one of the biggest reasons why Rust is so productive is that it's a superb language for code reuse.

First, ownership and borrowing system allows exposing in the API properties that are often impossible to express in other languages. The fact that the API communicates and enforces how the resources are being created, shared and moved and destroyed, all checked at the compilation time, gives the user great confidence that they are using any API - internal or external - correctly.

Second, Rust comes with first-class built-in tooling around discovering, creating, sharing and using publicly available Open Source libraries. It's not a property unique to Rust, but it builds a powerful synergy when combined with the first point.

Third, the community (at least so far), were strongly encouraging uniformity and commonality: similar code style, similar documentation style, common core libraries, and patterns. A big chunk of this effort was achieved through great tooling like rustfmt and clippy. Thanks to this, Rust ecosystem does not feel fragmented. Jumping into a code authored by someone else does not feel like a venture into a foreign land, as it often does in other programming languages.

Together, this properties creates a language and ecosystem where code reuse is almost effortless. While in other languages it's often more tempting and more convenient to implement things yourself and avoid learning a new API, in Rust the difference between own and 3rd party code, often blurs completely. In a way, this creates a completely new quality of building your software.

Despite all these strengths, there's one problem that sticks out like a sore thumb: trust. Every additional dependency is another piece of code that could be buggy, or even malicious. And in my opinion, it's problem so serious, that is entirely blocking the untapped potential of code reuse in Rust.

2018-12-28 · 6 min · 

Iteration time trumps everything

The longer I do software engineering (and even things outside of it), the more confidence I have that one of the most important metrics (most important one?) in any sort of creative process is iteration time.

What do I mean by iteration time? The time between having an idea for change and getting real feedback from the real world what are the results of implementing this idea.

Worse is Better, Agile, Lean, Antifragile they can all be destiled to iteration time.

The world is an infinitely complex place. It's very very hard to predict the real results of any action. Because of that, to navigate world it's best to make small steps and collect feedback. The faster you can make these steps, the faster you use a new knowledge, to make new, better steps, which compounds very quickly.

It's a principle so powerful, that taken to extreme allows agents that literally have no understanding of anything, beat everyone.

2018-11-21 · 5 min · 

The faster you unlearn OOP, the better for you and your software

Object-oriented programming is an exceptionally bad idea which could only have originated in California.

-- Edsger W. Dijkstra

Maybe it's just my experience, but Object-Oriented Programming seems like a default, most common paradigm of software engineering. The one typically thought to students, featured in online material and for some reason, spontaneously applied even by people that didn't intend it.

I know how succumbing it is, and how great of an idea it seems on the surface. It took me years to break its spell, and understand clearly how horrible it is and why. Because of this perspective, I have a strong belief that it's important that people understand what is wrong with OOP, and what they should do instead.

Many people discussed problems with OOP before, and I will provide a list of my favorite articles and videos at the end of this post. Before that, I'd like to give it my own take.

2018-11-19 · 9 min · 

All the right moves in #Rust

2018-11-14 · 1 min · 

Still in love with Rust

I think I've discovered Rust somewhere around the year 2012. Back then it was much different language than it is today. It had green-threads, @ and ~ were used a lot, and there was even a GC.

Rust caught my attention because I was looking for a language for myself. I always considered myself "a C guy": a bottom-up developer, that first learned machine code, then learned higher level programming. And while C was my language of choice, I couldn't stand it anymore.

I was tired of how difficult it was to write a correct, robust software in C, especially:

  • inability to create solid abstractions and nice APIs,
  • segfaults, double checking my pointers and general lack of trust in my code,
  • make and make-likes building system.

I loved the simplicity and minimalism, I loved the flexibility and control, but I couldn't stand primitivism and lack of modern features.

With time I grew more and more fond of Rust. The language kept evolving in a direction that was my personal sweet spot: a modern C. And at some point I realized I'm in love with Rust. And I still am today, after a couple of years of using it.

Just look at my github profile. It has "Rust" written all over it. And check how my contributions grew since 2013. Rust made me much more productive and enthusiastic about programming.

So let me tell you why is Rust my darling programming language.

2018-11-05 · 8 min · 

Rust’s fearless concurrency in `rdedup`

Introduction

In this post, I will describe how I refactored quite complicated Rust codebase (rdedup) to optimize performance and utilize 100% of CPU cores.

This will serve as a documentation of rdedup.

Other reasons it might be interesting:

  • I explain some details of deduplication in rdedup.
  • I show an interesting approach of zero-copy data stream processing in Rust.
  • I show how to optimize fsync calls.
  • I share tips working on performance-oriented Rust codebase.

2017-04-04 · 7 min · 

My opinion on Go

TL;DR

The biggest strength of #Go, IMO, was the FAD created by the fact that it is “backed by Google”. That gave Go immediate traction and bootstrapped a decently sized ecosystem. Everybody knows about it, and have a somewhat positive attitude thinking “it’s simple, fast, and easy to learn”.

I enjoy (crude but still) static typing, compiling to native code, and most of all: native-green thread, making Go quite productive for server-side code. I just had to get used to many workarounds for lack of generics, remember about avoid all the Go landmines and ignore poor expressiveness.

My favorite thing about Go, is that it produces static, native binaries. Unlike software written in Python, getting software written in Go to actually run is always painless.

However, overall, Go is a poorly designed language full of painful archaisms. It ignores multiple great ideas from programming languages research and other PL experiences.

“Go’s simplicity is syntactic. The complexity is in semantics and runtime behavior.”

Every time I write code in Go, I get the job done, but I feel deeply disappointed.

2016-09-27 · 5 min · 

Make current dir a tmux session placeholder

2016-09-15 · 1 min · 

Precache all the things!

Having a lot of RAM nowadays is relatively cheap and Linux can make a good use of it. With tools like preload most of Linux distributions are trying to proactively read things that you might want to use soon.

However if your desktop have a ridiculous amount of memory (mine has 32GB) it may take ages for these tools to make use of all that memory. And why would you pay for it and then let it just sit idle instead of working for you?

The thing is: you can do much better, because you know what you are going to use in the future.

So, as always, let’s write a tiny script under the name precache.

#!/bin/sh

exec nice -n 20 ionice -c 3 find "${1:-.}" -xdev -type f \
    -exec nice -n 20 ionice -c 3 cat '{}' \; > /dev/null

Personally I keep it as $HOME/bin/precache.

2015-09-15 · 2 min ·