Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow configuring max past time of transaction created_time #1776

Merged

Conversation

baziorek
Copy link
Member

@baziorek baziorek commented Dec 30, 2021

Description of the Change

This is PoC of adding possibility of configuration:
https://iroha.readthedocs.io/en/develop/develop/api/queries.html?highlight=24%20hours#validation
to be different than 24 hours before current time.

It is just PoC, so it needs to be consult with somebody.

Issue

Benefits

Possibility of additional param configuration

Possible Drawbacks

Default behavious is without changes, so I assume none drawbacks

Usage Examples or Tests [optional]

After changing the value in config the changes were tested with the code (20 hours vs 40 hours before current time):

import datetime
import os
import binascii
from iroha import IrohaCrypto, Iroha, IrohaGrpc, primitive_pb2
from functools import wraps


IROHA_HOST_ADDR = os.getenv('IROHA_HOST_ADDR', 'localhost')
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)


DOMAIN = 'test'

private_key = '1234567890123456789012345678901234567890123456789012345678901234'
public_key = IrohaCrypto.derive_public_key(private_key)


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}"\n')
        return result

    return tracer

@trace
def create_account(user_account_short_id: str, user_public_key: str, created_time: datetime):
    created_time_ts = get_timestamp_milliseconds(created_time)
    tx = iroha_admin.transaction([
        iroha_admin.command('CreateAccount', account_name=user_account_short_id, domain_id=DOMAIN,
                            public_key=user_public_key)
    ], created_time=created_time_ts)
    IrohaCrypto.sign_transaction(tx, ADMIN_PRIVATE_KEY)
    send_transaction_and_print_status(tx)


