kaistshadow / blockchain-sim

Scalable blockchain simulator/emulator running on shadow simulator
MIT License
9 stars 1 forks source link

FF - 3 client connection test #283

Closed tkdlqm2 closed 3 years ago

tkdlqm2 commented 3 years ago

FF - 3 client connection test

시뮬레이션 시 bitcoin 플러그인과 connection만 될뿐 노드의 역할은 하지 않음. 다만 bitcoin 플러그인으로부터 transaction, propagation, block propagation에 대한 수신을 함.

시뮬레이션 후, 각 노드들의 플러그인 결과 로그에서 client의 ip address 로그를 필터링으로 연결 유무를 확인하여, 로그가 있으면 return 0 아닐 경우 return 1임.

Originally posted by @tkdlqm2 in https://github.com/kaistshadow/blockchain-sim/issues/278#issuecomment-809904132

tkdlqm2 commented 3 years ago

BLEEPeval/tpstest-app/prototype 디렉토리에는 one_setmining 기능을 하는 rpc.so 플러그인 파일을 만들어주는 로직이 없음. BLEEPemul/emulation 디렉토리의 rpc.so 플러그인 파일을 copy하는 빌드 시스템을 만들어 놓음.

add_custom_target(emulation-one-node-mine-plugin ALL
        COMMAND g++ -o rpc.so one_node_setmine.cpp ../../testlibs/rpc_client.cpp -ljsoncpp -lcurl -lssl -shared -fPIC -Wl,-rpath=${CMAKE_CURRENT_SOURCE_DIR}/../../Install/curl_7.70.0/lib -L${CMAKE_CURRENT_SOURCE_DIR}/../../Install/curl_7.70.0/lib -g
        COMMAND cp rpc.so ${CMAKE_SOURCE_DIR}/BLEEPeval/tpstest-app/prototype
        COMMAND g++ -o transaction.so transaction.cpp  ../../testlibs/rpc_client.cpp -ljsoncpp -lcurl -lssl -shared -fPIC -Wl,-rpath=${CMAKE_CURRENT_SOURCE_DIR}/../../Install/curl_7.70.0/lib -L${CMAKE_CURRENT_SOURCE_DIR}/../../Install/curl_7.70.0/lib -g
        WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})

위 소스코드는 emulation/CMakeLists.txt 임.

tkdlqm2 commented 3 years ago
# 이 테스트를 통해 실행될 플러그인 중에 monitor node 플러그인에 대한 테스트임.
# monitor 노드는 시뮬레이션되는 블록체인의 모든 노드의 블록 전파를 관장함.
# 현재 테스트에서는 시뮬레이션되는 블록체인의 노드와 monitor node와의 conncetion test임. 
def monitor_connection_test(plugin_output_files, abs_path, node_count):
    condition_count = 0
    # 실행되는 node 수 + 
    node_count = int(node_count) + 1
    for i in range(0,len(plugin_output_files)):
        result = plugin_output_files[i].find("monitor")
        if result != -1:
            f = open(plugin_output_files[i], "r")
            while True:
                line = f.readline()
                if not line: break
                result = line.find("Socket is successfully connected")
                if result != -1:
                    condition_count += 1
                    if condition_count == node_count:
                        f.close()
                        break
            f.close()

        if condition_count == node_count:
            print("Success monitor connection test ... ")
            sys.exit(0)

    print("Fail monitor conncetion test ... ")
    print("only %d node connection ... " %condition_count)
    sys.exit(1)
# TxGenerator 가 node connection 과정에서 xml파일로부터 정의된 노드의 IP 주소를 기준으로 필터링 시작.

def TxGenerator_connection_test(plugin_output_files, xmlfile, node_count):
    IP_list = utils.get_address_list(xmlfile)
    condition_count = 0
    for i in range(0,len(plugin_output_files)):
        result = plugin_output_files[i].find("txgenerator/stdout-txgenerator.BITCOINTPS_TESTER.1000.log")
        if result != -1:
            f = open(plugin_output_files[i], "r")
            while True:
                line = f.readline()
                if not line: break
                result = line.find("addTarget")
                if result != -1:
                    for i in range(0,len(IP_list)):
                        result = line.find(IP_list[i])
                        if result != -1:
                            condition_count += 1
                            if condition_count == 2:
                                f.close()
                                print("Success txGenrator connection test ...")
                                sys.exit(0)
                            else:
                                break
            f.close()
    print(condition_count)
    print("Fail txGenerator connection test ... ")
    sys.exit(1)
tkdlqm2 commented 3 years ago

How to reproduce

  1. git checkout issue/283
  2. python setup.py --test