mirror of https://github.com/logos-co/scratch.git
committee simulations notebook, gitignore file
This commit is contained in:
parent
7c765b5442
commit
dc4b092553
|
@ -0,0 +1 @@
|
||||||
|
.ipynb_checkpoints
|
|
@ -0,0 +1,270 @@
|
||||||
|
{
|
||||||
|
"cells": [
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 1,
|
||||||
|
"id": "b01c279a-cd3f-4e6f-a7ba-fca8d1f42804",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"import random\n",
|
||||||
|
"import pandas as pd"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"id": "53cc43b6-051f-43fb-8195-6a753ab74cf1",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"LogosBFT works by partitioning the nodes into equally-sized committees, then forming a binary tree structure from those committees. A primary (or leader) then partitions the propposed data to be verified via erasure coding techniques (fountain or raptor codes) and distributes it through the tree.\n",
|
||||||
|
"\n",
|
||||||
|
"This notebook is an attempt to simulate various structures and their respective consequences w.r.t. bandwidth, byzantine behavior, latency, etc. \n",
|
||||||
|
"\n",
|
||||||
|
"The general process can be described by the following:\n",
|
||||||
|
"- Get Random Seed (Blackboxed here)\n",
|
||||||
|
"- Form Overlay\n",
|
||||||
|
" - Initial Committee Assignment\n",
|
||||||
|
" - Overlay Tree Structure Formation\n",
|
||||||
|
" - Parent <--> Child Assignment\n",
|
||||||
|
"- Leader Selection (Blackboxed here)\n",
|
||||||
|
"- Leader Forms Block Proposal (Blackboxed here)\n",
|
||||||
|
"- Proposal Erasure Coding\n",
|
||||||
|
"- Data Dissemination\n",
|
||||||
|
"- Each Committee Forms Block Independently\n",
|
||||||
|
"\n",
|
||||||
|
"We'd like to track the following metrics:\n",
|
||||||
|
"- total bandwidth for an individual node\n",
|
||||||
|
"- total num of messages for an individual node\n",
|
||||||
|
"- latency of block distribution throughout the network"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"id": "2b3761fe-d4dc-438f-8cdb-dbfafeb3b6e5",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"## Globals definitions"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 2,
|
||||||
|
"id": "4da35087-f815-4b88-99f8-04890b839beb",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"num_nodes = 1000\n",
|
||||||
|
"committee_size = 50\n",
|
||||||
|
"num_committees = num_nodes / committee_size\n",
|
||||||
|
"byzantine_coeff = 0.15\n",
|
||||||
|
"max_time_delay = 60 # seconds\n",
|
||||||
|
"block_size = 1 # MB"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"id": "e1238929-cbe8-4f80-90c0-5823c6a5ddf6",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"# Form overlay\n",
|
||||||
|
"\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"id": "14c20750-375a-410d-aa2b-1b97e17c2ef8",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"## Initial Committee Assignment"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 15,
|
||||||
|
"id": "0bec3377-a302-4bbd-bcfc-3e9c40af51bb",
|
||||||
|
"metadata": {
|
||||||
|
"tags": []
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"def chunks(l, n):\n",
|
||||||
|
" \"\"\"Yield successive n-sized chunks from l.\"\"\"\n",
|
||||||
|
" for i in range(0, len(l), n):\n",
|
||||||
|
" yield l[i:i + n]\n",
|
||||||
|
"\n",
|
||||||
|
"random_node_list = [i for i in range(num_nodes)]\n",
|
||||||
|
"random.shuffle(random_node_list)\n",
|
||||||
|
"\n",
|
||||||
|
"committee_list = list(chunks(random_node_list, committee_size))"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 29,
|
||||||
|
"id": "e5917cca-9c2b-423d-b930-6fddfcdea47e",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/html": [
|
||||||
|
"<div>\n",
|
||||||
|
"<style scoped>\n",
|
||||||
|
" .dataframe tbody tr th:only-of-type {\n",
|
||||||
|
" vertical-align: middle;\n",
|
||||||
|
" }\n",
|
||||||
|
"\n",
|
||||||
|
" .dataframe tbody tr th {\n",
|
||||||
|
" vertical-align: top;\n",
|
||||||
|
" }\n",
|
||||||
|
"\n",
|
||||||
|
" .dataframe thead th {\n",
|
||||||
|
" text-align: right;\n",
|
||||||
|
" }\n",
|
||||||
|
"</style>\n",
|
||||||
|
"<table border=\"1\" class=\"dataframe\">\n",
|
||||||
|
" <thead>\n",
|
||||||
|
" <tr style=\"text-align: right;\">\n",
|
||||||
|
" <th></th>\n",
|
||||||
|
" <th>committee_ind</th>\n",
|
||||||
|
" <th>committee_members</th>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" </thead>\n",
|
||||||
|
" <tbody>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>0</th>\n",
|
||||||
|
" <td>0</td>\n",
|
||||||
|
" <td>[506, 929, 199, 437, 427, 686, 861, 597, 81, 5...</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>1</th>\n",
|
||||||
|
" <td>1</td>\n",
|
||||||
|
" <td>[677, 491, 334, 209, 41, 121, 697, 943, 504, 6...</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>2</th>\n",
|
||||||
|
" <td>2</td>\n",
|
||||||
|
" <td>[439, 996, 238, 574, 388, 12, 956, 330, 386, 3...</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>3</th>\n",
|
||||||
|
" <td>3</td>\n",
|
||||||
|
" <td>[817, 370, 626, 151, 562, 539, 797, 270, 791, ...</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>4</th>\n",
|
||||||
|
" <td>4</td>\n",
|
||||||
|
" <td>[288, 693, 282, 348, 777, 671, 545, 222, 477, ...</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" </tbody>\n",
|
||||||
|
"</table>\n",
|
||||||
|
"</div>"
|
||||||
|
],
|
||||||
|
"text/plain": [
|
||||||
|
" committee_ind committee_members\n",
|
||||||
|
"0 0 [506, 929, 199, 437, 427, 686, 861, 597, 81, 5...\n",
|
||||||
|
"1 1 [677, 491, 334, 209, 41, 121, 697, 943, 504, 6...\n",
|
||||||
|
"2 2 [439, 996, 238, 574, 388, 12, 956, 330, 386, 3...\n",
|
||||||
|
"3 3 [817, 370, 626, 151, 562, 539, 797, 270, 791, ...\n",
|
||||||
|
"4 4 [288, 693, 282, 348, 777, 671, 545, 222, 477, ..."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 29,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"# Create DataFrame of committee assignments and their index\n",
|
||||||
|
"committee_df = pd.DataFrame(\n",
|
||||||
|
" [{\"committee_ind\": ind, \n",
|
||||||
|
" \"committee_members\": committee}\n",
|
||||||
|
" for ind, committee in enumerate(committee_list)])\n",
|
||||||
|
"committee_df.head()"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 30,
|
||||||
|
"id": "903154d0-9cc0-4e96-9c07-6fba378eb063",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"50\n",
|
||||||
|
"50\n",
|
||||||
|
"50\n",
|
||||||
|
"50\n",
|
||||||
|
"50\n",
|
||||||
|
"50\n",
|
||||||
|
"50\n",
|
||||||
|
"50\n",
|
||||||
|
"50\n",
|
||||||
|
"50\n",
|
||||||
|
"50\n",
|
||||||
|
"50\n",
|
||||||
|
"50\n",
|
||||||
|
"50\n",
|
||||||
|
"50\n",
|
||||||
|
"50\n",
|
||||||
|
"50\n",
|
||||||
|
"50\n",
|
||||||
|
"50\n",
|
||||||
|
"50\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"# Sanity check that all buckets are the same (or close) in size\n",
|
||||||
|
"for committee in committee_df[\"committee_members\"].values:\n",
|
||||||
|
" print(len(committee))"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"id": "d3a9986e-7720-43b2-94fb-b4c6b8b43a05",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"## Form Overlay Tree Structure"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"id": "b10a466b-f2d5-4a8f-9572-b2ca2ada520d",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"## Parent <> Child Assignment"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"id": "68de5fdc-0900-4e95-b2d0-57e5c98cb30c",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"metadata": {
|
||||||
|
"kernelspec": {
|
||||||
|
"display_name": "Python 3 (ipykernel)",
|
||||||
|
"language": "python",
|
||||||
|
"name": "python3"
|
||||||
|
},
|
||||||
|
"language_info": {
|
||||||
|
"codemirror_mode": {
|
||||||
|
"name": "ipython",
|
||||||
|
"version": 3
|
||||||
|
},
|
||||||
|
"file_extension": ".py",
|
||||||
|
"mimetype": "text/x-python",
|
||||||
|
"name": "python",
|
||||||
|
"nbconvert_exporter": "python",
|
||||||
|
"pygments_lexer": "ipython3",
|
||||||
|
"version": "3.8.10"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nbformat": 4,
|
||||||
|
"nbformat_minor": 5
|
||||||
|
}
|
Loading…
Reference in New Issue