Created
March 18, 2019 12:08
-
-
Save igor-egorov/fe4c861abefdaa955daf952137b03024 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "obj_counter.hpp" | |
class Block : public ::google::protobuf::Message, public ::ObjCounter<Block> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"block_store_path" : "/tmp/block_store/", | |
"torii_port" : 50051, | |
"internal_port" : 10001, | |
"pg_opt" : "host=localhost port=5432 user=postgres password=mysecretpassword", | |
"max_proposal_size" : 1000, | |
"proposal_delay" : 5000, | |
"vote_delay" : 5000, | |
"mst_enable" : false, | |
"mst_expiration_time" : 1440, | |
"max_rounds_delay": 100, | |
"stale_stream_max_rounds": 2, | |
"log":{"level":"critical"} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# | |
# Copyright Soramitsu Co., Ltd. All Rights Reserved. | |
# SPDX-License-Identifier: Apache-2.0 | |
# | |
from iroha import Iroha, IrohaGrpc | |
from iroha import IrohaCrypto | |
import binascii | |
import sys | |
import time | |
import os | |
if sys.version_info[0] < 3: | |
raise Exception('Python 3 or a more recent version is required.') | |
IROHA_HOST_ADDR = os.getenv('IROHA_HOST_ADDR', '127.0.0.1') | |
IROHA_PORT = os.getenv('IROHA_PORT', '50051') | |
ADMIN_ACCOUNT_ID = os.getenv('ADMIN_ACCOUNT_ID', 'admin@test') | |
ADMIN_PRIVATE_KEY = os.getenv( | |
'ADMIN_PRIVATE_KEY', 'f101537e319568c765b2cc89698325604991dca57b9716b58016b253506cab70') | |
iroha = Iroha(ADMIN_ACCOUNT_ID) | |
net = IrohaGrpc('{}:{}'.format(IROHA_HOST_ADDR, IROHA_PORT)) | |
def trace(func): | |
""" | |
A decorator for tracing methods' begin/end execution points | |
""" | |
def tracer(*args, **kwargs): | |
name = func.__name__ | |
print('\tEntering "{}"'.format(name)) | |
result = func(*args, **kwargs) | |
print('\tLeaving "{}"'.format(name)) | |
return result | |
return tracer | |
@trace | |
def get_blocks(): | |
""" | |
Subscribe to blocks stream from the network | |
:return: | |
""" | |
query = iroha.blocks_query() | |
IrohaCrypto.sign_query(query, ADMIN_PRIVATE_KEY) | |
for response in net.send_blocks_stream_query(query): | |
response_kind = response.WhichOneof('response') | |
if response_kind == 'block_error_response': | |
raise str(response) | |
print('block {}'.format(response.block_response.block.block_v1.payload.height)) | |
time.sleep(10) | |
# for tx in response.block_response.block.block_v1.payload.transactions: | |
# print(binascii.hexlify(IrohaCrypto.hash(tx))) | |
# for tx in response.block_response.block.block_v1.payload.rejected_transactions_hashes: | |
# print('rejected ' + tx) | |
get_blocks() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Copyright Soramitsu Co., Ltd. All Rights Reserved. | |
* SPDX-License-Identifier: Apache-2.0 | |
*/ | |
#ifndef IROHA_OBJ_COUNTER_HPP | |
#define IROHA_OBJ_COUNTER_HPP | |
#include <atomic> | |
#include <iostream> | |
#include <mutex> | |
#include <sstream> | |
template <typename T> | |
struct ObjCounter { | |
static std::atomic<size_t> objects_created; | |
static std::atomic<size_t> objects_alive; | |
ObjCounter() noexcept { | |
objects_created.fetch_add(1, std::memory_order_relaxed); | |
objects_alive.fetch_add(1, std::memory_order_relaxed); | |
std::cout << "\033[1;31m" << typeid(T).name() << " created\033[0m" | |
<< std::endl; | |
} | |
static std::string getStats() { | |
std::lock_guard<std::mutex> lock(get_stats_mu_); | |
std::stringstream ss; | |
ss << typeid(T).name() << ": created " | |
<< objects_created.load(std::memory_order_relaxed) | |
<< ", alive :" << objects_alive.load(std::memory_order_relaxed); | |
return ss.str(); | |
} | |
protected: | |
~ObjCounter() // objects should never be removed through pointers of this | |
// type | |
{ | |
objects_alive.fetch_add(-1, std::memory_order_relaxed); | |
std::cout << "\033[1;31m" << typeid(T).name() << " destructed\033[0m" | |
<< std::endl; | |
} | |
private: | |
static std::mutex get_stats_mu_; | |
}; | |
template <typename T> | |
std::atomic<size_t> ObjCounter<T>::objects_created(0); | |
template <typename T> | |
std::atomic<size_t> ObjCounter<T>::objects_alive(0); | |
template <typename T> | |
std::mutex ObjCounter<T>::get_stats_mu_; | |
#endif // IROHA_OBJ_COUNTER_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: irohad/torii/impl/query_service.cpp | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
--- irohad/torii/impl/query_service.cpp (revision 04684185ba208efc04bb6a6de9ca79743e2606b8) | |
+++ irohad/torii/impl/query_service.cpp (date 1552909892000) | |
@@ -102,8 +102,9 @@ | |
auto proto_block_response = static_cast< | |
const shared_model::proto::BlockResponse | |
&>(block_response); | |
- writer->Write( | |
+ auto result = writer->Write( | |
proto_block_response.getTransport()); | |
+ log_->critical("{} writer result {}", result, iroha::protocol::Block::getStats()); | |
}, | |
[this, writer, request]( | |
const shared_model::interface:: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# Transactions generator for infinite block stream | |
# | |
# Copyright Soramitsu Co., Ltd. All Rights Reserved. | |
# SPDX-License-Identifier: Apache-2.0 | |
# | |
from iroha import Iroha, IrohaGrpc | |
from iroha import IrohaCrypto | |
import os | |
import sys | |
import time | |
import uuid | |
import binascii | |
import signal | |
TERMINATE = False | |
def signal_handler(signal, frame): | |
global TERMINATE | |
TERMINATE = True | |
print('Terminating') | |
signal.signal(signal.SIGINT, signal_handler) | |
IROHA_HOST_ADDR = os.getenv('IROHA_HOST_ADDR', '127.0.0.1') | |
IROHA_PORT = os.getenv('IROHA_PORT', '50051') | |
ADMIN_ACCOUNT_ID = os.getenv('ADMIN_ACCOUNT_ID', 'admin@test') | |
ADMIN_PRIVATE_KEY = os.getenv( | |
'ADMIN_PRIVATE_KEY', 'f101537e319568c765b2cc89698325604991dca57b9716b58016b253506cab70') | |
iroha = Iroha(ADMIN_ACCOUNT_ID) | |
net = IrohaGrpc('{}:{}'.format(IROHA_HOST_ADDR, IROHA_PORT)) | |
def send_tx(): | |
rand_name = uuid.uuid4().hex | |
rand_key = IrohaCrypto.private_key() | |
domain = ADMIN_ACCOUNT_ID.split('@')[1] | |
tx = iroha.transaction([ | |
iroha.command('CreateAccount', | |
account_name=rand_name, | |
domain_id=domain, | |
public_key=rand_key) | |
]) | |
IrohaCrypto.sign_transaction(tx, ADMIN_PRIVATE_KEY) | |
net.send_tx(tx) | |
print(binascii.hexlify(IrohaCrypto.hash(tx))) | |
while not TERMINATE: | |
send_tx() | |
time.sleep(0.1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
watch -n 1 ls /tmp/block_store |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment