@@ -817,7 +817,7 @@ def makeReservedEvmAddress(account):
817817 time1 = time .time ()
818818 res = json .loads (recevied_msg )
819819 block_json = res ["params" ]["result" ]
820- last_ws_evm_blocknum = (int )( block_json ["number" ])
820+ last_ws_evm_blocknum = (block_json ["number" ])
821821 hash = block_json ["hash" ]
822822 parent_hash = block_json ["parentHash" ]
823823 Utils .Print ("received block {0} from websocket, hash={1}..., parent={2}..." .format (last_ws_evm_blocknum , hash [0 :8 ], parent_hash [0 :8 ]))
@@ -912,19 +912,21 @@ def makeReservedEvmAddress(account):
912912 # receive blocks from websocket server
913913 Utils .Print ("receive some blocks from websocket up to the latest blocks, which should cover the expected diverage point" );
914914 time .sleep (1.0 )
915+ hash_dict = {}
915916 while True :
916917 time0 = time .time ()
917918 recevied_msg = ws .recv ()
918919 time1 = time .time ()
919920 res = json .loads (recevied_msg )
920921 block_json = res ["params" ]["result" ]
921- last_ws_evm_blocknum = (int )( block_json ["number" ])
922+ last_ws_evm_blocknum = (block_json ["number" ])
922923 hash = block_json ["hash" ]
923924 parent_hash = block_json ["parentHash" ]
924925 Utils .Print ("received block {0} from websocket, hash={1}..., parent={2}..." .format (last_ws_evm_blocknum , hash [0 :8 ], parent_hash [0 :8 ]))
925926 if block_count > 0 :
926927 assert (len (parent_hash ) > 0 and parent_hash == prev_hash )
927928 prev_hash = hash
929+ hash_dict [hash ] = last_ws_evm_blocknum
928930 block_count = block_count + 1
929931 if (time1 - time0 > 0.9 ):
930932 break
@@ -1053,23 +1055,34 @@ def makeReservedEvmAddress(account):
10531055
10541056 # try to receive some blocks from websocket server
10551057 Utils .Print ("receive blocks from websocket up to the latest blocks" )
1058+ fork_switched = False
1059+ fork_hash = ""
10561060 while True :
10571061 time0 = time .time ()
10581062 recevied_msg = ws .recv ()
10591063 time1 = time .time ()
10601064 res = json .loads (recevied_msg )
10611065 block_json = res ["params" ]["result" ]
1062- last_ws_evm_blocknum = (int )( block_json ["number" ])
1066+ last_ws_evm_blocknum = (block_json ["number" ])
10631067 hash = block_json ["hash" ]
10641068 parent_hash = block_json ["parentHash" ]
10651069 Utils .Print ("received block {0} from websocket, hash={1}..., parent={2}..." .format (last_ws_evm_blocknum , hash [0 :8 ], parent_hash [0 :8 ]))
10661070 if block_count > 0 :
1067- assert (len (parent_hash ) > 0 and parent_hash == prev_hash )
1071+ assert (len (parent_hash ) > 0 )
1072+ if parent_hash != prev_hash :
1073+ assert (parent_hash in hash_dict )
1074+ fork_switched = True
1075+ fork_hash = parent_hash
1076+ Utils .Print ("EVM chain fork switch detected, block linkable" )
10681077 prev_hash = hash
1078+ hash_dict [hash ] = last_ws_evm_blocknum
10691079 block_count = block_count + 1
10701080 if time1 - time0 > 0.9 :
10711081 break ;
10721082
1083+ assert (fork_switched == True , "no EVM chain fork switch detected" )
1084+ Utils .Print ("fork swtiched at hash {0}" .format (fork_hash ))
1085+
10731086 blockProducers0 = []
10741087 blockProducers1 = []
10751088 ws .close ()
0 commit comments