diff --git a/doc/economic_sim/dmcx_economic_sim.ipynb b/doc/economic_sim/dmcx_economic_sim.ipynb index 1334c56..838a3c9 100644 --- a/doc/economic_sim/dmcx_economic_sim.ipynb +++ b/doc/economic_sim/dmcx_economic_sim.ipynb @@ -26,7 +26,7 @@ }, { "cell_type": "code", - "execution_count": 197, + "execution_count": 233, "metadata": {}, "outputs": [ { @@ -146,7 +146,7 @@ }, { "cell_type": "code", - "execution_count": 198, + "execution_count": 234, "metadata": {}, "outputs": [ { @@ -290,7 +290,7 @@ }, { "cell_type": "code", - "execution_count": 199, + "execution_count": 235, "metadata": {}, "outputs": [ { @@ -395,7 +395,7 @@ }, { "cell_type": "code", - "execution_count": 200, + "execution_count": 236, "metadata": {}, "outputs": [ { @@ -470,7 +470,7 @@ "\n", "### Supplier(矿工) SHOW一个公共数据需要准备的GWT质押币\n", "\n", - "Supplier(矿工)是真正保存公共数据的人,他们把公共数据保存到本地,并在合适的时机SHOW存储证明以得到奖励。DMCX的存储证明基于ERC7585构造,要出示一个存储证明,就必须基一个“基准块高度”开始计算,在有效块高度前完成计算并提交到链上就是一次有效的存储证明。ERC7585的机制里,链上的合约并不能100%验证存储证明的正确性,而是基于博弈模型:如果有人发现了一个更好的存储证明,那就说明之前上链的是Fake的存储证明(挑战成功)。挑战成功的矿工会拿走提交Fake证明用户的质押币。\n", + "Supplier(矿工)是真正保存公共数据的人,他们把公共数据保存到本地,并在合适的时机SHOW存储证明以得到奖励。DMCX的存储证明基于ERC7585构造,要出示一个存储证明,就必须基一个“基准块高度”开始计算,在有效块高度前(目前是3个区块,在XLayer上大概是10秒,包含上链时间)完成计算并提交到链上就是一次有效的存储证明。ERC7585的机制里,链上的合约并不能100%验证存储证明的正确性,而是基于博弈模型:如果有人发现了一个更好的存储证明,那就说明之前上链的是Fake的存储证明(挑战成功)。挑战成功的矿工会拿走提交Fake证明用户的质押币。\n", "\n", "基于上述流程,矿工在开始公共数据挖矿之前必须需要准备一定的质押币。质押币的需求和其潜在收益有关,公式如下:\n", "\n", @@ -500,7 +500,7 @@ }, { "cell_type": "code", - "execution_count": 201, + "execution_count": 237, "metadata": {}, "outputs": [ { @@ -597,7 +597,12 @@ "\n", "算力奖励系数是一个和两次SHOW时间有关的函数,其设计逻辑在于通过首次SHOW和当前SHOW所在周期的平均总算力和平均算力增长率,通过一个公式得到一个算力奖励系数。算力奖励系数的计算公式的基本原则是与平均总算力成反比,与平均算力增长率成正比,公式如下:\n", "\n", - "```\n", + "```python\n", + "def getGWTDifficultRatio(total_size,growth_rate):\n", + " m = 1024*1024 - 1024*8*growth_rate\n", + " result = (0.243*m) / (total_size+0.867*m) + 0.02\n", + "\n", + " return result\n", "```\n", "\n", "\n", @@ -610,7 +615,7 @@ }, { "cell_type": "code", - "execution_count": 203, + "execution_count": 239, "metadata": {}, "outputs": [ { @@ -618,16 +623,21 @@ "output_type": "stream", "text": [ "public data hash0 min stake amount:3.84 GWT,immediate stake amount:213.84 GWT\n", - "public data hash3 min stake amount:1996.8000000000002 GWT,immediate stake amount:5105.770554358223 GWT\n", - "show data hash0 get blance reward: 37.44619289660616\n", - "show data hash3 get blance reward: 1554.4852771791113\n", - "show data hash0 get blance reward:33.701573606945544,power:402.2857142857143,power reward:-3842.73694489528\n", - "show data hash3 get blance reward:1399.0367494612,power:5895.314285714287,power reward:-73728.0706516202\n" + "public data hash3 min stake amount:1996.8000000000002 GWT,immediate stake amount:4821.72922698268 GWT\n", + "show data hash0 get blance reward: 38.087807115830266\n", + "show data hash3 get blance reward: 1412.46461349134\n", + "total_size:1225014.5142455557,growth_rate:5.036804229031415,difficult ratio:0.13665198936584874\n", + "show data hash0 get blance reward:34.27902640424724,power:402.2857142857143,power reward:43.97851452048344\n", + "total_size:1220534.497522133,growth_rate:5.0025,difficult ratio:0.13692058391200523\n", + "show data hash3 get blance reward:1271.2181521422062,power:5895.314285714287,power reward:645.751899475829\n", + "total_size:1551717.2603819617,growth_rate:0.042835620204552824,difficult ratio:0.12352194901444982\n", + "show data hash3 get blance reward:1156.2041850431574,power:5705.142857142857,power reward:563.7682920961221\n" ] } ], "source": [ "from datetime import datetime\n", + "import random\n", "\n", "global compute_power_cycles\n", "compute_power_cycles = []\n", @@ -640,7 +650,10 @@ "\n", "# from 0.02 to 0.3\n", "def getGWTDifficultRatio(total_size,growth_rate):\n", - " return 0.15\n", + " m = 1024*1024 - 1024*8*growth_rate\n", + " result = (0.243*m) / (total_size+0.867*m) + 0.02\n", + " print(f\"total_size:{total_size},growth_rate:{growth_rate},difficult ratio:{result}\")\n", + " return result\n", "\n", "# duration 单位是周\n", "def cacl_compute_power(datasize,pledgement,duration,price=16):\n", @@ -662,6 +675,8 @@ " last_power = compute_power_cycles[-1][\"total_power\"]\n", " if total_power > last_power*1.005:\n", " cycle_data[\"d_power\"] = (total_power - last_power) / last_power\n", + " if cycle_data[\"d_power\"] > 10:\n", + " cycle_data[\"d_power\"] = 10\n", " else:\n", " cycle_data[\"d_power\"] = 0.005\n", "\n", @@ -712,31 +727,18 @@ "\n", "add_compute_power_cycle(1)\n", "add_compute_power_cycle(1)\n", - "add_compute_power_cycle(16*10)\n", - "add_compute_power_cycle(16*20)\n", - "add_compute_power_cycle(16*50)\n", - "add_compute_power_cycle(16*40)\n", - "add_compute_power_cycle(16*70)\n", - "add_compute_power_cycle(16*90)\n", - "add_compute_power_cycle(16*100)\n", - "add_compute_power_cycle(16*120)\n", - "add_compute_power_cycle(16*200)\n", - "add_compute_power_cycle(16*200)\n", - "add_compute_power_cycle(16*200)\n", - "add_compute_power_cycle(16*200)\n", - "add_compute_power_cycle(16*200)\n", - "add_compute_power_cycle(16*200)\n", - "add_compute_power_cycle(16*200)\n", - "add_compute_power_cycle(16*200)\n", - "add_compute_power_cycle(16*200)\n", - "add_compute_power_cycle(16*200)\n", + "totals = 1024*1024\n", + "for i in range(100):\n", + " totals = totals + totals * random.uniform(-0.1,0.2)\n", + " add_compute_power_cycle(totals)\n", "\n", "show_min_stack(\"hash0\")\n", "show_min_stack(\"hash3\")\n", "showdata(\"hash0\",\"2024-08-01 00:00:00\")\n", "showdata(\"hash3\",\"2024-08-01 00:00:00\")\n", "showdata(\"hash0\",\"2024-08-12 00:00:00\")\n", - "showdata(\"hash3\",\"2024-09-01 00:00:00\")" + "showdata(\"hash3\",\"2024-09-01 00:00:00\")\n", + "showdata(\"hash3\",\"2024-10-01 00:00:00\")" ] }, { @@ -818,51 +820,9 @@ }, { "cell_type": "code", - "execution_count": 152, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "reward rank 0 ,reward percent:0.15\n", - "reward rank 1 ,reward percent:0.1125\n", - "reward rank 2 ,reward percent:0.09375\n", - "reward rank 3 ,reward percent:0.075\n", - "reward rank 4 ,reward percent:0.0625\n", - "reward rank 5 ,reward percent:0.05\n", - "reward rank 6 ,reward percent:0.0375\n", - "reward rank 7 ,reward percent:0.033125\n", - "reward rank 8 ,reward percent:0.02625\n", - "reward rank 9 ,reward percent:0.0225\n", - "reward rank 10 ,reward percent:0.021875\n", - "reward rank 11 ,reward percent:0.02125\n", - "reward rank 12 ,reward percent:0.020625\n", - "reward rank 13 ,reward percent:0.02\n", - "reward rank 14 ,reward percent:0.019375\n", - "reward rank 15 ,reward percent:0.01875\n", - "reward rank 16 ,reward percent:0.018125\n", - "reward rank 17 ,reward percent:0.0175\n", - "reward rank 18 ,reward percent:0.016875\n", - "reward rank 19 ,reward percent:0.01625\n", - "reward rank 20 ,reward percent:0.015625\n", - "reward rank 21 ,reward percent:0.015\n", - "reward rank 22 ,reward percent:0.014375\n", - "reward rank 23 ,reward percent:0.01375\n", - "reward rank 24 ,reward percent:0.013125\n", - "reward rank 25 ,reward percent:0.0125\n", - "reward rank 26 ,reward percent:0.011875\n", - "reward rank 27 ,reward percent:0.01125\n", - "reward rank 28 ,reward percent:0.010625\n", - "reward rank 29 ,reward percent:0.01\n", - "reward rank 30 ,reward percent:0.009375\n", - "reward rank 31 ,reward percent:0.00875\n", - "=============================================\n", - "rank 12 ,pool reword:140020\n", - "\t total reward:2310.33,sponsor reward:1155.165,owner reward:462.06600000000003,supplier reward:138.6198\n" - ] - } - ], + "outputs": [], "source": [ "def get_winner_reward_percent(reword_rank):\n", " rewardScores = [\n",