kaistshadow / blockchain-sim

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

공인인증브랜치(2) #352

Closed tkdlqm2 closed 3 years ago

tkdlqm2 commented 3 years ago

합의 알고리즘 모듈 개발

애뮬레이션 처리속도

tkdlqm2 commented 3 years ago

현재 pow, pos, pbft 모듈들이 합쳐진 develop 브랜치와 issue/352/cert_2 브랜치를 merge하여서 진행하는 중. 합의 알고리즘의 safety는 시뮬레이션된 노드들의 블록동기화 여부를 통해서 판단할 것이고, (예를들어 700노드의 종료시점에 블록 동기화가 모두 잘 이루어졌는지) liveness는 블록 생성 과정 또는 전파를 받는 과정에 시간을 파싱을 하여서 파싱된 시간을 보고 판단할 것임. (예를들어 이전 블록과 현재 블록의 생성시간 또는 전파 받은 시간 차가 15분 이상 발생하는지 여부 판단)

+) visualization 기능도 추가가 되어서 다음 메뉴얼 대로 실행을 할 경우 재현가능합니다.

2-1. 합의 알고리즘 모듈 개발 - POW How to reproduce

git ckecout issue/352/cert_2
python setup.py --bitcoin
cd cert_2/consensus_modules
npm install websocket finalhandler serve-static jsonpath
cd cert_2/consensus_modules/POW
python cert_pow.py pow.xml

Output console 밑의 output console은 shadow 실행을 하지 않고 전에 실행된 로그 파일들을 통해 나온 값이라, Run time이 0인 이유임.

Start POW consensus certification test ...
Start emulate POW consensus ... 
** Starting Shadow v1.12.1-273-gbf9b9561 2021-05-30 (built 2021-06-22) with GLib v2.56.4 and IGraph v0.7.1
** Stopping Shadow, returning code 0 (success)
Finish emulate POW consensus ...
-------------------------------------------------------------------------------
                         POW module test result
-------------------------------------------------------------------------------
                 Run time : 63
                 Simulate time : 100
                 Block count : 81
                 Fork count : 5
                 POW module safety result : Success
                 POW module liveness result : Success
-------------------------------------------------------------------------------

                 Starting visualization    -- > localhost:1337/frontend.html 

The script has launched the NodeJS web server for visualization.
You can see the visualization results of the configuration requested (i.e., pow.xml)
To see the results, connect to the server using address 'localhost:1337/frontend.html' in web browser.

Type Ctrl-C to terminate the NodeJS web server
tkdlqm2 commented 3 years ago

합의 알고리즘 모듈 테스트는 1000개 블록 생성 기준으로 평가가 이루어지기에, 1000개 블록 이상 생성을 기준으로 시뮬레이션 시간을 실행했음.

+) visualization 기능도 추가가 되어서 다음 메뉴얼 대로 실행을 할 경우 재현가능합니다.

2-2. 합의 알고리즘 모듈 개발 - POS

How to reproduce

git ckecout issue/352/cert_2
python setup.py --bitcoin
cd cert_2/consensus_modules
npm install websocket finalhandler serve-static jsonpath
cd cert_2/consensus_modules/POS
python cert_pos.py pos.xml

Output console

Start POS consensus certification test ...
Start emulate POS consensus ... 
** Starting Shadow v1.12.1-273-gbf9b9561 2021-05-30 (built 2021-06-22) with GLib v2.56.4 and IGraph v0.7.1
** Stopping Shadow, returning code 0 (success)
Finish emulate POS consensus ...
-------------------------------------------------------------------------------
                         POS module test result
-------------------------------------------------------------------------------
                 Run time : 3
                 Simulate time : 800
                 Block count : 1099
                 Fork count : 0
                 POS module safety result : Success
                 POS module liveness result : Success
-------------------------------------------------------------------------------

                 Starting visualization    -- > localhost:1337/frontend.html 

The script has launched the NodeJS web server for visualization.
You can see the visualization results of the configuration requested (i.e., pos.xml)
To see the results, connect to the server using address 'localhost:1337/frontend.html' in web browser.

Type Ctrl-C to terminate the NodeJS web server.
tkdlqm2 commented 3 years ago
  1. 애뮬레이션 처리 속도 테스트

테스트 합의 알고리즘 : POW 실행 노드 수 : 700 pownodes 애뮬레이션 결과 기준 : n개의 블록이 생성되었을 경우 시뮬레이션된 전체 노드가 n-6번째 블록을 모두 전파 받았는지 여부 테스트 성공 기준 : 시뮬레이션 시간이 실제 실행 시간보다 작아야 하며, 애뮬레이션 결과 기준이 부합하는 경우

How to reproduce

git checkout issue/352/cert_2
python setup.py --bitcoin
cd cert_2/emulation_processing
python cert_emulationProcessing.py

Output console

Start emulation processing certification test ...
Start POW blockchain simulation ... 
Success POW blockchain simulation ...
---------------------------------------------------
1. Real time : 384 Sec
2. Emulation time : 1000 Sec
3. Running nodes : 700 nodes
4. Successful emulated nodes : 700
---------------------------------------------------
     Certification test result : Success
