Bitcoin Core Network Event Loops

This article is an analysis of the network event loops based on bitcoin core v0.19.0.

Bitcoin starts two threads to handle network messages, and each thread runs its own event loop.

I prefer using Vim in a terminal. I can switch to the shell with Ctrl-Z and back with fg. However it is hard to integrate a terminal command with other GUI tools, such as editing a file in Vim from Finder.

In macOS, the default Terminal app and iTerm both supports automation. It's easy to write a script to open a new terminal window and run a command like “vim file” in it. But I want to close the window after Vim quits. A quick work around is running the following command:

vim file; exit 0

Now the problem is that if I suspend Vim via Ctrl-Z, the terminal window is closed, because shell will continue to execute the next command when the process is suspended.

After research and reading a StackOverflow answer, I wrote two scripts to launch Vim in iTerm. I also added features in iterm-vim-wrapper to edit clipboard and empty scratch file in temporary directory.

This is an example which uses the scripts to create File Action in Alfred.

I prefer reading my mails in the Gmail web client directly. I rarely send new mails or replies. But when I do, I want to use PGP to encrypt or sign the mail. I have tried two extensions to use PGP in Gmail, FlowCrypt and Mailvelope. But both of them are far from a competent solution for me. GPG Mail in the GPG Suite for macOS is still my preferred way. However, GPG Mail is an Apple Mail plugin, which requires downloading mails first. Based on my scenarios, I only need to download the mails I left in the inbox. But the basic setup of Gmail in Apple Mail will download many mails in the background.

I tried POP3. It has two issues:

  • The status is not synchronized with the server. I can configure Gmail to archive the mails which have been downloaded via POP3, but that means once I have downloaded mails, I must process them locally. This is a burden, since I only want to reply several mails in the client.
  • POP3 does not observe the filter which auto archives new mails. The filtered emails still occur in the client.

IMAP is still the better choice. The real issue is indeed that Apple Mail uses remote IMAP mail boxes for Drafts, Sent, Junk, Trash and Archive by default. If it uses local mail boxes instead, the client will no longer try to synchronize this mail boxes.

Following is the detailed instructions to setup a Gmail IMAP client which only downloads mails in the inbox.

I have read the post Get Everything Done & Still Have Time to Play by Jackie Ashton recently and adopted some strategies into my process.

Before I plan the tasks daily by allocating them into time slots in a calendar, it is tedious and time-wasting. It messes up my agenda, which is intended only to contain the events that I must do on time. And it makes me nervous and exhausted to follow a pre-defined schedule every day.

My new process is much simpler. I review my life objectives first and group them into categories. Then I evaluate their importance in my current life stage and allocate my energy in percentage into them.

How to mock time in Rust tests and Cargo gotchas we met. I'm working in a team developing a big Rust project recently. The project has some features depending on time. We, the developers, want to be able to mock the time in the test. In this post, I'll talk about the problems we have met, mostly related to Cargo.

In Rust document, Cell is “A mutable memory location”, and RefCell is “A mutable memory location with dynamically checked borrow rules”.

They both provide “interior mutability”, where you can modify the value stored in cell via immutable reference of the cell.

They both have an API get_mut to return a mutable reference to the underlying data. This method requires a mutable reference to the cell, which guarantees that the callee has exclusive ownership of the cell.

pub fn get_mut(&mut self) -> &mut T

The difference is how they implement interior mutability. Cell copies or moves contained value, while RefCell allows both mutable and immutable reference borrowing. I will try to explain the difference via their APIs in this article.

I categorize reading into 3 different categories:

  • Skim Reading: This includes the feeds I subscribed in Inoreader, websites I frequently visit and articles shared from my friends. I quickly skim them using fragmented time, usually less than half an hour in total per day, and save the articles which worth reading to Instapaper.
  • Insensitive Reading: Instapaper sends me 20 unread articles to Kindle every morning. If I can spare at least 10 minutes, I will read them on the Kindle.
  • Challenging Reading: Papers are definitely in this category. There are also articles hard to understand, I will print them into PDF. I schedule the time in advance, usually one hour or more, and read the PDF files on Sony Digital Paper.

I'll share the detailed workflow and the IFTTT applets used in the process.

https://papers.ssrn.com/sol3/papers.cfm?abstract_id=3243656

Introduction

(LR is) as flexible and responsive as the market, but avoids free-rider problems.

  • Flexible and responsive: any one can propose a new public good project, and the project can get enough fundings even when only a small community funds it.
  • Subsidies create incentives for citizens to fund projects.

Background

(Free-rider problem is) due to the expense or inefficiency involved in excluding individuals from access.

Cons of Existing Solutions

  • 1p1v: oppress minorities.
  • Capitalism: inefficiently exclude potential users.
  • Charitable organization: difficult to closely align reliably with the common good.
  • QV: it doesn’t solve the problem of flexibility, a.k.a., it requires a curated projects list.

Model

Assumptions

  • We can verifiably distinguish among and identify these citizens.
  • Any citizen may at any time propose a new public good.
  • Our interest here is in maximization of dollar-equivalent value rather than achieving an equitable distribution of value.
  • Utility function V is concave (国内的叫法一般是反的,即我们平常说的凸函数), smooth, increasing.
  • The deficit is not bounded, a.k.a, the funding solution can collect unbounded taxes.

Economic problem of society is mainly one of rapid adaptation to changes in the particular circumstances of time and place, it would seem to follow that the ultimate decisions must be left to the people who are familiar with these circumstances, who know directly of the relevant changes and of the resources immediately available to meet them.

The knowledge is dispersed and rapid changes. To take advantage of this knowledge, people must make decision distributively. People require only relevant information to make better decisions. This communicating mechanism should be

communicating to him such further information as he needs to fit his decisions into the whole pattern of changes of the larger economic system.

It is always a question of the relative importance of the particular things with which he is concerned, and the causes which alter their relative importance are of no interest.

The price system solved it, and

We must look at the price system as such a mechanism for communicating information.

It is an effective communicating system because:

Only the most essential information is passed on and passed on only to those concerned.

It extends the span of our utilization of resources without the control of any one mind. Also, it will make the individuals do the desirable things without anyone having to tell them what to do.

Thoughts

It opened my mind to look at the price system differently. It is an effective way to watch the only the necessary and relevant information, and the messages are propagated rapidly in the system. It makes distributed decisions possible and outperforms central decision authorities in most cases.

Although distributed decisions can achieve local optimum, which may not be the global optimum. We human may also need some centralization to break the equilibrium by a trial and error like method.

References

Orbs - Read the Helix Consensus Algorithm White Paper

Hazel is a Byzantine fault-tolerant and scalable consensus algorithm for the fair ordering of transactions among nodes in a distributed network.

It assumed that:

  • Node-node connections are assumed to be strongly synchronous.
  • There is a known bound for the faulty nodes.

It is scalable because the PBFT committee size is bounded.

Helix archives fairness in these aspects.

  • Committee selection relies on reputation and a random seed.
  • Transactions are randomly selected when they are encrypted.

Both committee election and transactions sampling utilize a random seed derived from the previous decrypted block.

Helix nodes validate block transaction by checking the distribution overlap with local transaction pool.