diff --git a/test/txgen_test.py b/test/txgen_test.py index 6f93b8a04a42d2e00822c2bccf2f7359571df8a4..fad862797da80077926d8c6b288a6bc2741359bc 100644 --- a/test/txgen_test.py +++ b/test/txgen_test.py @@ -6,6 +6,12 @@ from tinman import txgen FULL_CONF = { "transactions_per_block" : 40, + "steem_block_interval" : 3, + "num_blocks_to_clear_witness_round" : 21, + "transaction_witness_setup_pad" : 100, + "steem_max_authority_membership" : 10, + "steem_address_prefix" : "TST", + "steem_init_miner_name" : 'initminer', "snapshot_file" : "/tmp/test-snapshot.json", "backfill_file" : "/tmp/test-backfill.actions", "min_vesting_per_account" : {"amount" : "1", "precision" : 3, "nai" : "@@000000021"}, @@ -219,13 +225,14 @@ class TxgenTest(unittest.TestCase): cmd, args = action if cmd == "metadata": - self.assertEqual(args["txgen:semver"], "0.2") - self.assertEqual(args["txgen:transactions_per_block"], 40) - self.assertIsNotNone(args["epoch:created"]) - self.assertEqual(args["actions:count"], 73) - self.assertGreater(args["recommend:miss_blocks"], 28631339) - self.assertEqual(args["snapshot:semver"], "0.2") - self.assertEqual(args["snapshot:origin_api"], "http://calculon.local") + if not args.get("post_backfill"): + self.assertEqual(args["txgen:semver"], "0.2") + self.assertEqual(args["txgen:transactions_per_block"], 40) + self.assertIsNotNone(args["epoch:created"]) + self.assertEqual(args["actions:count"], 73) + self.assertGreater(args["recommend:miss_blocks"], 28631339) + self.assertEqual(args["snapshot:semver"], "0.2") + self.assertEqual(args["snapshot:origin_api"], "http://calculon.local") elif cmd == "wait_blocks": self.assertGreater(args["count"], 0) elif cmd == "submit_transaction": diff --git a/tinman/txgen.py b/tinman/txgen.py index 04bc774e78a47e1fc526557dd904e005db088479..d367aa397ea24be78401544133cdf4a3bdc49adf 100755 --- a/tinman/txgen.py +++ b/tinman/txgen.py @@ -31,8 +31,11 @@ TRANSACTION_WITNESS_SETUP_PAD = 100 STEEM_MAX_AUTHORITY_MEMBERSHIP = 10 DENOM = 10**12 # we need stupidly high precision because VESTS STEEM_BLOCKS_PER_DAY = 28800 +STEEM_ADDRESS_PREFIX = "TST" +STEEM_INIT_MINER_NAME = "initminer" def create_system_accounts(conf, keydb, name): + steem_init_miner_name = conf.get("steem_init_miner_name", STEEM_INIT_MINER_NAME) desc = conf["accounts"][name] for index in range(desc.get("count", 1)): name = desc["name"].format(index=index) @@ -46,7 +49,7 @@ def create_system_accounts(conf, keydb, name): "memo_key" : keydb.get_pubkey(name, "memo"), "json_metadata" : "", }}, {"type" : "transfer_to_vesting_operation", "value" : { - "from" : "initminer", + "from" : steem_init_miner_name, "to" : name, "amount" : desc["vesting"], }}], @@ -107,26 +110,28 @@ def build_setup_transactions(account_stats, conf, keydb, silent=True): yield from port_snapshot(account_stats, conf, keydb, silent) def build_initminer_tx(conf, keydb): + steem_init_miner_name = conf.get("steem_init_miner_name", STEEM_INIT_MINER_NAME) + return {"operations" : [ {"type" : "account_update_operation", "value" : { - "account" : "initminer", - "owner" : keydb.get_authority("initminer", "owner"), - "active" : keydb.get_authority("initminer", "active"), - "posting" : keydb.get_authority("initminer", "posting"), - "memo_key" : keydb.get_pubkey("initminer", "memo"), + "account" : steem_init_miner_name, + "owner" : keydb.get_authority(steem_init_miner_name, "owner"), + "active" : keydb.get_authority(steem_init_miner_name, "active"), + "posting" : keydb.get_authority(steem_init_miner_name, "posting"), + "memo_key" : keydb.get_pubkey(steem_init_miner_name, "memo"), "json_metadata" : "", }}, {"type" : "transfer_to_vesting_operation", "value" : { - "from" : "initminer", - "to" : "initminer", - "amount" : conf["accounts"]["initminer"]["vesting"], + "from" : steem_init_miner_name, + "to" : steem_init_miner_name, + "amount" : conf["accounts"][steem_init_miner_name]["vesting"], }}, {"type" : "account_witness_vote_operation", "value" : { - "account" : "initminer", - "witness" : "initminer", + "account" : steem_init_miner_name, + "witness" : steem_init_miner_name, "approve" : True, }}, ], @@ -221,6 +226,7 @@ def get_proportions(account_stats, conf, silent=True): } def create_accounts(account_stats, conf, keydb, silent=True): + steem_address_prefix = conf.get("steem_address_prefix", STEEM_ADDRESS_PREFIX) system_account_names = set(get_system_account_names(conf)) proportions = get_proportions(account_stats, conf, silent) min_vesting_per_account = proportions["min_vesting_per_account"] @@ -250,7 +256,7 @@ def create_accounts(account_stats, conf, keydb, silent=True): "owner" : create_auth, "active" : create_auth, "posting" : create_auth, - "memo_key" : "TST"+a["memo_key"][3:], + "memo_key" : steem_address_prefix + a["memo_key"][3:], "json_metadata" : "", }}, {"type" : "transfer_to_vesting_operation", "value" : { "from" : porter, @@ -278,6 +284,8 @@ def create_accounts(account_stats, conf, keydb, silent=True): print("\t100.00%% complete") def update_accounts(account_stats, conf, keydb, silent=True): + steem_max_authority_membership = conf.get("steem_max_authority_membership", STEEM_MAX_AUTHORITY_MEMBERSHIP) + steem_address_prefix = conf.get("steem_address_prefix", STEEM_ADDRESS_PREFIX) system_account_names = set(get_system_account_names(conf)) account_names = account_stats["account_names"] num_accounts = len(account_names) @@ -298,13 +306,13 @@ def update_accounts(account_stats, conf, keydb, silent=True): new_posting_auth = cur_posting_auth.copy() # filter to only include existing accounts - for aw in cur_owner_auth["account_auths"][:(STEEM_MAX_AUTHORITY_MEMBERSHIP - 1)]: + for aw in cur_owner_auth["account_auths"][:(steem_max_authority_membership - 1)]: if (aw[0] not in account_names) or (aw[0] in system_account_names): new_owner_auth["account_auths"].remove(aw) - for aw in cur_active_auth["account_auths"][:(STEEM_MAX_AUTHORITY_MEMBERSHIP - 1)]: + for aw in cur_active_auth["account_auths"][:(steem_max_authority_membership - 1)]: if (aw[0] not in account_names) or (aw[0] in system_account_names): new_active_auth["account_auths"].remove(aw) - for aw in cur_posting_auth["account_auths"][:(STEEM_MAX_AUTHORITY_MEMBERSHIP - 1)]: + for aw in cur_posting_auth["account_auths"][:(steem_max_authority_membership - 1)]: if (aw[0] not in account_names) or (aw[0] in system_account_names): new_posting_auth["account_auths"].remove(aw) @@ -314,9 +322,9 @@ def update_accounts(account_stats, conf, keydb, silent=True): new_posting_auth["account_auths"].append([tnman, cur_posting_auth["weight_threshold"]]) # substitute prefix for key_auths - new_owner_auth["key_auths"] = [["TST"+k[3:], w] for k, w in new_owner_auth["key_auths"][:STEEM_MAX_AUTHORITY_MEMBERSHIP]] - new_active_auth["key_auths"] = [["TST"+k[3:], w] for k, w in new_active_auth["key_auths"][:STEEM_MAX_AUTHORITY_MEMBERSHIP]] - new_posting_auth["key_auths"] = [["TST"+k[3:], w] for k, w in new_posting_auth["key_auths"][:STEEM_MAX_AUTHORITY_MEMBERSHIP]] + new_owner_auth["key_auths"] = [[steem_address_prefix + k[3:], w] for k, w in new_owner_auth["key_auths"][:steem_max_authority_membership]] + new_active_auth["key_auths"] = [[steem_address_prefix + k[3:], w] for k, w in new_active_auth["key_auths"][:steem_max_authority_membership]] + new_posting_auth["key_auths"] = [[steem_address_prefix + k[3:], w] for k, w in new_posting_auth["key_auths"][:steem_max_authority_membership]] ops = [{"type" : "account_update_operation", "value" : { "account" : a["name"], @@ -340,16 +348,17 @@ def update_accounts(account_stats, conf, keydb, silent=True): print("\t100.00%% complete") def port_snapshot(account_stats, conf, keydb, silent=True): + steem_init_miner_name = conf.get("steem_init_miner_name", STEEM_INIT_MINER_NAME) porter = conf["accounts"]["porter"]["name"] yield {"operations" : [ {"type" : "transfer_operation", - "value" : {"from" : "initminer", + "value" : {"from" : steem_init_miner_name, "to" : porter, "amount" : conf["total_port_balance"], "memo" : "Fund porting balances", }}], - "wif_sigs" : [keydb.get_privkey("initminer")]} + "wif_sigs" : [keydb.get_privkey(steem_init_miner_name)]} yield from create_accounts(account_stats, conf, keydb, silent) yield from update_accounts(account_stats, conf, keydb, silent) @@ -364,6 +373,8 @@ def build_actions(conf, silent=True): account_names = account_stats["account_names"] num_accounts = len(account_names) transactions_per_block = conf["transactions_per_block"] + steem_block_interval = conf.get("steem_block_interval", STEEM_BLOCK_INTERVAL) + transaction_witness_setup_pad = conf.get("transaction_witness_setup_pad", TRANSACTION_WITNESS_SETUP_PAD) genesis_time = datetime.datetime.utcfromtimestamp(STEEM_GENESIS_TIMESTAMP) @@ -379,11 +390,11 @@ def build_actions(conf, silent=True): # Pad for update witnesses, vote witnesses, clear rounds, and transaction # setup processing time - predicted_block_count += TRANSACTION_WITNESS_SETUP_PAD + (predicted_transaction_setup_seconds // STEEM_BLOCK_INTERVAL) + predicted_block_count += transaction_witness_setup_pad + (predicted_transaction_setup_seconds // steem_block_interval) now = datetime.datetime.utcnow() - start_time = now - datetime.timedelta(seconds=predicted_block_count * STEEM_BLOCK_INTERVAL) - miss_blocks = int((start_time - genesis_time).total_seconds()) // STEEM_BLOCK_INTERVAL + start_time = now - datetime.timedelta(seconds=predicted_block_count * steem_block_interval) + miss_blocks = int((start_time - genesis_time).total_seconds()) // steem_block_interval miss_blocks = max(miss_blocks-1, 0) origin_api = None snapshot_head_block_num = None @@ -455,7 +466,7 @@ def build_actions(conf, silent=True): for tx in vote_accounts(conf, keydb, "elector", "init"): yield ["submit_transaction", {"tx" : tx}] - yield ["wait_blocks", {"count" : NUM_BLOCKS_TO_CLEAR_WITNESS_ROUND}] + yield ["wait_blocks", {"count" : conf.get("num_blocks_to_clear_witness_round", NUM_BLOCKS_TO_CLEAR_WITNESS_ROUND)}] return def main(argv): diff --git a/txgen.conf.example b/txgen.conf.example index 353789761af3f44272c19fe8c58da38522b902c7..f1aa39a75c2b42319cd889175b6bfd68ed906b8c 100644 --- a/txgen.conf.example +++ b/txgen.conf.example @@ -1,5 +1,11 @@ { "transactions_per_block" : 40, + "steem_block_interval" : 3, + "num_blocks_to_clear_witness_round" : 21, + "transaction_witness_setup_pad" : 100, + "steem_max_authority_membership" : 10, + "steem_address_prefix" : "TST", + "steem_init_miner_name" : "initminer", "snapshot_file" : "snapshot.json", "backfill_file" : "backfill.actions",