.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/consensus/agreement/plot_04_partial_synchrony.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code or to run this example in your browser via JupyterLite. .. rst-class:: sphx-glr-example-title .. _sphx_glr_api_gallery_consensus_agreement_plot_04_partial_synchrony.py: Partial synchrony: timeouts that eventually work (Dwork, Lynch and Stockmeyer 1988) =================================================================================== Real networks are usually fast but sometimes not. Dwork, Lynch and Stockmeyer modelled this as partial synchrony: message delays are unbounded until an unknown Global Stabilization Time (GST), and bounded by an unknown Delta afterwards. A leader-based protocol keeps safety at all times and waits out each leader with a timeout. Doubling the timeout every failed view guarantees it eventually exceeds Delta, whatever Delta is. What to look for ---------------- Views fail until GST; the first view that starts after GST with a long enough timeout makes progress. With a fixed timeout below Delta, no view ever succeeds. PBFT, Tendermint and HotStuff all rely on this model. The history behind this experiment: :doc:`/history/consensus_breakthroughs`. .. GENERATED FROM PYTHON SOURCE LINES 23-25 Views before and after GST -------------------------- .. GENERATED FROM PYTHON SOURCE LINES 25-38 .. code-block:: Python import matplotlib.pyplot as plt import blockchainkit as bk run = bk.consensus.view_changes(gst=300, delta=40, base_timeout=5) print(f"view {run.decided_view} decides at t = {run.decision_time}") assert run.view_starts[run.decided_view] >= 300 and run.timeouts[run.decided_view] >= 40 try: bk.consensus.view_changes(gst=0, delta=40, base_timeout=5, growth=1, max_views=100) except TimeoutError: print("fixed 5-tick timeouts never outlast a 40-tick delay") .. rst-class:: sphx-glr-script-out .. code-block:: none view 6 decides at t = 355 fixed 5-tick timeouts never outlast a 40-tick delay .. GENERATED FROM PYTHON SOURCE LINES 39-41 Progress time grows only linearly with GST ------------------------------------------ .. GENERATED FROM PYTHON SOURCE LINES 41-55 .. code-block:: Python gsts = list(range(0, 2001, 100)) decisions = [bk.consensus.view_changes(gst=g, delta=40, base_timeout=5).decision_time for g in gsts] assert all(d >= g for d, g in zip(decisions, gsts, strict=True)) fig, ax = plt.subplots(figsize=(7, 4)) ax.plot(gsts, decisions, "o-", label="decision time") ax.plot(gsts, gsts, "--", color="black", label="GST") ax.set( xlabel="global stabilization time", ylabel="time", title="Doubling timeouts: progress soon after GST", ) ax.legend() fig.tight_layout() .. image-sg:: /api/gallery/consensus/agreement/images/sphx_glr_plot_04_partial_synchrony_001.png :alt: Doubling timeouts: progress soon after GST :srcset: /api/gallery/consensus/agreement/images/sphx_glr_plot_04_partial_synchrony_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 56-61 Exercise -------- Doubling can overshoot: after a long asynchronous period the timeout may be far larger than Delta. What does that cost after GST, and why do some protocols reset the timeout after a successful view? .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.154 seconds) .. _sphx_glr_download_api_gallery_consensus_agreement_plot_04_partial_synchrony.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: lite-badge .. image:: images/jupyterlite_badge_logo.svg :target: ../../../../lite/lab/index.html?path=api/gallery/consensus/agreement/plot_04_partial_synchrony.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_04_partial_synchrony.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_04_partial_synchrony.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_04_partial_synchrony.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_