Skip to content

Instantly share code, notes, and snippets.

@protolambda
Last active May 4, 2019 19:14
Show Gist options
  • Save protolambda/23cc276b8562c811b3e36b21676a8ef6 to your computer and use it in GitHub Desktop.
Save protolambda/23cc276b8562c811b3e36b21676a8ef6 to your computer and use it in GitHub Desktop.

Some test runs on LMD-GHOST

Based on https://github.com/protolambda/lmd-ghost/

Simulation config:

	config := &sim.SimConfig{
		ValidatorCount: 40000,
		LatencyFactor: 0.8,
		SlotSkipChance: 0.3,
		BaseAttestWeight: 100,
		MaxExtraAttestWeight: 10,
		Blocks: 10000,
		AttestationsPerBlock: 1000,
		JustifyEpochsAgo: 7,
		FinalizeEpochsAgo: 10,
		ForkChoiceRule: "<fill in>",
	}

Notes:

  • results between fork-choice rules are not exactly the same, but similar: sometimes there's no "best" option; two (or more) options have equal attesting weight. In this case you can choose any. The simulation creates new blocks based on this choice, so from this point on the blocks created by the RNG may be different.
  • Different algorithms perform better in different scenarios. With tweaks to the config, there may be another winning algorithm. Do note that some algorithms are more useful than others:
    • stateful algorithms provide the fork-choice head of any block in the DAG.
    • some algorithms are easier to manage and prune than others. Caches are troublesome sometimes. State may also not fit.

"Winner" (imho): proto_array does well for several reasons:

  • you can look-up the head for any node in the graph in O(1)
  • pruning triggering is easy: gh.indices[gh.dag.Finalized] > X, with X being the amount of nodes you want to keep around, while not using them.
    • Note: you can do more heavy pruning by not exploiting the sequential property of the nodes (aka insertion time), and go further: remove nodes that are inserted later than the finalized node, but not connected to this finalized node. However, this is more complex, and does not win you much, if any at all.
  • it is fast
  • it is completely stateful, but low on memory (just 4 arrays of integers for state, plus normal node bookkeeping).
  • it is very open to extend on: you do not strictly need a second DAG structure, you can use these arrays as DAG. My guess is that fork-choice simulation time of 10000 blocks could be cut by 50% if you remove the overhead+memory of the full pointer & slice based DAG.
