From db5e80bc9041f800fec3860f99f6ccdef56ae345 Mon Sep 17 00:00:00 2001 From: pingke Date: Fri, 18 Feb 2022 09:37:53 +0800 Subject: [PATCH 01/14] add fields to posw config --- devnet/singularity/cluster_config.json | 9 +++++++++ .../singularity/cluster_config_template.json | 6 +++++- quarkchain/cluster/jsonrpc.py | 4 ++++ quarkchain/cluster/master.py | 4 ++-- quarkchain/cluster/slave.py | 3 +++ quarkchain/cluster/tests/test_cluster.py | 1 + quarkchain/config.py | 18 ++++++++++++++++++ quarkchain/tests/test_config.py | 6 +++++- 8 files changed, 47 insertions(+), 4 deletions(-) diff --git a/devnet/singularity/cluster_config.json b/devnet/singularity/cluster_config.json index 1c02c60a6..574af6242 100644 --- a/devnet/singularity/cluster_config.json +++ b/devnet/singularity/cluster_config.json @@ -53,6 +53,15 @@ "DIFFICULTY_ADJUSTMENT_FACTOR": 1024, "EPOCH_INTERVAL": 525600, "POSW_CONFIG": { + "ENABLED": true, + "ENABLE_TIMESTAMP": 1645200000, + "DIFF_DIVIDER": 100, + "WINDOW_SIZE": 512, + "TOTAL_STAKE_PER_BLOCK": 10000000000000000000000, + "BOOST_TIMESTAMP": 1645372800, + "BOOST_MULTIPLER_PER_STEP": 2, + "BOOST_STEPS": 8, + "BOOST_SETP_INTERVAL": 43200 } }, "CHAINS": [ diff --git a/mainnet/singularity/cluster_config_template.json b/mainnet/singularity/cluster_config_template.json index 4a93b7958..d45c278bf 100644 --- a/mainnet/singularity/cluster_config_template.json +++ b/mainnet/singularity/cluster_config_template.json @@ -89,7 +89,11 @@ "ENABLE_TIMESTAMP": 1569567600, "DIFF_DIVIDER": 10000, "WINDOW_SIZE": 512, - "TOTAL_STAKE_PER_BLOCK": 1000000000000000000000000 + "TOTAL_STAKE_PER_BLOCK": 1000000000000000000000000, + "BOOST_TIMESTAMP": 1646064000, + "BOOST_MULTIPLER_PER_STEP": 2, + "BOOST_STEPS": 8, + "BOOST_SETP_INTERVAL": 172800 } }, "CHAINS": [ diff --git a/quarkchain/cluster/jsonrpc.py b/quarkchain/cluster/jsonrpc.py index 7158999e2..fd464e3aa 100644 --- a/quarkchain/cluster/jsonrpc.py +++ b/quarkchain/cluster/jsonrpc.py @@ -1469,6 +1469,7 @@ def __init__( self.port = port self.host = host self.env = env + self.default_shard_id = slave_server.get_default_shard_id() self.slave = slave_server self.counters = dict() self.pending_tx_cache = LRUCache(maxsize=1024) @@ -1515,6 +1516,9 @@ async def __handle(self, websocket, path): sub_id = response["result"] full_shard_id = shard_id_decoder(d.get("params")[1]) sub_ids[sub_id] = full_shard_id + elif method == "eth_subscribe": + sub_id = response["result"] + sub_ids[sub_id] = self.default_shard_id elif method == "unsubscribe": sub_id = d.get("params")[0] del sub_ids[sub_id] diff --git a/quarkchain/cluster/master.py b/quarkchain/cluster/master.py index da26ac12d..e4ce6527b 100644 --- a/quarkchain/cluster/master.py +++ b/quarkchain/cluster/master.py @@ -1459,7 +1459,7 @@ async def get_stats(self): shard["poswEnabled"] = config.ENABLED shard["poswMinStake"] = config.TOTAL_STAKE_PER_BLOCK shard["poswWindowSize"] = config.WINDOW_SIZE - shard["difficultyDivider"] = config.DIFF_DIVIDER + shard["difficultyDivider"] = config.get_diff_divider(shard_stats.timestamp) shards.append(shard) shards.sort(key=lambda x: x["fullShardId"]) @@ -1685,7 +1685,7 @@ async def get_work( check(isinstance(block, RootBlock)) posw_mineable = await self.posw_mineable(block) config = self.env.quark_chain_config.ROOT.POSW_CONFIG - return work, config.DIFF_DIVIDER if posw_mineable else None + return work, config.get_diff_divider(block.header.create_time) if posw_mineable else None if branch.value not in self.branch_to_slaves: return None, None diff --git a/quarkchain/cluster/slave.py b/quarkchain/cluster/slave.py index 81c570b41..272f4e773 100644 --- a/quarkchain/cluster/slave.py +++ b/quarkchain/cluster/slave.py @@ -964,6 +964,9 @@ def start_mining(self, artificial_tx_config): ) shard.miner.start() + def get_default_shard_id(self): + return self.full_shard_id_list[0] + def create_transactions( self, num_tx_per_shard, x_shard_percent, tx: TypedTransaction ): diff --git a/quarkchain/cluster/tests/test_cluster.py b/quarkchain/cluster/tests/test_cluster.py index 2f23005f2..eb76458e0 100644 --- a/quarkchain/cluster/tests/test_cluster.py +++ b/quarkchain/cluster/tests/test_cluster.py @@ -2502,6 +2502,7 @@ def add_root_block(addr, sign=False): qkc_config.ROOT.POSW_CONFIG.WINDOW_SIZE = 2 # should always pass pow check if posw is applied qkc_config.ROOT.POSW_CONFIG.DIFF_DIVIDER = 1000000 + qkc_config.ROOT.POSW_CONFIG.BOOST_TIMESTAMP = 0 shard = next(iter(clusters[0].slave_list[0].shards.values())) # monkey patch staking results diff --git a/quarkchain/config.py b/quarkchain/config.py index 2e4054bed..4ac136f0d 100644 --- a/quarkchain/config.py +++ b/quarkchain/config.py @@ -118,6 +118,21 @@ class POSWConfig(BaseConfig): # TODO: needs better tuning / estimating # = total stakes / alpha TOTAL_STAKE_PER_BLOCK = (10 ** 9) * QUARKSH_TO_JIAOZI + BOOST_TIMESTAMP = 0 # 0 mean Disable + BOOST_MULTIPLER_PER_STEP = 2 + BOOST_STEPS = 8 + BOOST_SETP_INTERVAL = 43200 + + def get_diff_divider(self, block_timestamp): + diff_divider = self.DIFF_DIVIDER + if 0 < self.BOOST_TIMESTAMP < block_timestamp: + steps = (block_timestamp - self.BOOST_TIMESTAMP) // self.BOOST_SETP_INTERVAL + 1 + if steps > self.BOOST_STEPS: + steps = self.BOOST_STEPS + + diff_divider = self.DIFF_DIVIDER * pow(self.BOOST_MULTIPLER_PER_STEP, steps) + + return diff_divider class ChainConfig(BaseConfig): @@ -251,6 +266,9 @@ def __init__(self): self.POSW_CONFIG.WINDOW_SIZE = 4320 # 72 hours self.POSW_CONFIG.DIFF_DIVIDER = 1000 self.POSW_CONFIG.TOTAL_STAKE_PER_BLOCK = 240000 * QUARKSH_TO_JIAOZI + self.POSW_CONFIG.BOOST_MULTIPLER_PER_STEP = 2 + self.POSW_CONFIG.BOOST_STEPS = 8 + self.POSW_CONFIG.BOOST_SETP_INTERVAL = 172800 def to_dict(self): ret = super().to_dict() diff --git a/quarkchain/tests/test_config.py b/quarkchain/tests/test_config.py index f82b7837e..3c7687482 100644 --- a/quarkchain/tests/test_config.py +++ b/quarkchain/tests/test_config.py @@ -115,7 +115,11 @@ def test_serialization(self): "ENABLE_TIMESTAMP": 0, "DIFF_DIVIDER": 20, "WINDOW_SIZE": 256, - "TOTAL_STAKE_PER_BLOCK": 1000000000000000000000000000 + "TOTAL_STAKE_PER_BLOCK": 1000000000000000000000000000, + "BOOST_TIMESTAMP": 0, + "BOOST_MULTIPLER_PER_STEP": 2, + "BOOST_STEPS": 8, + "BOOST_SETP_INTERVAL": 172800 }, "MAX_MINOR_BLOCKS_IN_MEMORY": 1536 }, From 96e172951a321e2762d4f2db80d7f41b7f0c3758 Mon Sep 17 00:00:00 2001 From: pingke Date: Fri, 18 Feb 2022 09:50:53 +0800 Subject: [PATCH 02/14] remove not required change --- quarkchain/cluster/jsonrpc.py | 4 ---- quarkchain/cluster/slave.py | 3 --- quarkchain/tests/test_config.py | 8 ++++---- 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/quarkchain/cluster/jsonrpc.py b/quarkchain/cluster/jsonrpc.py index fd464e3aa..7158999e2 100644 --- a/quarkchain/cluster/jsonrpc.py +++ b/quarkchain/cluster/jsonrpc.py @@ -1469,7 +1469,6 @@ def __init__( self.port = port self.host = host self.env = env - self.default_shard_id = slave_server.get_default_shard_id() self.slave = slave_server self.counters = dict() self.pending_tx_cache = LRUCache(maxsize=1024) @@ -1516,9 +1515,6 @@ async def __handle(self, websocket, path): sub_id = response["result"] full_shard_id = shard_id_decoder(d.get("params")[1]) sub_ids[sub_id] = full_shard_id - elif method == "eth_subscribe": - sub_id = response["result"] - sub_ids[sub_id] = self.default_shard_id elif method == "unsubscribe": sub_id = d.get("params")[0] del sub_ids[sub_id] diff --git a/quarkchain/cluster/slave.py b/quarkchain/cluster/slave.py index 272f4e773..81c570b41 100644 --- a/quarkchain/cluster/slave.py +++ b/quarkchain/cluster/slave.py @@ -964,9 +964,6 @@ def start_mining(self, artificial_tx_config): ) shard.miner.start() - def get_default_shard_id(self): - return self.full_shard_id_list[0] - def create_transactions( self, num_tx_per_shard, x_shard_percent, tx: TypedTransaction ): diff --git a/quarkchain/tests/test_config.py b/quarkchain/tests/test_config.py index 3c7687482..7077b164a 100644 --- a/quarkchain/tests/test_config.py +++ b/quarkchain/tests/test_config.py @@ -116,10 +116,10 @@ def test_serialization(self): "DIFF_DIVIDER": 20, "WINDOW_SIZE": 256, "TOTAL_STAKE_PER_BLOCK": 1000000000000000000000000000, - "BOOST_TIMESTAMP": 0, - "BOOST_MULTIPLER_PER_STEP": 2, - "BOOST_STEPS": 8, - "BOOST_SETP_INTERVAL": 172800 + "BOOST_TIMESTAMP": 0, + "BOOST_MULTIPLER_PER_STEP": 2, + "BOOST_STEPS": 8, + "BOOST_SETP_INTERVAL": 172800 }, "MAX_MINOR_BLOCKS_IN_MEMORY": 1536 }, From 6c438a84930c97ab8a69bab62bd158149e1c4b77 Mon Sep 17 00:00:00 2001 From: pingke Date: Fri, 18 Feb 2022 10:46:36 +0800 Subject: [PATCH 03/14] fix testcase fail --- quarkchain/tests/test_config.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/quarkchain/tests/test_config.py b/quarkchain/tests/test_config.py index 7077b164a..e9050bc09 100644 --- a/quarkchain/tests/test_config.py +++ b/quarkchain/tests/test_config.py @@ -77,7 +77,11 @@ def test_serialization(self): "ENABLE_TIMESTAMP": 0, "DIFF_DIVIDER": 1000, "WINDOW_SIZE": 4320, - "TOTAL_STAKE_PER_BLOCK": 240000000000000000000000 + "TOTAL_STAKE_PER_BLOCK": 240000000000000000000000, + "BOOST_TIMESTAMP": 0, + "BOOST_MULTIPLER_PER_STEP": 2, + "BOOST_STEPS": 8, + "BOOST_SETP_INTERVAL": 172800 } }, "CHAINS": [ @@ -119,7 +123,7 @@ def test_serialization(self): "BOOST_TIMESTAMP": 0, "BOOST_MULTIPLER_PER_STEP": 2, "BOOST_STEPS": 8, - "BOOST_SETP_INTERVAL": 172800 + "BOOST_SETP_INTERVAL": 43200 }, "MAX_MINOR_BLOCKS_IN_MEMORY": 1536 }, @@ -157,7 +161,11 @@ def test_serialization(self): "ENABLE_TIMESTAMP": 0, "DIFF_DIVIDER": 20, "WINDOW_SIZE": 256, - "TOTAL_STAKE_PER_BLOCK": 1000000000000000000000000000 + "TOTAL_STAKE_PER_BLOCK": 1000000000000000000000000000, + "BOOST_TIMESTAMP": 0, + "BOOST_MULTIPLER_PER_STEP": 2, + "BOOST_STEPS": 8, + "BOOST_SETP_INTERVAL": 43200 }, "MAX_MINOR_BLOCKS_IN_MEMORY": 1536 }, @@ -195,7 +203,11 @@ def test_serialization(self): "ENABLE_TIMESTAMP": 0, "DIFF_DIVIDER": 20, "WINDOW_SIZE": 256, - "TOTAL_STAKE_PER_BLOCK": 1000000000000000000000000000 + "TOTAL_STAKE_PER_BLOCK": 1000000000000000000000000000, + "BOOST_TIMESTAMP": 0, + "BOOST_MULTIPLER_PER_STEP": 2, + "BOOST_STEPS": 8, + "BOOST_SETP_INTERVAL": 43200 }, "MAX_MINOR_BLOCKS_IN_MEMORY": 1536 } From a66c14ff21d245a2824e640bf37ff2098d6c5352 Mon Sep 17 00:00:00 2001 From: pingke Date: Fri, 18 Feb 2022 14:20:13 +0800 Subject: [PATCH 04/14] add test case --- quarkchain/tests/test_config.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/quarkchain/tests/test_config.py b/quarkchain/tests/test_config.py index e9050bc09..c3ca92463 100644 --- a/quarkchain/tests/test_config.py +++ b/quarkchain/tests/test_config.py @@ -339,3 +339,21 @@ def test_special_contract_enable_ts(self): env.cluster_config = cluster_config for addr in PRECOMPILED_CONTRACTS_AFTER_EVM_ENABLED: self.assertEqual(specials[addr][1], 123) + + def test_get_diff_divider(self): + block_timestamp = 1646064000 + config = QuarkChainConfig().config.ROOT.POSW_CONFIG + config.BOOST_TIMESTAMP = 0 + self.assertEqual(config.DIFF_DIVIDER, config.get_diff_divider(block_timestamp)) + config.BOOST_TIMESTAMP = block_timestamp + 1 + self.assertEqual(config.DIFF_DIVIDER, config.get_diff_divider(block_timestamp)) + config.BOOST_TIMESTAMP = block_timestamp - 1 + self.assertEqual(config.DIFF_DIVIDER * config.BOOST_MULTIPLER_PER_STEP, + config.get_diff_divider(block_timestamp)) + config.BOOST_TIMESTAMP = block_timestamp - config.BOOST_SETP_INTERVAL * config.BOOST_STEPS + 1 + self.assertEqual(config.DIFF_DIVIDER * config.BOOST_MULTIPLER_PER_STEP * config.BOOST_STEPS, + config.get_diff_divider(block_timestamp)) + config.BOOST_TIMESTAMP = block_timestamp - config.BOOST_SETP_INTERVAL * config.BOOST_STEPS - 1 + self.assertEqual(config.DIFF_DIVIDER * config.BOOST_MULTIPLER_PER_STEP * config.BOOST_STEPS, + config.get_diff_divider(block_timestamp)) + From edae0f588c84bdf9b740afe36ab270b423a45742 Mon Sep 17 00:00:00 2001 From: pingke Date: Fri, 18 Feb 2022 14:25:18 +0800 Subject: [PATCH 05/14] fix testcase fail --- quarkchain/tests/test_config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quarkchain/tests/test_config.py b/quarkchain/tests/test_config.py index c3ca92463..62c1744d3 100644 --- a/quarkchain/tests/test_config.py +++ b/quarkchain/tests/test_config.py @@ -342,7 +342,7 @@ def test_special_contract_enable_ts(self): def test_get_diff_divider(self): block_timestamp = 1646064000 - config = QuarkChainConfig().config.ROOT.POSW_CONFIG + config = QuarkChainConfig().ROOT.POSW_CONFIG config.BOOST_TIMESTAMP = 0 self.assertEqual(config.DIFF_DIVIDER, config.get_diff_divider(block_timestamp)) config.BOOST_TIMESTAMP = block_timestamp + 1 From 4d8ae1aed75c9667314403567c6acc1fd664914d Mon Sep 17 00:00:00 2001 From: pingke Date: Fri, 18 Feb 2022 14:32:34 +0800 Subject: [PATCH 06/14] fix get_diff_divider testcase --- quarkchain/tests/test_config.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/quarkchain/tests/test_config.py b/quarkchain/tests/test_config.py index 62c1744d3..5968df7c4 100644 --- a/quarkchain/tests/test_config.py +++ b/quarkchain/tests/test_config.py @@ -351,9 +351,9 @@ def test_get_diff_divider(self): self.assertEqual(config.DIFF_DIVIDER * config.BOOST_MULTIPLER_PER_STEP, config.get_diff_divider(block_timestamp)) config.BOOST_TIMESTAMP = block_timestamp - config.BOOST_SETP_INTERVAL * config.BOOST_STEPS + 1 - self.assertEqual(config.DIFF_DIVIDER * config.BOOST_MULTIPLER_PER_STEP * config.BOOST_STEPS, + self.assertEqual(config.DIFF_DIVIDER * pow(config.BOOST_MULTIPLER_PER_STEP, config.BOOST_STEPS), config.get_diff_divider(block_timestamp)) config.BOOST_TIMESTAMP = block_timestamp - config.BOOST_SETP_INTERVAL * config.BOOST_STEPS - 1 - self.assertEqual(config.DIFF_DIVIDER * config.BOOST_MULTIPLER_PER_STEP * config.BOOST_STEPS, + self.assertEqual(config.DIFF_DIVIDER * pow(config.BOOST_MULTIPLER_PER_STEP, config.BOOST_STEPS), config.get_diff_divider(block_timestamp)) From ac46a0db445328ebd2e4182ad92399d6daa0943b Mon Sep 17 00:00:00 2001 From: pingke Date: Mon, 21 Feb 2022 09:48:48 +0800 Subject: [PATCH 07/14] resolve comments --- devnet/singularity/cluster_config.json | 2 +- mainnet/singularity/cluster_config_template.json | 2 +- quarkchain/config.py | 7 ++++--- quarkchain/tests/test_config.py | 12 ++++++------ 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/devnet/singularity/cluster_config.json b/devnet/singularity/cluster_config.json index 574af6242..4f1a0ebcc 100644 --- a/devnet/singularity/cluster_config.json +++ b/devnet/singularity/cluster_config.json @@ -61,7 +61,7 @@ "BOOST_TIMESTAMP": 1645372800, "BOOST_MULTIPLER_PER_STEP": 2, "BOOST_STEPS": 8, - "BOOST_SETP_INTERVAL": 43200 + "BOOST_STEP_INTERVAL": 43200 } }, "CHAINS": [ diff --git a/mainnet/singularity/cluster_config_template.json b/mainnet/singularity/cluster_config_template.json index d45c278bf..f6a65ad93 100644 --- a/mainnet/singularity/cluster_config_template.json +++ b/mainnet/singularity/cluster_config_template.json @@ -93,7 +93,7 @@ "BOOST_TIMESTAMP": 1646064000, "BOOST_MULTIPLER_PER_STEP": 2, "BOOST_STEPS": 8, - "BOOST_SETP_INTERVAL": 172800 + "BOOST_STEP_INTERVAL": 172800 } }, "CHAINS": [ diff --git a/quarkchain/config.py b/quarkchain/config.py index 4ac136f0d..794c5961f 100644 --- a/quarkchain/config.py +++ b/quarkchain/config.py @@ -121,12 +121,12 @@ class POSWConfig(BaseConfig): BOOST_TIMESTAMP = 0 # 0 mean Disable BOOST_MULTIPLER_PER_STEP = 2 BOOST_STEPS = 8 - BOOST_SETP_INTERVAL = 43200 + BOOST_STEP_INTERVAL = 43200 def get_diff_divider(self, block_timestamp): diff_divider = self.DIFF_DIVIDER if 0 < self.BOOST_TIMESTAMP < block_timestamp: - steps = (block_timestamp - self.BOOST_TIMESTAMP) // self.BOOST_SETP_INTERVAL + 1 + steps = (block_timestamp - self.BOOST_TIMESTAMP) // self.BOOST_STEP_INTERVAL + 1 if steps > self.BOOST_STEPS: steps = self.BOOST_STEPS @@ -266,9 +266,10 @@ def __init__(self): self.POSW_CONFIG.WINDOW_SIZE = 4320 # 72 hours self.POSW_CONFIG.DIFF_DIVIDER = 1000 self.POSW_CONFIG.TOTAL_STAKE_PER_BLOCK = 240000 * QUARKSH_TO_JIAOZI + self.POSW_CONFIG.BOOST_TIMESTAMP = 0 self.POSW_CONFIG.BOOST_MULTIPLER_PER_STEP = 2 self.POSW_CONFIG.BOOST_STEPS = 8 - self.POSW_CONFIG.BOOST_SETP_INTERVAL = 172800 + self.POSW_CONFIG.BOOST_STEP_INTERVAL = 172800 def to_dict(self): ret = super().to_dict() diff --git a/quarkchain/tests/test_config.py b/quarkchain/tests/test_config.py index 5968df7c4..59406737e 100644 --- a/quarkchain/tests/test_config.py +++ b/quarkchain/tests/test_config.py @@ -81,7 +81,7 @@ def test_serialization(self): "BOOST_TIMESTAMP": 0, "BOOST_MULTIPLER_PER_STEP": 2, "BOOST_STEPS": 8, - "BOOST_SETP_INTERVAL": 172800 + "BOOST_STEP_INTERVAL": 172800 } }, "CHAINS": [ @@ -123,7 +123,7 @@ def test_serialization(self): "BOOST_TIMESTAMP": 0, "BOOST_MULTIPLER_PER_STEP": 2, "BOOST_STEPS": 8, - "BOOST_SETP_INTERVAL": 43200 + "BOOST_STEP_INTERVAL": 43200 }, "MAX_MINOR_BLOCKS_IN_MEMORY": 1536 }, @@ -165,7 +165,7 @@ def test_serialization(self): "BOOST_TIMESTAMP": 0, "BOOST_MULTIPLER_PER_STEP": 2, "BOOST_STEPS": 8, - "BOOST_SETP_INTERVAL": 43200 + "BOOST_STEP_INTERVAL": 43200 }, "MAX_MINOR_BLOCKS_IN_MEMORY": 1536 }, @@ -207,7 +207,7 @@ def test_serialization(self): "BOOST_TIMESTAMP": 0, "BOOST_MULTIPLER_PER_STEP": 2, "BOOST_STEPS": 8, - "BOOST_SETP_INTERVAL": 43200 + "BOOST_STEP_INTERVAL": 43200 }, "MAX_MINOR_BLOCKS_IN_MEMORY": 1536 } @@ -350,10 +350,10 @@ def test_get_diff_divider(self): config.BOOST_TIMESTAMP = block_timestamp - 1 self.assertEqual(config.DIFF_DIVIDER * config.BOOST_MULTIPLER_PER_STEP, config.get_diff_divider(block_timestamp)) - config.BOOST_TIMESTAMP = block_timestamp - config.BOOST_SETP_INTERVAL * config.BOOST_STEPS + 1 + config.BOOST_TIMESTAMP = block_timestamp - config.BOOST_STEP_INTERVAL * config.BOOST_STEPS + 1 self.assertEqual(config.DIFF_DIVIDER * pow(config.BOOST_MULTIPLER_PER_STEP, config.BOOST_STEPS), config.get_diff_divider(block_timestamp)) - config.BOOST_TIMESTAMP = block_timestamp - config.BOOST_SETP_INTERVAL * config.BOOST_STEPS - 1 + config.BOOST_TIMESTAMP = block_timestamp - config.BOOST_STEP_INTERVAL * config.BOOST_STEPS - 1 self.assertEqual(config.DIFF_DIVIDER * pow(config.BOOST_MULTIPLER_PER_STEP, config.BOOST_STEPS), config.get_diff_divider(block_timestamp)) From bb6ccab5b4ef488b6100479e0014d5e9dd287e12 Mon Sep 17 00:00:00 2001 From: pingke Date: Mon, 21 Feb 2022 18:50:23 +0800 Subject: [PATCH 08/14] update boost steps from 8 to 10 --- devnet/singularity/cluster_config.json | 2 +- mainnet/singularity/cluster_config_template.json | 2 +- quarkchain/config.py | 4 ++-- quarkchain/tests/test_config.py | 8 ++++---- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/devnet/singularity/cluster_config.json b/devnet/singularity/cluster_config.json index 4f1a0ebcc..56fb78e1d 100644 --- a/devnet/singularity/cluster_config.json +++ b/devnet/singularity/cluster_config.json @@ -60,7 +60,7 @@ "TOTAL_STAKE_PER_BLOCK": 10000000000000000000000, "BOOST_TIMESTAMP": 1645372800, "BOOST_MULTIPLER_PER_STEP": 2, - "BOOST_STEPS": 8, + "BOOST_STEPS": 10, "BOOST_STEP_INTERVAL": 43200 } }, diff --git a/mainnet/singularity/cluster_config_template.json b/mainnet/singularity/cluster_config_template.json index f6a65ad93..d08f81a14 100644 --- a/mainnet/singularity/cluster_config_template.json +++ b/mainnet/singularity/cluster_config_template.json @@ -92,7 +92,7 @@ "TOTAL_STAKE_PER_BLOCK": 1000000000000000000000000, "BOOST_TIMESTAMP": 1646064000, "BOOST_MULTIPLER_PER_STEP": 2, - "BOOST_STEPS": 8, + "BOOST_STEPS": 10, "BOOST_STEP_INTERVAL": 172800 } }, diff --git a/quarkchain/config.py b/quarkchain/config.py index 794c5961f..c7bb3b026 100644 --- a/quarkchain/config.py +++ b/quarkchain/config.py @@ -120,7 +120,7 @@ class POSWConfig(BaseConfig): TOTAL_STAKE_PER_BLOCK = (10 ** 9) * QUARKSH_TO_JIAOZI BOOST_TIMESTAMP = 0 # 0 mean Disable BOOST_MULTIPLER_PER_STEP = 2 - BOOST_STEPS = 8 + BOOST_STEPS = 10 BOOST_STEP_INTERVAL = 43200 def get_diff_divider(self, block_timestamp): @@ -268,7 +268,7 @@ def __init__(self): self.POSW_CONFIG.TOTAL_STAKE_PER_BLOCK = 240000 * QUARKSH_TO_JIAOZI self.POSW_CONFIG.BOOST_TIMESTAMP = 0 self.POSW_CONFIG.BOOST_MULTIPLER_PER_STEP = 2 - self.POSW_CONFIG.BOOST_STEPS = 8 + self.POSW_CONFIG.BOOST_STEPS = 10 self.POSW_CONFIG.BOOST_STEP_INTERVAL = 172800 def to_dict(self): diff --git a/quarkchain/tests/test_config.py b/quarkchain/tests/test_config.py index 59406737e..f39d596f3 100644 --- a/quarkchain/tests/test_config.py +++ b/quarkchain/tests/test_config.py @@ -80,7 +80,7 @@ def test_serialization(self): "TOTAL_STAKE_PER_BLOCK": 240000000000000000000000, "BOOST_TIMESTAMP": 0, "BOOST_MULTIPLER_PER_STEP": 2, - "BOOST_STEPS": 8, + "BOOST_STEPS": 10, "BOOST_STEP_INTERVAL": 172800 } }, @@ -122,7 +122,7 @@ def test_serialization(self): "TOTAL_STAKE_PER_BLOCK": 1000000000000000000000000000, "BOOST_TIMESTAMP": 0, "BOOST_MULTIPLER_PER_STEP": 2, - "BOOST_STEPS": 8, + "BOOST_STEPS": 10, "BOOST_STEP_INTERVAL": 43200 }, "MAX_MINOR_BLOCKS_IN_MEMORY": 1536 @@ -164,7 +164,7 @@ def test_serialization(self): "TOTAL_STAKE_PER_BLOCK": 1000000000000000000000000000, "BOOST_TIMESTAMP": 0, "BOOST_MULTIPLER_PER_STEP": 2, - "BOOST_STEPS": 8, + "BOOST_STEPS": 10, "BOOST_STEP_INTERVAL": 43200 }, "MAX_MINOR_BLOCKS_IN_MEMORY": 1536 @@ -206,7 +206,7 @@ def test_serialization(self): "TOTAL_STAKE_PER_BLOCK": 1000000000000000000000000000, "BOOST_TIMESTAMP": 0, "BOOST_MULTIPLER_PER_STEP": 2, - "BOOST_STEPS": 8, + "BOOST_STEPS": 10, "BOOST_STEP_INTERVAL": 43200 }, "MAX_MINOR_BLOCKS_IN_MEMORY": 1536 From a11f7fa45781c247d2ea10ba65d6eb895f005526 Mon Sep 17 00:00:00 2001 From: pingke Date: Thu, 24 Feb 2022 23:30:57 +0800 Subject: [PATCH 09/14] update config for test --- devnet/singularity/cluster_config.json | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/devnet/singularity/cluster_config.json b/devnet/singularity/cluster_config.json index 56fb78e1d..7784ba84a 100644 --- a/devnet/singularity/cluster_config.json +++ b/devnet/singularity/cluster_config.json @@ -33,7 +33,7 @@ "ENABLE_GENERAL_NATIVE_TOKEN_TIMESTAMP": 0, "ROOT": { "MAX_STALE_ROOT_BLOCK_HEIGHT_DIFF": 22500, - "CONSENSUS_TYPE": "POW_SIMULATE", + "CONSENSUS_TYPE": "POW_ETHASH", "CONSENSUS_CONFIG": { "TARGET_BLOCK_TIME": 60, "REMOTE_MINE": false @@ -44,24 +44,24 @@ "HASH_PREV_BLOCK": "0000000000000000000000000000000000000000000000000000000000000000", "HASH_MERKLE_ROOT": "0000000000000000000000000000000000000000000000000000000000000000", "TIMESTAMP": 1556639999, - "DIFFICULTY": 10000000000000, + "DIFFICULTY": 100000, "NONCE": 0 }, - "COINBASE_ADDRESS": "000000000000000000000000000000000000000000000000", + "COINBASE_ADDRESS": "a92885095A33E45A3C018Df7Aa6242B62Acb971800000000", "COINBASE_AMOUNT": 156000000000000000000, "DIFFICULTY_ADJUSTMENT_CUTOFF_TIME": 40, "DIFFICULTY_ADJUSTMENT_FACTOR": 1024, "EPOCH_INTERVAL": 525600, "POSW_CONFIG": { "ENABLED": true, - "ENABLE_TIMESTAMP": 1645200000, + "ENABLE_TIMESTAMP": 1645716600, "DIFF_DIVIDER": 100, "WINDOW_SIZE": 512, "TOTAL_STAKE_PER_BLOCK": 10000000000000000000000, - "BOOST_TIMESTAMP": 1645372800, + "BOOST_TIMESTAMP": 1645718100, "BOOST_MULTIPLER_PER_STEP": 2, "BOOST_STEPS": 10, - "BOOST_STEP_INTERVAL": 43200 + "BOOST_STEP_INTERVAL": 3600 } }, "CHAINS": [ @@ -90,6 +90,11 @@ "balances": { "QKC": 600000000000000000000000000 } + }, + "5C935469C5592Aeeac3372e922d9bCEabDF8830d00000000": { + "balances": { + "QKC": 600000000000000000000000000 + } } } }, From 0c88e527a6234d00819dc7a030c6803afca7167f Mon Sep 17 00:00:00 2001 From: pingke Date: Mon, 7 Mar 2022 10:43:02 +0800 Subject: [PATCH 10/14] update config for devnet --- devnet/singularity/cluster_config.json | 8 ++++---- mainnet/singularity/cluster_config_template.json | 2 +- quarkchain/config.py | 6 +++--- quarkchain/tests/test_config.py | 14 +++++++------- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/devnet/singularity/cluster_config.json b/devnet/singularity/cluster_config.json index 7784ba84a..e4da6fcd3 100644 --- a/devnet/singularity/cluster_config.json +++ b/devnet/singularity/cluster_config.json @@ -36,7 +36,7 @@ "CONSENSUS_TYPE": "POW_ETHASH", "CONSENSUS_CONFIG": { "TARGET_BLOCK_TIME": 60, - "REMOTE_MINE": false + "REMOTE_MINE": true }, "GENESIS": { "VERSION": 0, @@ -54,12 +54,12 @@ "EPOCH_INTERVAL": 525600, "POSW_CONFIG": { "ENABLED": true, - "ENABLE_TIMESTAMP": 1645716600, + "ENABLE_TIMESTAMP": 1646668800, "DIFF_DIVIDER": 100, "WINDOW_SIZE": 512, "TOTAL_STAKE_PER_BLOCK": 10000000000000000000000, - "BOOST_TIMESTAMP": 1645718100, - "BOOST_MULTIPLER_PER_STEP": 2, + "BOOST_TIMESTAMP": 1646719200, + "BOOST_MULTIPLIER_PER_STEP": 2, "BOOST_STEPS": 10, "BOOST_STEP_INTERVAL": 3600 } diff --git a/mainnet/singularity/cluster_config_template.json b/mainnet/singularity/cluster_config_template.json index d08f81a14..698938f31 100644 --- a/mainnet/singularity/cluster_config_template.json +++ b/mainnet/singularity/cluster_config_template.json @@ -91,7 +91,7 @@ "WINDOW_SIZE": 512, "TOTAL_STAKE_PER_BLOCK": 1000000000000000000000000, "BOOST_TIMESTAMP": 1646064000, - "BOOST_MULTIPLER_PER_STEP": 2, + "BOOST_MULTIPLIER_PER_STEP": 2, "BOOST_STEPS": 10, "BOOST_STEP_INTERVAL": 172800 } diff --git a/quarkchain/config.py b/quarkchain/config.py index c7bb3b026..c67ca71b6 100644 --- a/quarkchain/config.py +++ b/quarkchain/config.py @@ -119,7 +119,7 @@ class POSWConfig(BaseConfig): # = total stakes / alpha TOTAL_STAKE_PER_BLOCK = (10 ** 9) * QUARKSH_TO_JIAOZI BOOST_TIMESTAMP = 0 # 0 mean Disable - BOOST_MULTIPLER_PER_STEP = 2 + BOOST_MULTIPLIER_PER_STEP = 2 BOOST_STEPS = 10 BOOST_STEP_INTERVAL = 43200 @@ -130,7 +130,7 @@ def get_diff_divider(self, block_timestamp): if steps > self.BOOST_STEPS: steps = self.BOOST_STEPS - diff_divider = self.DIFF_DIVIDER * pow(self.BOOST_MULTIPLER_PER_STEP, steps) + diff_divider = self.DIFF_DIVIDER * pow(self.BOOST_MULTIPLIER_PER_STEP, steps) return diff_divider @@ -267,7 +267,7 @@ def __init__(self): self.POSW_CONFIG.DIFF_DIVIDER = 1000 self.POSW_CONFIG.TOTAL_STAKE_PER_BLOCK = 240000 * QUARKSH_TO_JIAOZI self.POSW_CONFIG.BOOST_TIMESTAMP = 0 - self.POSW_CONFIG.BOOST_MULTIPLER_PER_STEP = 2 + self.POSW_CONFIG.BOOST_MULTIPLIER_PER_STEP = 2 self.POSW_CONFIG.BOOST_STEPS = 10 self.POSW_CONFIG.BOOST_STEP_INTERVAL = 172800 diff --git a/quarkchain/tests/test_config.py b/quarkchain/tests/test_config.py index f39d596f3..4b195a614 100644 --- a/quarkchain/tests/test_config.py +++ b/quarkchain/tests/test_config.py @@ -79,7 +79,7 @@ def test_serialization(self): "WINDOW_SIZE": 4320, "TOTAL_STAKE_PER_BLOCK": 240000000000000000000000, "BOOST_TIMESTAMP": 0, - "BOOST_MULTIPLER_PER_STEP": 2, + "BOOST_MULTIPLIER_PER_STEP": 2, "BOOST_STEPS": 10, "BOOST_STEP_INTERVAL": 172800 } @@ -121,7 +121,7 @@ def test_serialization(self): "WINDOW_SIZE": 256, "TOTAL_STAKE_PER_BLOCK": 1000000000000000000000000000, "BOOST_TIMESTAMP": 0, - "BOOST_MULTIPLER_PER_STEP": 2, + "BOOST_MULTIPLIER_PER_STEP": 2, "BOOST_STEPS": 10, "BOOST_STEP_INTERVAL": 43200 }, @@ -163,7 +163,7 @@ def test_serialization(self): "WINDOW_SIZE": 256, "TOTAL_STAKE_PER_BLOCK": 1000000000000000000000000000, "BOOST_TIMESTAMP": 0, - "BOOST_MULTIPLER_PER_STEP": 2, + "BOOST_MULTIPLIER_PER_STEP": 2, "BOOST_STEPS": 10, "BOOST_STEP_INTERVAL": 43200 }, @@ -205,7 +205,7 @@ def test_serialization(self): "WINDOW_SIZE": 256, "TOTAL_STAKE_PER_BLOCK": 1000000000000000000000000000, "BOOST_TIMESTAMP": 0, - "BOOST_MULTIPLER_PER_STEP": 2, + "BOOST_MULTIPLIER_PER_STEP": 2, "BOOST_STEPS": 10, "BOOST_STEP_INTERVAL": 43200 }, @@ -348,12 +348,12 @@ def test_get_diff_divider(self): config.BOOST_TIMESTAMP = block_timestamp + 1 self.assertEqual(config.DIFF_DIVIDER, config.get_diff_divider(block_timestamp)) config.BOOST_TIMESTAMP = block_timestamp - 1 - self.assertEqual(config.DIFF_DIVIDER * config.BOOST_MULTIPLER_PER_STEP, + self.assertEqual(config.DIFF_DIVIDER * config.BOOST_MULTIPLIER_PER_STEP, config.get_diff_divider(block_timestamp)) config.BOOST_TIMESTAMP = block_timestamp - config.BOOST_STEP_INTERVAL * config.BOOST_STEPS + 1 - self.assertEqual(config.DIFF_DIVIDER * pow(config.BOOST_MULTIPLER_PER_STEP, config.BOOST_STEPS), + self.assertEqual(config.DIFF_DIVIDER * pow(config.BOOST_MULTIPLIER_PER_STEP, config.BOOST_STEPS), config.get_diff_divider(block_timestamp)) config.BOOST_TIMESTAMP = block_timestamp - config.BOOST_STEP_INTERVAL * config.BOOST_STEPS - 1 - self.assertEqual(config.DIFF_DIVIDER * pow(config.BOOST_MULTIPLER_PER_STEP, config.BOOST_STEPS), + self.assertEqual(config.DIFF_DIVIDER * pow(config.BOOST_MULTIPLIER_PER_STEP, config.BOOST_STEPS), config.get_diff_divider(block_timestamp)) From c80ac2d032278ed020206cf09737358232a8347f Mon Sep 17 00:00:00 2001 From: pingke Date: Wed, 9 Mar 2022 15:09:14 +0800 Subject: [PATCH 11/14] update boost timestamp --- devnet/singularity/cluster_config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/devnet/singularity/cluster_config.json b/devnet/singularity/cluster_config.json index e4da6fcd3..68f443ae4 100644 --- a/devnet/singularity/cluster_config.json +++ b/devnet/singularity/cluster_config.json @@ -58,7 +58,7 @@ "DIFF_DIVIDER": 100, "WINDOW_SIZE": 512, "TOTAL_STAKE_PER_BLOCK": 10000000000000000000000, - "BOOST_TIMESTAMP": 1646719200, + "BOOST_TIMESTAMP": 1646870400, "BOOST_MULTIPLIER_PER_STEP": 2, "BOOST_STEPS": 10, "BOOST_STEP_INTERVAL": 3600 From 578506a15d7dc8d6fd6877acdc00c29eda01a5f9 Mon Sep 17 00:00:00 2001 From: pingke Date: Fri, 11 Mar 2022 00:16:53 +0800 Subject: [PATCH 12/14] add ROOT_CHAIN_POSW_CONTRACT_BYTECODE_HASH to config --- devnet/singularity/cluster_config.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/devnet/singularity/cluster_config.json b/devnet/singularity/cluster_config.json index 68f443ae4..c2dbc5080 100644 --- a/devnet/singularity/cluster_config.json +++ b/devnet/singularity/cluster_config.json @@ -365,7 +365,8 @@ } ], "REWARD_TAX_RATE": 0.5, - "BLOCK_REWARD_DECAY_FACTOR": 0.88 + "BLOCK_REWARD_DECAY_FACTOR": 0.88, + "ROOT_CHAIN_POSW_CONTRACT_BYTECODE_HASH": "ee90e568da573f251d63256e843add8bd7a27cec1f4c2a06ef20380be68df0a3" }, "MASTER": { "MASTER_TO_SLAVE_CONNECT_RETRY_DELAY": 1.0 From 3665030e5ba52a50b63830a18b19848e790a4817 Mon Sep 17 00:00:00 2001 From: pingke Date: Fri, 11 Mar 2022 11:58:28 +0800 Subject: [PATCH 13/14] update timestamp --- devnet/singularity/cluster_config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/devnet/singularity/cluster_config.json b/devnet/singularity/cluster_config.json index c2dbc5080..0f0cb0aec 100644 --- a/devnet/singularity/cluster_config.json +++ b/devnet/singularity/cluster_config.json @@ -58,7 +58,7 @@ "DIFF_DIVIDER": 100, "WINDOW_SIZE": 512, "TOTAL_STAKE_PER_BLOCK": 10000000000000000000000, - "BOOST_TIMESTAMP": 1646870400, + "BOOST_TIMESTAMP": 1646978400, "BOOST_MULTIPLIER_PER_STEP": 2, "BOOST_STEPS": 10, "BOOST_STEP_INTERVAL": 3600 From a8899a2b280514fb9b9c10fae20adfc2671f6386 Mon Sep 17 00:00:00 2001 From: pingke Date: Sat, 12 Mar 2022 16:17:07 +0800 Subject: [PATCH 14/14] fix bug --- quarkchain/cluster/posw.py | 2 +- quarkchain/cluster/shard.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/quarkchain/cluster/posw.py b/quarkchain/cluster/posw.py index f0d3edacf..109bac838 100644 --- a/quarkchain/cluster/posw.py +++ b/quarkchain/cluster/posw.py @@ -82,7 +82,7 @@ def get_posw_info( diff = header.difficulty ret = lambda success: PoSWInfo( - diff // config.DIFF_DIVIDER if success else diff, + diff // config.get_diff_divider(header.create_time) if success else diff, block_threshold, # mined blocks should include current one, assuming success posw_mined_blocks=cnt + 1, diff --git a/quarkchain/cluster/shard.py b/quarkchain/cluster/shard.py index c203cd201..feb85435b 100644 --- a/quarkchain/cluster/shard.py +++ b/quarkchain/cluster/shard.py @@ -406,7 +406,7 @@ def __validate_block_headers(self, block_header_list: List[MinorBlockHeader]): consensus_type = shard_config.CONSENSUS_TYPE diff = header.difficulty if shard_config.POSW_CONFIG.ENABLED: - diff //= shard_config.POSW_CONFIG.DIFF_DIVIDER + diff //= shard_config.POSW_CONFIG.get_diff_divider(header.create_time) validate_seal( header, consensus_type,