tkdlqm2 commented 3 years ago
tkdlqm2 commented 3 years ago

2-3 합의 알고리즘 모듈 개발 - PBFT

How to reproduce

git checkout issue/352/cert_2
python setup.py --bitcoin
cd cert_2/consensus_modules;  npm install websocket finalhandler serve-static jsonpath
cd cert_2/consensus_modules/PBFT
python cert_pbft.py pbft.xml

Output

Start emulate PBFT consensus ... 
** Starting Shadow v1.12.1-273-gbf9b9561 2021-05-30 (built 2021-06-30) with GLib v2.56.4 and IGraph v0.7.1
** Stopping Shadow, returning code 0 (success)
Finish emulate PBFT consensus ...
Start emulate PBFT consensus ... 
Finish emulate PBFT consensus ...
-------------------------------------------------------------------------------
             PBFT module test result
-------------------------------------------------------------------------------
         Run time : 54
         Simulate time : 1000
         Block count : 1208
         Fork count : 0
         PBFT module safety result : Success
         PBFT module liveness result : Success
-------------------------------------------------------------------------------

         Starting visualization    -- > localhost:1337/frontend.html 

The script has launched the NodeJS web server for visualization.
You can see the visualization results of the configuration requested (i.e., pbft.xml)
To see the results, connect to the server using address 'localhost:1337/frontend.html' in web browser.

Type Ctrl-C to terminate the NodeJS web server.
tkdlqm2 commented 3 years ago

GUI - 블록해시 표시

image 그림의 블록 마다 적혀있는 숫자는 블록이 생성된 시간을 의미하는 것이고, 특정 블록에 마우스 커서를 대보면 해당 블록의 해시값이 그림에서 처럼 확인이 가능함. 블록 해시 값의 10번째까지의 문자임.

tkdlqm2 commented 3 years ago

pow mining process proof

python cert_pow.py pow.xml 

실행을 하면 실행한 경로에 pow_process_proof.txt 로그 파일이 생성이됨. 로그 파일은 각 노드마다 블록을 생성했을 때 이산 분포에서 뽑은 랜덤 시간과 blockid, blockhash 값이 파싱되어있음. 내용은 다음과 같음.

----------------------------------------------------------------------------------
/home/mong/cert/blockchain-sim/cert_2/consensus_modules/POW/shadow.data/hosts/pownode0/stdout-pownode0.NODE.1000.log
----------------------------------------------------------------------------------

blockhash:96b4cfd9e0207edc90043c03863e0c274d3d479b7fcf74404e68634e0f2a6871
blockID:725
pow_proof_process-> timer:5.23376
-----------------------
blockhash:a8190785de228124d315d021eacb4af4b8a22a7b8e0ee9356a953811320e420f
blockID:705
pow_proof_process-> timer:2.47778
-----------------------
blockhash:ff65bc7f68f440804faee86910c0c9dd2946d298ef6ce3adcb5ca1c031319ce7
blockID:695
pow_proof_process-> timer:5.11196
-----------------------
blockhash:8e50ea873f9bc1887ffa0b1bb8b19c2b54dca96e2f3ebc8638db468515b92d1e
blockID:688
pow_proof_process-> timer:0.624246
-----------------------
.
.
.

----------------------------------------------------------------------------------
tkdlqm2 commented 3 years ago

POS block 생성 프로세스 검증 과정 : 총 10개의 노드가 BLEEP POS합의 과정을 수행함. stakefile.txt 에 각 노드마다 stake 수치를 정의를함. 다음 pos_process_proof.txt 로그를 확인하면 0번째 노드는 30개를 stake, 두번째 노드는 60개를 stake한 것임. console로그 두번째 라인(?)은 파싱된 로그 파일을 프린트하였음. 그 다음 라인부터 파싱 로그에 해당되는 노드 id가 생성한 블록id와 블록 해시 값을 프린트하였으며, random number와 전체 stake양을 프린트 하였음. random value * total stake 를 하고 나서 나오는 결과 값이 첫번째 라인에서 각 노드마다 정의된 수치 중에 해당되는 값이 나오면, 그 노드가 블록을 생성하는 프로세스임.

Log file (pos_process_proof.txt)

Node0: 0 ~ 30
Node1 : 30 ~ 90
Node2 : 90 ~ 100
Node3 : 100 ~ 120
Node4 : 120 ~ 170
Node5 : 170 ~ 200
Node6 : 200 ~ 260
Node7 : 260 ~ 270
Node8 : 270 ~ 290
Node9 : 290 ~ 340
--------------------------------------------------------------------
/home/mong/cert/blockchain-sim/cert_2/consensus_modules/POS/shadow.data/hosts/posnode0/stdout-posnode0.NODE.1000.log
--------------------------------------------------------------------