2019/05/04 19:48:37 Start: v40000_lf0_800000_sc0_300000_bw100_ew10_bl10000_atpb1000_fork-proto_array
2019/05/04 19:48:37 total 0 blocks added, 1 blocks in dag, head at slot: 0, processed 0 attestations.
2019/05/04 19:48:37 total 500 blocks added, 501 blocks in dag, head at slot: 216, processed 500000 attestations.
2019/05/04 19:48:37 total 1000 blocks added, 1001 blocks in dag, head at slot: 449, processed 1000000 attestations.
2019/05/04 19:48:38 total 1500 blocks added, 1501 blocks in dag, head at slot: 661, processed 1500000 attestations.
2019/05/04 19:48:39 total 2000 blocks added, 1391 blocks in dag, head at slot: 879, processed 2000000 attestations.
2019/05/04 19:48:39 total 2500 blocks added, 1373 blocks in dag, head at slot: 1089, processed 2500000 attestations.
2019/05/04 19:48:40 total 3000 blocks added, 1389 blocks in dag, head at slot: 1288, processed 3000000 attestations.
2019/05/04 19:48:41 total 3500 blocks added, 1457 blocks in dag, head at slot: 1502, processed 3500000 attestations.
2019/05/04 19:48:42 total 4000 blocks added, 1496 blocks in dag, head at slot: 1724, processed 4000000 attestations.
2019/05/04 19:48:43 total 4500 blocks added, 1520 blocks in dag, head at slot: 1917, processed 4500000 attestations.
2019/05/04 19:48:43 total 5000 blocks added, 1428 blocks in dag, head at slot: 2132, processed 5000000 attestations.
2019/05/04 19:48:44 total 5500 blocks added, 1485 blocks in dag, head at slot: 2346, processed 5500000 attestations.
2019/05/04 19:48:45 total 6000 blocks added, 1330 blocks in dag, head at slot: 2573, processed 6000000 attestations.
2019/05/04 19:48:46 total 6500 blocks added, 1410 blocks in dag, head at slot: 2781, processed 6500000 attestations.
2019/05/04 19:48:48 total 7000 blocks added, 1456 blocks in dag, head at slot: 2991, processed 7000000 attestations.
2019/05/04 19:48:49 total 7500 blocks added, 1366 blocks in dag, head at slot: 3224, processed 7500000 attestations.
2019/05/04 19:48:51 total 8000 blocks added, 1283 blocks in dag, head at slot: 3469, processed 8000000 attestations.
2019/05/04 19:48:52 total 8500 blocks added, 1298 blocks in dag, head at slot: 3696, processed 8500000 attestations.
2019/05/04 19:48:53 total 9000 blocks added, 1426 blocks in dag, head at slot: 3887, processed 9000000 attestations.
2019/05/04 19:48:54 total 9500 blocks added, 1530 blocks in dag, head at slot: 4092, processed 9500000 attestations.
2019/05/04 19:48:56 total 10000 blocks added, 1465 blocks in dag, head at slot: 4328, processed 10000000 attestations.
2019/05/04 19:48:56 End: v40000_lf0_800000_sc0_300000_bw100_ew10_bl10000_atpb1000_fork-proto_array took 18.914421155s
2019/05/04 18:11:31 Start: v40000_lf0_800000_sc0_300000_bw100_ew10_bl10000_atpb1000_fork-simple_back_prop
2019/05/04 18:11:31 total 0 blocks added, 1 blocks in dag, head at slot: 0, processed 0 attestations.
2019/05/04 18:11:32 total 500 blocks added, 501 blocks in dag, head at slot: 203, processed 500000 attestations.
2019/05/04 18:11:33 total 1000 blocks added, 1001 blocks in dag, head at slot: 400, processed 1000000 attestations.
2019/05/04 18:11:34 total 1500 blocks added, 1501 blocks in dag, head at slot: 634, processed 1500000 attestations.
2019/05/04 18:11:34 total 2000 blocks added, 1333 blocks in dag, head at slot: 877, processed 2000000 attestations.
2019/05/04 18:11:35 total 2500 blocks added, 1364 blocks in dag, head at slot: 1080, processed 2500000 attestations.
2019/05/04 18:11:36 total 3000 blocks added, 1359 blocks in dag, head at slot: 1313, processed 3000000 attestations.
2019/05/04 18:11:38 total 3500 blocks added, 1305 blocks in dag, head at slot: 1546, processed 3500000 attestations.
2019/05/04 18:11:39 total 4000 blocks added, 1364 blocks in dag, head at slot: 1742, processed 4000000 attestations.
2019/05/04 18:11:40 total 4500 blocks added, 1442 blocks in dag, head at slot: 1948, processed 4500000 attestations.
2019/05/04 18:11:41 total 5000 blocks added, 1349 blocks in dag, head at slot: 2194, processed 5000000 attestations.
2019/05/04 18:11:43 total 5500 blocks added, 1384 blocks in dag, head at slot: 2392, processed 5500000 attestations.
2019/05/04 18:11:44 total 6000 blocks added, 1417 blocks in dag, head at slot: 2615, processed 6000000 attestations.
2019/05/04 18:11:45 total 6500 blocks added, 1359 blocks in dag, head at slot: 2832, processed 6500000 attestations.
2019/05/04 18:11:47 total 7000 blocks added, 1403 blocks in dag, head at slot: 3038, processed 7000000 attestations.
2019/05/04 18:11:49 total 7500 blocks added, 1334 blocks in dag, head at slot: 3274, processed 7500000 attestations.
2019/05/04 18:11:51 total 8000 blocks added, 1359 blocks in dag, head at slot: 3501, processed 8000000 attestations.
2019/05/04 18:11:52 total 8500 blocks added, 1425 blocks in dag, head at slot: 3711, processed 8500000 attestations.
2019/05/04 18:11:54 total 9000 blocks added, 1404 blocks in dag, head at slot: 3904, processed 9000000 attestations.
2019/05/04 18:11:55 total 9500 blocks added, 1457 blocks in dag, head at slot: 4156, processed 9500000 attestations.
2019/05/04 18:11:57 total 10000 blocks added, 1345 blocks in dag, head at slot: 4404, processed 10000000 attestations.
2019/05/04 18:11:57 End: v40000_lf0_800000_sc0_300000_bw100_ew10_bl10000_atpb1000_fork-simple_back_prop took 25.506930879s
2019/05/04 18:10:21 Start: v40000_lf0_800000_sc0_300000_bw100_ew10_bl10000_atpb1000_fork-stateful
2019/05/04 18:10:21 total 0 blocks added, 1 blocks in dag, head at slot: 0, processed 0 attestations.
2019/05/04 18:10:22 total 500 blocks added, 501 blocks in dag, head at slot: 216, processed 500000 attestations.
2019/05/04 18:10:22 total 1000 blocks added, 1001 blocks in dag, head at slot: 423, processed 1000000 attestations.
2019/05/04 18:10:24 total 1500 blocks added, 1501 blocks in dag, head at slot: 647, processed 1500000 attestations.
2019/05/04 18:10:25 total 2000 blocks added, 1391 blocks in dag, head at slot: 874, processed 2000000 attestations.
2019/05/04 18:10:27 total 2500 blocks added, 1296 blocks in dag, head at slot: 1094, processed 2500000 attestations.
2019/05/04 18:10:28 total 3000 blocks added, 1379 blocks in dag, head at slot: 1317, processed 3000000 attestations.
2019/05/04 18:10:30 total 3500 blocks added, 1324 blocks in dag, head at slot: 1554, processed 3500000 attestations.
2019/05/04 18:10:31 total 4000 blocks added, 1200 blocks in dag, head at slot: 1798, processed 4000000 attestations.
2019/05/04 18:10:33 total 4500 blocks added, 1175 blocks in dag, head at slot: 2061, processed 4500000 attestations.
2019/05/04 18:10:35 total 5000 blocks added, 1233 blocks in dag, head at slot: 2296, processed 5000000 attestations.
2019/05/04 18:10:36 total 5500 blocks added, 1253 blocks in dag, head at slot: 2551, processed 5500000 attestations.
2019/05/04 18:10:38 total 6000 blocks added, 1262 blocks in dag, head at slot: 2756, processed 6000000 attestations.
2019/05/04 18:10:40 total 6500 blocks added, 1357 blocks in dag, head at slot: 2988, processed 6500000 attestations.
2019/05/04 18:10:42 total 7000 blocks added, 1333 blocks in dag, head at slot: 3232, processed 7000000 attestations.
2019/05/04 18:10:45 total 7500 blocks added, 1340 blocks in dag, head at slot: 3425, processed 7500000 attestations.
2019/05/04 18:10:47 total 8000 blocks added, 1456 blocks in dag, head at slot: 3637, processed 8000000 attestations.
2019/05/04 18:10:49 total 8500 blocks added, 1425 blocks in dag, head at slot: 3854, processed 8500000 attestations.
2019/05/04 18:10:51 total 9000 blocks added, 1256 blocks in dag, head at slot: 4111, processed 9000000 attestations.
2019/05/04 18:10:53 total 9500 blocks added, 1337 blocks in dag, head at slot: 4351, processed 9500000 attestations.
2019/05/04 18:10:55 total 10000 blocks added, 1286 blocks in dag, head at slot: 4588, processed 10000000 attestations.
2019/05/04 18:10:55 End: v40000_lf0_800000_sc0_300000_bw100_ew10_bl10000_atpb1000_fork-stateful took 34.119842855s
2019/05/04 18:09:01 Start: v40000_lf0_800000_sc0_300000_bw100_ew10_bl10000_atpb1000_fork-vitalik
2019/05/04 18:09:01 total 0 blocks added, 1 blocks in dag, head at slot: 0, processed 0 attestations.
2019/05/04 18:09:02 total 500 blocks added, 501 blocks in dag, head at slot: 216, processed 500000 attestations.
2019/05/04 18:09:04 total 1000 blocks added, 1001 blocks in dag, head at slot: 449, processed 1000000 attestations.
2019/05/04 18:09:07 total 1500 blocks added, 1501 blocks in dag, head at slot: 661, processed 1500000 attestations.
2019/05/04 18:09:09 total 2000 blocks added, 1391 blocks in dag, head at slot: 699, processed 2000000 attestations.
2019/05/04 18:09:12 total 2500 blocks added, 1609 blocks in dag, head at slot: 913, processed 2500000 attestations.
2019/05/04 18:09:14 total 3000 blocks added, 1873 blocks in dag, head at slot: 1117, processed 3000000 attestations.
2019/05/04 18:09:18 total 3500 blocks added, 1858 blocks in dag, head at slot: 1322, processed 3500000 attestations.
2019/05/04 18:09:21 total 4000 blocks added, 1646 blocks in dag, head at slot: 1535, processed 4000000 attestations.
2019/05/04 18:09:24 total 4500 blocks added, 1578 blocks in dag, head at slot: 1547, processed 4500000 attestations.
2019/05/04 18:09:27 total 5000 blocks added, 1708 blocks in dag, head at slot: 1793, processed 5000000 attestations.
2019/05/04 18:09:29 total 5500 blocks added, 2090 blocks in dag, head at slot: 1867, processed 5500000 attestations.
2019/05/04 18:09:34 total 6000 blocks added, 2083 blocks in dag, head at slot: 2087, processed 6000000 attestations.
2019/05/04 18:09:37 total 6500 blocks added, 2006 blocks in dag, head at slot: 2236, processed 6500000 attestations.
2019/05/04 18:09:39 total 7000 blocks added, 2126 blocks in dag, head at slot: 2316, processed 7000000 attestations.
2019/05/04 18:09:43 total 7500 blocks added, 1949 blocks in dag, head at slot: 2530, processed 7500000 attestations.
2019/05/04 18:09:45 total 8000 blocks added, 2257 blocks in dag, head at slot: 2615, processed 8000000 attestations.
2019/05/04 18:09:48 total 8500 blocks added, 1673 blocks in dag, head at slot: 2852, processed 8500000 attestations.
2019/05/04 18:09:50 total 9000 blocks added, 1728 blocks in dag, head at slot: 2890, processed 9000000 attestations.
2019/05/04 18:09:53 total 9500 blocks added, 1333 blocks in dag, head at slot: 3284, processed 9500000 attestations.
2019/05/04 18:09:55 total 10000 blocks added, 1452 blocks in dag, head at slot: 3502, processed 10000000 attestations.
2019/05/04 18:09:55 End: v40000_lf0_800000_sc0_300000_bw100_ew10_bl10000_atpb1000_fork-vitalik took 54.405082002s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment