3 ms·
Are we allowed to share repos we've written? :) If so, then here's distributed consensus in Zig: https://github.com/coilhq/tigerbeetle/blob/main/src/vsr/repli
by _vvhw 5y ago
Are we allowed to share repos we've written? :)
If so, then here's distributed consensus in Zig:
https://github.com/coilhq/tigerbeetle/blob/main/src/vsr/replica.zig#L624 https://github.com/coilhq/tigerbeetle/blob/main/src/vsr/repl...
Something that differentiates this from many consensus implementations is that there's no boilerplate networking/multithreading code leaking through, it's all message passing, so that it can be deterministically fuzz tested.
I learned so much, and had so much fun writing this, that I also hope it's an enjoyable read—or please let me know what can be improved!
- Mawr 5y agoVery clean, tasteful formatting. Easy to read. There's even correct splitting of long argument lists over multiple lines: [1], [2]. You don't see that very often, most programmers have awful taste about this. I have some qualms with these one-line early returns though: if (commit <= self.commit_min) return; Control flow statements should always be on their own lines, then it's easy to find all of them by visually scanning top-down, without needing to look all the way down each line. [1]: https://github.com/coilhq/tigerbeetle/blob/main/src/vsr/replica.zig#L202 https://github.com/coilhq/tigerbeetle/blob/main/src/vsr/repl... [2]: https://github.com/coilhq/tigerbeetle/blob/main/src/vsr/replica.zig#L268 https://github.com/coilhq/tigerbeetle/blob/main/src/vsr/repl...
- mbrock 5y agoZig's code formatter puts list items on separate lines if the last item has a trailing comma; otherwise, it puts them all on the same line. So if you use the code formatter, you'll either have just one line, or one line per item. It's pretty nice.