-
Notifications
You must be signed in to change notification settings - Fork 664
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import sys | ||
import time | ||
|
||
sys.path.append('lib') | ||
|
||
from cluster import start_cluster | ||
from peer import * | ||
from proxy import ProxyHandler | ||
|
||
from multiprocessing import Value | ||
|
||
TIMEOUT = 120 | ||
NODES = 9 | ||
ignored_messages = set() | ||
max_height = Value('i', 0) | ||
|
||
|
||
class Handler(ProxyHandler): | ||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
|
||
async def handle(self, msg, fr, to): | ||
if msg.enum == 'Block': | ||
h = msg.Block.BlockV1.header.BlockHeaderV2.inner_lite.height | ||
if h > max_height.value: | ||
max_height.value = h | ||
print(h, fr, to, msg, msg.Block.enum) | ||
tpl = (h, fr, to) | ||
|
||
if h == NODES - 1 and to < (NODES - 1) / 2 and tpl not in ignored_messages: | ||
ignored_messages.add(tpl) | ||
print("skipping msg from %d to %d" % (fr, to)) | ||
return False | ||
|
||
return True | ||
|
||
|
||
if __name__ == '__main__': | ||
start_cluster(NODES, 0, 1, None, [], {}, message_handler=Handler) | ||
|
||
start = time.time() | ||
while True: | ||
print("max_height", max_height.value) | ||
if time.time() - start >= TIMEOUT or max_height.value > 3 * NODES: | ||
print("DONE") | ||
break | ||
time.sleep(1) | ||
|
||
assert max_height.value > 3 * NODES |