From 1db62a07c5a70fddc616a0f9bbabf02201a3a56b Mon Sep 17 00:00:00 2001 From: Jeremy Rubin Date: Thu, 23 Jan 2020 16:51:50 -0800 Subject: Assign CTV BIP #119 --- bip-0119/fifty.png | Bin 0 -> 372887 bytes bip-0119/five.png | Bin 0 -> 324707 bytes bip-0119/nic.svg | 1 + bip-0119/pooledcoshv.png | Bin 0 -> 255491 bytes bip-0119/simulation.py | 133 +++++++++++++++++++++++++++++++++++++++++++++++ bip-0119/states.svg | 1 + bip-0119/vaults.svg | 1 + 7 files changed, 136 insertions(+) create mode 100644 bip-0119/fifty.png create mode 100644 bip-0119/five.png create mode 100644 bip-0119/nic.svg create mode 100644 bip-0119/pooledcoshv.png create mode 100755 bip-0119/simulation.py create mode 100644 bip-0119/states.svg create mode 100644 bip-0119/vaults.svg (limited to 'bip-0119') diff --git a/bip-0119/fifty.png b/bip-0119/fifty.png new file mode 100644 index 0000000..6917937 Binary files /dev/null and b/bip-0119/fifty.png differ diff --git a/bip-0119/five.png b/bip-0119/five.png new file mode 100644 index 0000000..5cf741a Binary files /dev/null and b/bip-0119/five.png differ diff --git a/bip-0119/nic.svg b/bip-0119/nic.svg new file mode 100644 index 0000000..ae6fb3c --- /dev/null +++ b/bip-0119/nic.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/bip-0119/pooledcoshv.png b/bip-0119/pooledcoshv.png new file mode 100644 index 0000000..c9ea9d1 Binary files /dev/null and b/bip-0119/pooledcoshv.png differ diff --git a/bip-0119/simulation.py b/bip-0119/simulation.py new file mode 100755 index 0000000..ee06fee --- /dev/null +++ b/bip-0119/simulation.py @@ -0,0 +1,133 @@ +#!/usr/bin/python3 +import numpy as np +import matplotlib.pyplot as plt +PHASES = 15 +PHASE_LENGTH = 144 +SAMPLES = PHASE_LENGTH * PHASES +AVG_TX = 235 +COMPRESSED_NODE_SIZE = 4 + 1 + 1 + 4 + 32 + 4 + 4 + 8 + 8 + 34 + 34 + 33 + 32 + 34 +print(COMPRESSED_NODE_SIZE) +MAX_BLOCK_SIZE = 1e6 +AVG_INTERVAL = 10*60 +TXNS_PER_SEC = 0.5*MAX_BLOCK_SIZE/AVG_TX/AVG_INTERVAL +MAX_MEMPOOL = MAX_BLOCK_SIZE * 100 +COMPRESSABLE = 0.05 + + + + + +def get_rate(phase): + if phase > PHASES/3: + return 1.25**(2*PHASES/3 - phase) *TXNS_PER_SEC + else: + return 1.25**(phase)*TXNS_PER_SEC + +def normal(): + print("Max Txns Per Sec %f"%TXNS_PER_SEC) + backlog = 0 + results_unconfirmed = [0]*SAMPLES + total_time = [0]*SAMPLES + for phase in range(PHASES): + for i in range(PHASE_LENGTH*phase, PHASE_LENGTH*(1+phase)): + block_time = np.random.exponential(AVG_INTERVAL) + total_time[i] = block_time + # Equivalent to the sum of one poisson per block time + # I.E., \sum_1_n Pois(a) = Pois(a*n) + txns = np.random.poisson(get_rate(phase)* block_time) + weight = txns*AVG_TX + backlog + if weight > MAX_BLOCK_SIZE: + backlog = weight - MAX_BLOCK_SIZE + else: + backlog = 0 + results_unconfirmed[i] = backlog/AVG_TX + return results_unconfirmed, np.cumsum(total_time)/(60*60*24.0) +def compressed(rate_multiplier = 1): + print("Max Txns Per Sec %f"%TXNS_PER_SEC) + backlog = 0 + secondary_backlog = 0 + results = [0]*SAMPLES + results_lo_priority = [0]*SAMPLES + results_confirmed = [0]*SAMPLES + results_unconfirmed = [0]*SAMPLES + results_yet_to_spend = [0]*SAMPLES + total_time = [0]*(SAMPLES) + for phase in range(PHASES): + for i in range(PHASE_LENGTH*phase, PHASE_LENGTH*(1+phase)): + block_time = np.random.poisson(AVG_INTERVAL) + total_time[i] = block_time + txns = np.random.poisson(rate_multiplier*get_rate(phase)*block_time) + postponed = txns * COMPRESSABLE + weight = (txns-postponed)*AVG_TX + backlog + secondary_backlog += postponed*133 + postponed*34 # Total extra work + if weight > MAX_BLOCK_SIZE: + results_confirmed[i] += MAX_BLOCK_SIZE - AVG_TX + backlog = weight - MAX_BLOCK_SIZE + else: + space = MAX_BLOCK_SIZE - weight + secondary_backlog = max(secondary_backlog-space, 0) + backlog = 0 + results_unconfirmed[i] = float(backlog)/AVG_TX + results_yet_to_spend[i] = secondary_backlog/2/AVG_TX + + return results_unconfirmed, results_yet_to_spend, np.cumsum(total_time)/(60*60*24.0) + +DAYS = np.array(range(SAMPLES))/144 + +def make_patch_spines_invisible(ax): + ax.set_frame_on(True) + ax.patch.set_visible(False) + for sp in ax.spines.values(): + sp.set_visible(False) + +if __name__ == "__main__": + normal_txs, blocktimes_n = normal() + compressed_txs, unspendable, blocktimes_c1 = compressed() + compressed_txs2, unspendable2, blocktimes_c2 = compressed(2) + + fig, host = plt.subplots() + host.set_title("Transaction Compression Performance with %d%% Adoption During Spike"%(100*COMPRESSABLE)) + fig.subplots_adjust(right=0.75) + par1 = host.twinx() + par2 = host.twinx() + par3 = host.twinx() + + par2.spines["right"].set_position(("axes", 1.2)) + make_patch_spines_invisible(par2) + par2.spines["right"].set_visible(True) + + par3.spines["right"].set_position(("axes", 1.4)) + make_patch_spines_invisible(par3) + par3.spines["right"].set_visible(True) + + host.set_xlabel("Block Days") + + host.set_ylabel("Transactions per Second") + p5, = host.plot(range(PHASES), [get_rate(p) for p in range(PHASES)], "k-", label="Transactions Per Second (1x Rate)") + p6, = host.plot(range(PHASES), [2*get_rate(p) for p in range(PHASES)], "k:", label="Transactions Per Second (2x Rate)") + + host.yaxis.label.set_color(p5.get_color()) + + + par2.set_ylabel("Unconfirmed Transactions") + #p1, = par2.plot(DAYS, (-np.array(compressed_txs) + np.array(normal_txs)), "b-.", label = "Mempool Delta") + p1, = par2.plot(blocktimes_n, normal_txs, "g", label="Mempool without Congestion Control") + p2, = par2.plot(blocktimes_c1, compressed_txs,"y", label="Mempool with Congestion Control (1x Rate)") + p3, = par2.plot(blocktimes_c2, compressed_txs2,"m", label="Mempool with Congestion Control (2x Rate)") + p_full_block, = par2.plot([DAYS[0], DAYS[-1]], [MAX_BLOCK_SIZE/AVG_TX]*2, "b.-", label="Maximum Average Transactions Per Block") + + par2.yaxis.label.set_color(p2.get_color()) + + + par1.set_ylabel("Confirmed but Pending Transactions") + p4, = par1.plot(blocktimes_c1, unspendable2, "c", label="Congestion Control Pending (2x Rate)") + p4, = par1.plot(blocktimes_c2, unspendable, "r", label="Congestion Control Pending (1x Rate)") + par1.yaxis.label.set_color(p4.get_color()) + + + + + lines = [p1, p2, p3, p4, p5, p6, p_full_block] + host.legend(lines, [l.get_label() for l in lines]) + + plt.show() diff --git a/bip-0119/states.svg b/bip-0119/states.svg new file mode 100644 index 0000000..1ef108e --- /dev/null +++ b/bip-0119/states.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/bip-0119/vaults.svg b/bip-0119/vaults.svg new file mode 100644 index 0000000..9c69087 --- /dev/null +++ b/bip-0119/vaults.svg @@ -0,0 +1 @@ + \ No newline at end of file -- cgit v1.2.3