def send_transaction_and_print_status(transaction):
    hex_hash = binascii.hexlify(IrohaCrypto.hash(transaction))
    print(f'Transaction "{get_command_from_tx(transaction)}" hash = {hex_hash}, '
          f'creator = {transaction.payload.reduced_payload.creator_account_id}')
    net.send_tx(transaction)
    for status in net.tx_status_stream(transaction):
        print('\t\t', status)
    result = status[0]
    if result != 'COMMITTED':
        raise Exception(f'Command {get_command_from_tx(transaction)} failed! {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]

@trace
def get_account_transactions(iroha_connection, account_id: str, account_key: str):
    query = iroha_connection.query('GetAccountTransactions', account_id=account_id, page_size=10)

    IrohaCrypto.sign_query(query, account_key)

    response = net.send_query(query)
    print(f'\n----- Transactions of account {account_id}:\n', response)


def get_timestamp_milliseconds(dt: datetime.datetime):
    ts = dt.timestamp()
    return round(ts*1000)


if __name__ == '__main__':
    current_time = datetime.datetime.now()
    old_time = current_time - datetime.timedelta(hours=23)
    even_older_time = current_time - datetime.timedelta(hours=40)

    print(current_time, "miliseconds:", get_timestamp_milliseconds(current_time))
    print(old_time, "miliseconds:", get_timestamp_milliseconds(old_time))
    print(even_older_time, "miliseconds:", get_timestamp_milliseconds(even_older_time))

    create_account(user_account_short_id='a1', user_public_key=public_key, created_time=current_time)
    create_account(user_account_short_id='a2', user_public_key=public_key, created_time=old_time)
    create_account(user_account_short_id='a3', user_public_key=public_key, created_time=even_older_time)

    get_account_transactions(iroha_admin, ADMIN_ACCOUNT_ID, ADMIN_PRIVATE_KEY)

Alternate Designs [optional]

@baziorek baziorek added Enhancement New feature or request help wanted Extra attention is needed question Further information is requested 1.x labels Dec 30, 2021
@baziorek baziorek force-pushed the configurable_max_past_created_time branch 2 times, most recently from 114831d to 32b03a8 Compare December 30, 2021 18:13
@baziorek baziorek requested a review from iceseer January 3, 2022 20:27
@baziorek baziorek marked this pull request as ready for review January 3, 2022 20:27
docs/source/configure/index.rst Outdated Show resolved Hide resolved
irohad/main/irohad.cpp Outdated Show resolved Hide resolved
@baziorek baziorek self-assigned this Jan 13, 2022
@baziorek baziorek changed the title Added possibility to configure max past time of transaction created_time Draft: Added possibility to configure max past time of transaction created_time Apr 12, 2022
@appetrosyan appetrosyan changed the title Draft: Added possibility to configure max past time of transaction created_time Draft: Allow configuring max past time of transaction created_time Jun 24, 2022
@appetrosyan appetrosyan marked this pull request as draft July 28, 2022 06:33
@appetrosyan appetrosyan changed the title Draft: Allow configuring max past time of transaction created_time Allow configuring max past time of transaction created_time Jul 28, 2022
docs/source/configure/index.rst Outdated Show resolved Hide resolved
irohad/main/irohad.cpp Outdated Show resolved Hide resolved
irohad/ordering/impl/batches_cache.cpp Outdated Show resolved Hide resolved
shared_model/validators/field_validator.cpp Outdated Show resolved Hide resolved
@baziorek baziorek temporarily deployed to test-env August 11, 2022 10:58 Inactive
@baziorek baziorek temporarily deployed to test-env August 11, 2022 10:58 Inactive
@baziorek baziorek temporarily deployed to test-env August 11, 2022 10:58 Inactive
@baziorek baziorek temporarily deployed to test-env August 11, 2022 10:58 Inactive
@baziorek
Copy link
Member Author

@appetrosyan Thanks for the review. I haven't forgotten about the PR. In September I should be able to fight with the PR again and correct all suggestions. In August it is hard time for me:(.

@iceseer iceseer force-pushed the develop branch 2 times, most recently from ee7a58c to 3ac5147 Compare September 13, 2022 05:42
@baziorek baziorek temporarily deployed to test-env September 26, 2022 19:56 Inactive
@baziorek baziorek temporarily deployed to test-env September 26, 2022 19:56 Inactive
@baziorek baziorek temporarily deployed to test-env September 26, 2022 19:56 Inactive
@baziorek baziorek temporarily deployed to test-env October 17, 2022 15:19 Inactive
@baziorek baziorek temporarily deployed to test-env October 17, 2022 15:19 Inactive
@baziorek baziorek temporarily deployed to test-env October 17, 2022 15:19 Inactive
@baziorek baziorek temporarily deployed to test-env October 17, 2022 15:19 Inactive
@baziorek baziorek temporarily deployed to test-env October 18, 2022 09:54 Inactive
@baziorek baziorek temporarily deployed to test-env October 18, 2022 09:54 Inactive
@baziorek baziorek temporarily deployed to test-env October 18, 2022 09:54 Inactive
@baziorek baziorek temporarily deployed to test-env October 18, 2022 09:54 Inactive
@baziorek
Copy link
Member Author

I pressed "Update branch" - hopefully it will help. Could somebody run test-env again please?

appetrosyan
appetrosyan previously approved these changes Oct 19, 2022
@iceseer
Copy link
Contributor

iceseer commented Oct 19, 2022

std::chrono::duration seems better for this purpose.

iceseer
iceseer previously approved these changes Oct 19, 2022
@appetrosyan appetrosyan dismissed stale reviews from iceseer and themself via 4a3a8a8 October 20, 2022 07:46
@appetrosyan appetrosyan force-pushed the configurable_max_past_created_time branch 2 times, most recently from 590d194 to 51b68e1 Compare October 20, 2022 07:52
Signed-off-by: Aleksandr Petrosyan <a-p-petrosyan@yandex.ru>
@appetrosyan appetrosyan force-pushed the configurable_max_past_created_time branch 2 times, most recently from 7dd007c to d844cd4 Compare October 20, 2022 07:55
@appetrosyan appetrosyan merged commit b8ddc67 into hyperledger:develop Oct 20, 2022
@baziorek baziorek deleted the configurable_max_past_created_time branch November 11, 2022 11:02
6r1d pushed a commit to 6r1d/iroha that referenced this pull request Aug 28, 2023
@nxsaken nxsaken added the iroha1 The legacy version of Iroha. label Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.x Enhancement New feature or request help wanted Extra attention is needed iroha1 The legacy version of Iroha. question Further information is requested
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants