Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mining: set minimum block weight to 5000, parse as configuration option #514

Merged
merged 4 commits into from
Nov 22, 2020

Conversation

pinheadmz
Copy link
Member

@pinheadmz pinheadmz commented Sep 16, 2020

Addresses #430 -- solution 1 & 2

(see also #515)

Goal

Prevent low- or no-fee transactions from being stuck in the mempool forever, by adjusting mining policy to occasionally include them.

This PR is mainly changing a constant in policy.js from a value that used to be 0:

/**
 * Minimum block size to create. Block will be
 * filled with free transactions until block
 * reaches this weight.
 * @const {Number}
 * @default
 */

exports.MIN_BLOCK_WEIGHT = 5000;

What this means is, in miner.js assemble() when a block is being put together to be hashed, if the current block template has a total weight under 5000, the miner will insert "free" transactions from the mempool (very low fee transactions).

One such TX might be this poor guy:

https://shakescan.com/transaction/a239970210b948d462adf8a07fb2e8bf9b301ba34942cb01b86eb96aeec2ad30

...that has been patiently pending for SIX MONTHS.

5000 weight units is tiny by the way. An "empty" block with just a coinbase is already 1308 weight.

I ran a few heuristics to determine how often a block with <5000 weight ever gets mined. Parsing blocks 2016-33054. (all data)

weight || count
   1000   2834
   2000   1391
   3000   1175
   4000   840
   5000   829
   6000   727
   7000   708
   8000   719
   9000   598
   10000  4361
   20000  2867
   30000  2128
   40000  1595
   50000  1206
   60000  979
   70000  848
   80000  724
   90000  628
   100000 502

and another test to see how big the average "gap" in blocks is between blocks of a certain weight:

wt.   || average gap
1000   10.942484121383204
2000   22.249640287769783
3000   26.313458262350938
4000   36.84642857142857
5000   37.39492753623188
6000   42.57575757575758
7000   43.74115983026874
8000   43.17941585535466
9000   51.88609715242881
10000   7.109736540664375
20000  10.815202231520223
30000  14.49906015037594
40000  19.337092731829575
50000  25.409958506224065
60000  31.163265306122447
70000  36.560802833530104
80000  42.881051175656985
90000  48.346092503987244
100000 60.439121756487026

So,

long story short - we can expect a block < 5000 weight a few times a day at the current network activity level. This means there is still very limited opportunities for a low-fee tx to get included in a block with this new policy rule. And when it happens, miners won't be sacrificing really anything.

Also,

miners can bypass this rule by launching with --min-weight=0 (or other value) which is now parsed by the full node.

@coveralls
Copy link

coveralls commented Sep 16, 2020

Pull Request Test Coverage Report for Build 259425278

  • 1 of 1 (100.0%) changed or added relevant line in 1 file are covered.
  • 3 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.002%) to 59.228%

Files with Coverage Reduction New Missed Lines %
lib/net/pool.js 1 32.63%
lib/net/peer.js 2 35.28%
Totals Coverage Status
Change from base Build 238010293: -0.002%
Covered Lines: 19387
Relevant Lines: 30471

💛 - Coveralls

@pinheadmz
Copy link
Member Author

To Review

One way to experiment with this patch is as follows:

export HSD_NETWORK=regtest

  • Start hsd with the "old policy": $ hsd --min-weight=0
  • In a second terminal, set tx fee very low (don't use 0 -- that has a special "reset" meaning): hsw-rpc settxfee 0.000001
  • Send a TX: hsw-rpc sendtoaddress $(hsw-rpc getnewaddress) 1.23456
  • Inspect the mempool:
$ hsd-cli mempool
[
  "f637b582c8c2cf952e5375d446239a0d23825c3f36296a21ad005a84053a5391"
]
  • Generate a block and inspect mempool again -- TX is still there!
$ hsd-rpc generatetoaddress 1 $(hsw-rpc getnewaddress)
[
  "39c9958d8ae464ea23d88275b564614812eca0b8a721f109ae55832fe90a20f3"
]
$ hsd-cli mempool
[
  "35497154a208a5c29dd6f1b17028dddac1616aad74cc07672973731009b044b0"
]
  • Restart hsd with new default policy (minWeight = 5000): $ hsd
  • Inspect mempool, mine block, inspect mempool again -- confirmed!!
$ hsd-cli mempool
[
  "35497154a208a5c29dd6f1b17028dddac1616aad74cc07672973731009b044b0"
]
$ hsd-rpc generatetoaddress 1 $(hsw-rpc getnewaddress)
[
  "5ccfa275513f4fab077454d9a6c4be6e4f94e07ec2d9c33d1d1d42b96e233d03"
]
$ hsd-cli mempool
[]

@chjj chjj merged commit 25173cf into handshake-org:master Nov 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants