Make it pay — Handling disappearing transaction in Ethereum

For a more friendly and fun onboard experience, we have introduced bonus system to like.co. Users get LikeCoin reward for completing various missions, e.g. watching the LikeCoin introduction video, joining one of our communities, etc.

Click here to signup if you are not yet onboard!

like.co bonus system in action

Running a system like this involves sending many small transactions through the Ethereum network. To keep the cost low, we have to achieve the following goals:

1. Merge those transactions with the same “to-address” into single batches

2. Send them with a low gas price, since speed is not an important factor here

3. Notify the users when they receive the LikeCoin (after the transaction is completed on the network)

Transaction disappearing

Things went smoothly when we were on test net. However once we get onto main net, things were different: many of our transactions sent were disappearing and (sometimes) reappearing mysteriously.

It turns out that when the current gas price is too high, transactions with low gas price will get stuck in txpool, since no miner is willing to process it just yet. Gas price in the Ethereum network fluctuates a lot, it gets very high when there is a big ICO launch; but could also be quite low when everyone is sleeping.

Theoretically, after the gas price fall back, the sent transactions will automatically be mined, without any extra work. In Practice however, low gas transactions tend to got dropped out of txpool due to memory limit. It is very possible that our transaction was already dropped after a long time. Therefore we need to remind the network to handle our transactions after the gas price drops.

Pray, then try again later

To solve the problem and achieve our goals, we have created two microservices. Both solution is based on Firebase Firestore as data storage, and is open sourced on Github.

Transaction completed notification email

Prayer is in charge of batching transactions in a time interval, and sending them to Ethereum network through Infura. The name prayer comes from the fact that we are passively hoping for miners’ to do the work, andlikecoin-payer doesn’t sounds like a good name after all.

Tx-poll has two functions that is configurable when deploy. First it can act as an Ethereum transaction status tracker, which updates transaction states when it fails or completes. We then send notifications to our users accordingly.

On the other hand, it also support retrying a transaction, when it is not found in the Ethereum network. By retrying only the first few transactions in a relatively long interval, we can do this without heavily increasing INFURA’s workload. Actually it is pointless to retry too frequently: since Ethereum account nonce works in a strictly increasing way, every transactions in the same account will always be blocked by the earliest un-processed transaction.

Automated retrying transaction seems to be a generic useful case, especially for sending non-time-critical transactions with low cost. We are looking into expanding these microservices to not only support Firestore, but different kinds of database/storage backend, so it can fit in more scenarios.

Next episode (probably)

Now that we have mentionednonce, it is in fact quite a trouble to tackle with,kik engineer wrote an related article on this topic before.

In LikeCoin, we have a mechanism to work around (or rather,

work with) this restriction. We will be writing another article soon, sharing our solutions. Stay tuned!

Give me some LIKEs if you like this article!

以下方式关注我们

官网:https://like.co/

Medium:medium.com/likecoin/zh/

Facebook:fb.com/LikeCoin.Foundation,fb.com/groups/likecoin

电报群:t.me/likecoin

Twitter:twitter.com/likecoin_fdn

Youtube:youtube.com/c/LikeCoin

Github:github.com/likecoin

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 8,116评论 0赞 10
  • 今天忘记记了,也忘记发生了啥了……
    安星阅读 247评论 0赞 0
  • 图1:婚姻 婚姻就如这幅画,无论谁放手,受伤的都是孩子!多经典的话,多牛的配图。 所以从你选择了婚姻有了孩子那一...
    向钱钱阅读 1,942评论 0赞 0
  • 昨天晚上10点半,孩子说,有些累想先睡10分钟,再起来写作业,10分钟以后,我却怎么也叫不醒她,她睡得好沉,看...
    定静慧心阅读 288评论 2赞 5

友情链接更多精彩内容