Debug Selected:0
POS_process_proof -> number:0.0489869
POS_process_proof -> stakes.getTotal:340
randomValue * getTotalValue : 16.655546
blockID:12
blockhash:c34bdb14e0ce4def874071b1083a654928451d7ec9f135522396cb7fac7cf4ce
----------------------------------------
Debug Selected:0
POS_process_proof -> number:0.0220537
POS_process_proof -> stakes.getTotal:340
randomValue * getTotalValue : 7.498258
blockID:27
blockhash:62433356c422d7579ad2059227437f95d71cc29ca74a739d79ad4649af38e739
----------------------------------------
Debug Selected:0
POS_process_proof -> number:0.074356
POS_process_proof -> stakes.getTotal:340
randomValue * getTotalValue : 25.28104
blockID:35
blockhash:8f5f8833e8535ef09235505e62559fe59ed4f73b5852f2f65c8b7d4c50fd175d
----------------------------------------
.
.
.
.
tkdlqm2 commented 3 years ago

PBFT block 생성 프로세스 검증 과정 : pbft_process_proof.txt를 보면 첫번째 라인은 primary node의 output log file path임. 그 다음 라인에서는 pbft의 합의 프로세스에 대한 로그들임. 10개 노드로 pbft 합의 프로세스가 진행이 됨으로, 합의를 진행하는 단계마다 6개 이상의 합의를 이뤘다는 메시지를 수신할 경우 1~3번 과정이 페스 되는 것임.

1.Preprepare Debug StartPreprepare called

  1. Prepare Result_prePrepared:True
  2. Commit Result_commit:True
  3. 생성된 BlockHash

How to reproduce

cd cert_2/consensus_modules/PBFT;
python cert_pbft.py pbft.xml

Log output log (pbft_process_proof.txt)

------------------------------------------------------------------------------------------------
/home/mong/cert/blockchain-sim/cert_2/consensus_modules/PBFT/shadow.data/hosts/pbftnode0/stdout-pbftnode0.NODE.1000.log
--------------------------------------------------------------------------------------------------

Debug StartPreprepare called
predicate Prepared for block hash fd42873d950d0927fd5888b8a7edcdc85bb4801a5bbaf0c9d8b35751655bd2a2 become true with: { 4 5 6 7 8 9 }
predicate CommittedLocal for block hash fd42873d950d0927fd5888b8a7edcdc85bb4801a5bbaf0c9d8b35751655bd2a2 become true with: { 0 3 4 5 6 7 9 }
blockHash: 12f70d98b034c40c03b93b966672a8891368be4f355e3fd21ba7bc0a8171a7a8
-----------------------------
Debug StartPreprepare called
predicate Prepared for block hash 6ea210ffe560be91dc88ce63eb8973d5481c046feac8f665d9c63e05d8bfba05 become true with: { 4 5 6 7 8 9 }
predicate CommittedLocal for block hash 6ea210ffe560be91dc88ce63eb8973d5481c046feac8f665d9c63e05d8bfba05 become true with: { 0 3 4 5 6 7 9 }
blockHash: ec3e7451b732ad47010fb39bb8f78fd17edf77ffc9fe52052e6bcbc8c0479b80
-----------------------------
Debug StartPreprepare called
predicate Prepared for block hash 0ef656f6e20f97c6a32dfe055f5c729213f0039a0d0b0d462a48a98b5e4fdc1e become true with: { 3 4 5 6 7 9 }
predicate CommittedLocal for block hash 0ef656f6e20f97c6a32dfe055f5c729213f0039a0d0b0d462a48a98b5e4fdc1e become true with: { 0 3 4 5 6 7 9 }
blockHash: 42df15f3d19654f1c06169638fca9b860f293fe1439f41cb204fd8dd4dff5a2c
-----------------------------
.
.
.
tkdlqm2 commented 3 years ago

기존에 구현한 블록체인 애뮬레이션 처리 속도에서 피드백 받은 부분을 추가 수정하였습니다.


 Certification test result : Success
tkdlqm2 commented 3 years ago

애뮬레이션 처리 속도 100 - 700 초 결과 캡처 image

tkdlqm2 commented 3 years ago

143.248.38.82 서버에서 실행한 결과 정상 동작함.

image

Pasted Graphic 4
tkdlqm2 commented 3 years ago

수정한 내용은 다음과 같음. longest chain을 기준으로 마지막 여섯 번째의 블록 해시 값을 return 해주게 수정함.

def get_target_blockhash(target_path_file):
    lastsixblock_count = 6
    condition_value = 0
    blockhash = ""
    f = open(target_path_file, "r")
    for line in f.readlines()[::-1]:
        if condition_value == 0:
            result = line.find("========================")
            if result != -1:
                condition_value = 1
                continue

        if condition_value == 1:
            lastsixblock_count -= 1
            if lastsixblock_count == 0:
                f.close()
                blockhash = line[:-1]
                blockhash = blockhash.replace("[", "")
                blockhash = blockhash.replace("]", "")
                return blockhash

    f.close()
    print("Fail get last six block ... ")
    sys.exit(1)