Open kamilsa opened 2 years ago
@kamilsa I've prepared script:
import os import binascii import time from iroha import IrohaCrypto, Iroha, IrohaGrpc from functools import wraps IROHA_HOST_ADDR = os.getenv('IROHA_HOST_ADDR', '127.0.0.1') IROHA_PORT = os.getenv('IROHA_PORT', '50051') net = IrohaGrpc(f'{IROHA_HOST_ADDR}:{IROHA_PORT}') ADMIN_ACCOUNT_ID = os.getenv('ADMIN_ACCOUNT_ID', 'admin@test') ADMIN_PRIVATE_KEY = os.getenv( 'ADMIN_PRIVATE_KEY', 'f101537e319568c765b2cc89698325604991dca57b9716b58016b253506cab70') IROHA_ADMIN = Iroha(ADMIN_ACCOUNT_ID) ADMIN_PRIVATE_KEY_2 = '1234567890123456789012345678901234567890123456789012345678901234' USER_ACCOUNT_1 = 'a@test' USER_ACCOUNT_2 = 'b@test' USER_ACCOUNT_3 = 'c@test' USER_KEY = 'abcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcd' def trace(func): """ A decorator for tracing methods' begin/end execution points """ @wraps(func) def tracer(*args, **kwargs): name = func.__name__ print(f'\tEntering "{name}"') result = func(*args, **kwargs) print(f'\tLeaving "{name}"') return result return tracer @trace def send_transaction_and_print_status(tx): print(f'Transaction "{get_command_from_tx(tx)}" hash = {calculate_hash_of_transaction(tx)}, ' f'creator = {tx.payload.reduced_payload.creator_account_id}') net.send_tx(tx) for status in net.tx_status_stream(tx): print('\t\t', status) def get_command_from_tx(tx): commands_from_tx = [] for command in tx.payload.reduced_payload.__getattribute__("commands"): listed_fields = command.ListFields() commands_from_tx.append(listed_fields[0][0].name) return commands_from_tx[0] def calculate_hash_of_transaction(transaction_with_payload): h = IrohaCrypto.hash(transaction_with_payload) return binascii.hexlify(h).decode("utf-8") @trace def add_signatory(user_account: str, new_signatory_private_key: str): new_signatory_public_key = public_key_from_private(new_signatory_private_key) tx = IROHA_ADMIN.transaction([ IROHA_ADMIN.command('AddSignatory', account_id=user_account, public_key=new_signatory_public_key) ]) IrohaCrypto.sign_transaction(tx, ADMIN_PRIVATE_KEY) send_transaction_and_print_status(tx) def public_key_from_private(private_key: str): return IrohaCrypto.derive_public_key(private_key).decode('utf-8') @trace def create_account_pending(user_account: str, user_public_key: str): account, domain = user_account.split('@') tx = IROHA_ADMIN.transaction([ IROHA_ADMIN.command('CreateAccount', account_name=account, domain_id=domain, public_key=user_public_key) ], quorum=2) IrohaCrypto.sign_transaction(tx, ADMIN_PRIVATE_KEY) send_transaction_and_print_status(tx) def print_paragraph(text: str): print(10 * '-', text, ':', 10 * '-') @trace def get_pending_transactions(): query = IROHA_ADMIN.query('GetPendingTransactions') IrohaCrypto.sign_query(query, ADMIN_PRIVATE_KEY_2) pending_transactions = net.send_query(query) return pending_transactions.transactions_response.transactions @trace def sign_pending_transactions(txs_to_sign: [], txs_to_reject: [] = []): for i, tx in enumerate(get_pending_transactions()): if i in txs_to_sign: print(f'>>>>> Signing {i} transaction:', tx) IrohaCrypto.sign_transaction(tx, ADMIN_PRIVATE_KEY_2) elif i in txs_to_reject: print(f'>>>>> Rejecting {i} transaction:', tx) rejecting_key = len(ADMIN_PRIVATE_KEY_2) * '0' IrohaCrypto.sign_transaction(tx, rejecting_key) send_transaction_and_print_status(tx) if __name__ == '__main__': print_paragraph('Preparation') add_signatory(user_account=ADMIN_ACCOUNT_ID, new_signatory_private_key=ADMIN_PRIVATE_KEY_2) ################################################################################################ print_paragraph('Creating pending transactions (three accounts)') create_account_pending(user_account=USER_ACCOUNT_1, user_public_key=USER_KEY) create_account_pending(user_account=USER_ACCOUNT_2, user_public_key=USER_KEY) create_account_pending(user_account=USER_ACCOUNT_3, user_public_key=USER_KEY) ################################################################################################ print_paragraph('Checking pending transactions') print(get_pending_transactions()) ################################################################################################ print_paragraph('Signing again as usual') sign_pending_transactions(txs_to_sign=[0]) ################################################################################################ print_paragraph('Waiting') seconds_to_take_longer_than_mst_expiration_time = 2*60*60 # 2 hours time.sleep(seconds_to_take_longer_than_mst_expiration_time) ################################################################################################ print_paragraph('Checking pending transactions after waiting') print(get_pending_transactions()) ################################################################################################ print_paragraph('Signing after waiting') sign_pending_transactions(txs_to_sign=[0], txs_to_reject=[1])
And I've set in config one minute:
config
"mst_expiration_time" : 1,
But the pending transactions are not disappearing, here is output:
python /home/agh/Pulpit/blockchain/Watra-Ledger/src/irohaTeam/mstForever.py ---------- Preparation : ---------- Entering "add_signatory" Entering "send_transaction_and_print_status" Transaction "add_signatory" hash = 24a4ee2ac220ff3835e7fdb3b016b928b3306d2a3d6b6d9e24cd8fab24d6f86e, creator = admin@test ('ENOUGH_SIGNATURES_COLLECTED', 9, 0) ('STATEFUL_VALIDATION_SUCCESS', 3, 0) ('COMMITTED', 5, 0) Leaving "send_transaction_and_print_status" Leaving "add_signatory" ---------- Creating pending transactions (three accounts) : ---------- Entering "create_account_pending" Entering "send_transaction_and_print_status" Transaction "create_account" hash = 66e9f7587338fc9a7f4ebd1095c1d293bdc7be6fc07a42c1416f26117761873a, creator = admin@test ('MST_PENDING', 8, 0) Leaving "send_transaction_and_print_status" Leaving "create_account_pending" Entering "create_account_pending" Entering "send_transaction_and_print_status" Transaction "create_account" hash = 10295b459e9338e522f1f8f6094c7fb7c2500abbe31d399a7be84da2a1759f5d, creator = admin@test ('MST_PENDING', 8, 0) Leaving "send_transaction_and_print_status" Leaving "create_account_pending" Entering "create_account_pending" Entering "send_transaction_and_print_status" Transaction "create_account" hash = 2d37a1664cdef7c602f8dcfcaf47c376712f4b9b9147eec3b7f5db89d9fb9b55, creator = admin@test ('MST_PENDING', 8, 0) Leaving "send_transaction_and_print_status" Leaving "create_account_pending" ---------- Checking pending transactions : ---------- Entering "get_pending_transactions" Leaving "get_pending_transactions" [payload { reduced_payload { commands { create_account { account_name: "a" domain_id: "test" public_key: "abcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcd" } } creator_account_id: "admin@test" created_time: 1633428778070 quorum: 2 } } signatures { public_key: "313a07e6384776ed95447710d15e59148473ccfc052a681317a72a69f2a49910" signature: "5247eed81d8c80784ad45face08c830314813063b0e318320db6e746b3669a56e1d7f6a8b9820806d006926a73d0d8367789e661c68db9fb42dd9516d8061c0c" } , payload { reduced_payload { commands { create_account { account_name: "b" domain_id: "test" public_key: "abcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcd" } } creator_account_id: "admin@test" created_time: 1633428780088 quorum: 2 } } signatures { public_key: "313a07e6384776ed95447710d15e59148473ccfc052a681317a72a69f2a49910" signature: "6dfe28fd49cd18e001fce5dc7766a42752bad71d073d22fd03e81907480259be16098e227e28024c5aca7ef9521c89c018874ec0e9c24fd3ccc1a74e413afd03" } , payload { reduced_payload { commands { create_account { account_name: "c" domain_id: "test" public_key: "abcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcd" } } creator_account_id: "admin@test" created_time: 1633428784104 quorum: 2 } } signatures { public_key: "313a07e6384776ed95447710d15e59148473ccfc052a681317a72a69f2a49910" signature: "a0511f7046ecb4426a0ddf49b1a86e6a8d05c36b40bb7dfd593d66079ded0dacda9b2b0bb443db7c6046022096804e630b248658deee12d160fa13868e048c0f" } ] ---------- Signing again as usual : ---------- Entering "sign_pending_transactions" Entering "get_pending_transactions" Leaving "get_pending_transactions" >>>>> Signing 0 transaction: payload { reduced_payload { commands { create_account { account_name: "a" domain_id: "test" public_key: "abcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcd" } } creator_account_id: "admin@test" created_time: 1633428778070 quorum: 2 } } signatures { public_key: "313a07e6384776ed95447710d15e59148473ccfc052a681317a72a69f2a49910" signature: "5247eed81d8c80784ad45face08c830314813063b0e318320db6e746b3669a56e1d7f6a8b9820806d006926a73d0d8367789e661c68db9fb42dd9516d8061c0c" } Entering "send_transaction_and_print_status" Transaction "create_account" hash = 66e9f7587338fc9a7f4ebd1095c1d293bdc7be6fc07a42c1416f26117761873a, creator = admin@test ('ENOUGH_SIGNATURES_COLLECTED', 9, 0) ('STATEFUL_VALIDATION_SUCCESS', 3, 0) ('COMMITTED', 5, 0) Leaving "send_transaction_and_print_status" Entering "send_transaction_and_print_status" Transaction "create_account" hash = 10295b459e9338e522f1f8f6094c7fb7c2500abbe31d399a7be84da2a1759f5d, creator = admin@test ('MST_PENDING', 8, 0) Leaving "send_transaction_and_print_status" Entering "send_transaction_and_print_status" Transaction "create_account" hash = 2d37a1664cdef7c602f8dcfcaf47c376712f4b9b9147eec3b7f5db89d9fb9b55, creator = admin@test ('MST_PENDING', 8, 0) Leaving "send_transaction_and_print_status" Leaving "sign_pending_transactions" ---------- Waiting : ---------- ---------- Checking pending transactions after waiting : ---------- Entering "get_pending_transactions" Leaving "get_pending_transactions" [payload { reduced_payload { commands { create_account { account_name: "b" domain_id: "test" public_key: "abcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcd" } } creator_account_id: "admin@test" created_time: 1633428780088 quorum: 2 } } signatures { public_key: "313a07e6384776ed95447710d15e59148473ccfc052a681317a72a69f2a49910" signature: "6dfe28fd49cd18e001fce5dc7766a42752bad71d073d22fd03e81907480259be16098e227e28024c5aca7ef9521c89c018874ec0e9c24fd3ccc1a74e413afd03" } , payload { reduced_payload { commands { create_account { account_name: "c" domain_id: "test" public_key: "abcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcd" } } creator_account_id: "admin@test" created_time: 1633428784104 quorum: 2 } } signatures { public_key: "313a07e6384776ed95447710d15e59148473ccfc052a681317a72a69f2a49910" signature: "a0511f7046ecb4426a0ddf49b1a86e6a8d05c36b40bb7dfd593d66079ded0dacda9b2b0bb443db7c6046022096804e630b248658deee12d160fa13868e048c0f" } ] ---------- Signing after waiting : ---------- Entering "sign_pending_transactions" Entering "get_pending_transactions" Leaving "get_pending_transactions" >>>>> Signing 0 transaction: payload { reduced_payload { commands { create_account { account_name: "b" domain_id: "test" public_key: "abcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcd" } } creator_account_id: "admin@test" created_time: 1633428780088 quorum: 2 } } signatures { public_key: "313a07e6384776ed95447710d15e59148473ccfc052a681317a72a69f2a49910" signature: "6dfe28fd49cd18e001fce5dc7766a42752bad71d073d22fd03e81907480259be16098e227e28024c5aca7ef9521c89c018874ec0e9c24fd3ccc1a74e413afd03" } Entering "send_transaction_and_print_status" Transaction "create_account" hash = 10295b459e9338e522f1f8f6094c7fb7c2500abbe31d399a7be84da2a1759f5d, creator = admin@test ('ENOUGH_SIGNATURES_COLLECTED', 9, 0) ('STATEFUL_VALIDATION_SUCCESS', 3, 0) ('COMMITTED', 5, 0) Leaving "send_transaction_and_print_status" >>>>> Rejecting 1 transaction: payload { reduced_payload { commands { create_account { account_name: "c" domain_id: "test" public_key: "abcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcd" } } creator_account_id: "admin@test" created_time: 1633428784104 quorum: 2 } } signatures { public_key: "313a07e6384776ed95447710d15e59148473ccfc052a681317a72a69f2a49910" signature: "a0511f7046ecb4426a0ddf49b1a86e6a8d05c36b40bb7dfd593d66079ded0dacda9b2b0bb443db7c6046022096804e630b248658deee12d160fa13868e048c0f" } Entering "send_transaction_and_print_status" Transaction "create_account" hash = 2d37a1664cdef7c602f8dcfcaf47c376712f4b9b9147eec3b7f5db89d9fb9b55, creator = admin@test ('MST_EXPIRED', 6, 0) ('STATEFUL_VALIDATION_FAILED', 2, 2) ('REJECTED', 4, 0) Leaving "send_transaction_and_print_status" Leaving "sign_pending_transactions"
Hopefully it would help:)
@kamilsa I've prepared script:
And I've set in
config
one minute:But the pending transactions are not disappearing, here is output:
Hopefully it would help:)