Skip to content

Commit

Permalink
Merge pull request #9409 from MinaProtocol/fix/vrf-evaluation-subproc…
Browse files Browse the repository at this point in the history
…ess-1.2.0

VRF evaluation subprocess on 1.2.0
  • Loading branch information
lk86 authored Oct 13, 2021
2 parents 4689c3b + 36ec994 commit 1f98b8b
Show file tree
Hide file tree
Showing 50 changed files with 1,211 additions and 427 deletions.
146 changes: 72 additions & 74 deletions dockerfiles/puppeteer-context/mina_daemon_puppeteer.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,32 +29,32 @@
HTTPServer.timeout = 1

class MockRequestHandler(BaseHTTPRequestHandler):
def do_GET(s):
s.send_response(200)
s.send_header('Content-Type', 'text/html')
s.end_headers()
s.wfile.write(b'<html><body>The daemon is currently offline.<br/><i>This broadcast was brought to you by the puppeteer mock server</i></body></html>')
def do_GET(s):
s.send_response(200)
s.send_header('Content-Type', 'text/html')
s.end_headers()
s.wfile.write(b'<html><body>The daemon is currently offline.<br/><i>This broadcast was brought to you by the puppeteer mock server</i></body></html>')

# just nooping on this signal suffices, since merely trapping it will cause
# `signal.pause()` to resume
def handle_child_termination(signum, frame):
pass
pass

def handle_start_request(signum, frame):
global active_daemon_request
active_daemon_request = True
global active_daemon_request
active_daemon_request = True

def handle_stop_request(signum, frame):
global inactive_daemon_request
inactive_daemon_request = True
global inactive_daemon_request
inactive_daemon_request = True

def get_child_processes(pid):
result = subprocess.run(
['ps', '-o', 'pid=', '--ppid', str(pid)],
stdout=subprocess.PIPE
)
output = result.stdout.decode('ascii')
return list(map(int, filter(lambda s: len(s) > 0, output.split(' '))))
result = subprocess.run(
['ps', '-o', 'pid=', '--ppid', str(pid)],
stdout=subprocess.PIPE
)
output = result.stdout.decode('ascii')
return list(map(int, filter(lambda s: len(s) > 0, output.split(' '))))

def pid_is_running(pid):
try:
Expand All @@ -68,81 +68,79 @@ def wait_for_pid(pid):
time.sleep(0.25)

def start_daemon():
global mina_process
with open('mina.log', 'a') as f:
mina_process = subprocess.Popen(
['mina'] + daemon_args,
stdout=f,
stderr=subprocess.STDOUT
)
Path('daemon-active').touch()
global mina_process
with open('mina.log', 'a') as f:
mina_process = subprocess.Popen(
['mina'] + daemon_args,
stdout=f,
stderr=subprocess.STDOUT
)
Path('daemon-active').touch()

def stop_daemon():
global mina_process
mina_process.send_signal(signal.SIGTERM)
global mina_process
mina_process.send_signal(signal.SIGTERM)

child_pids = get_child_processes(mina_process.pid)
mina_process.wait()
for child_pid in child_pids:
wait_for_pid(child_pid)
Path('daemon-active').unlink()
mina_process = None
child_pids = get_child_processes(mina_process.pid)
mina_process.wait()
for child_pid in child_pids:
wait_for_pid(child_pid)
Path('daemon-active').unlink()
mina_process = None

# technically, doing the loops like this will eventually result in a stack overflow
# however, you would need to do a lot of starts and stops to hit this condition

def inactive_loop():
global active_daemon_request
global active_daemon_request

try:
server = HTTPServer(('0.0.0.0', 3085), MockRequestHandler)
while True:
server.handle_request()
signal.sigtimedwait(ALL_SIGNALS, 0)
if active_daemon_request:
start_daemon()
active_daemon_request = False
break
finally:
server.shutdown()
server.handle_request()
signal.sigtimedwait(ALL_SIGNALS, 0)
if active_daemon_request:
start_daemon()
active_daemon_request = False
server.server_close()
break

active_loop()
active_loop()

def active_loop():
global mina_process, inactive_daemon_request
global mina_process, inactive_daemon_request

while True:
signal.pause()
status = mina_process.poll()
if status != None:
cleanup_and_exit(status)
elif inactive_daemon_request:
stop_daemon()
inactive_daemon_request = False
break
while True:
signal.pause()
status = mina_process.poll()
if status != None:
cleanup_and_exit(status)
elif inactive_daemon_request:
stop_daemon()
inactive_daemon_request = False
break

inactive_loop()
inactive_loop()

def cleanup_and_exit(status):
time.sleep(5)
tail_process.terminate()
tail_process.wait()
sys.exit(status)
time.sleep(5)
tail_process.terminate()
tail_process.wait()
sys.exit(status)

if __name__ == '__main__':
signal.signal(signal.SIGCHLD, handle_child_termination)
signal.signal(signal.SIGUSR1, handle_stop_request)
signal.signal(signal.SIGUSR2, handle_start_request)

Path('.mina-config').mkdir(exist_ok=True)
Path('mina.log').touch()
Path('.mina-config/mina-prover.log').touch()
Path('.mina-config/mina-verifier.log').touch()
Path('.mina-config/mina-best-tip.log').touch()

# currently does not handle tail process dying
tail_process = subprocess.Popen(
['tail', '-q', '-f', 'mina.log', '-f', '.mina-config/mina-prover.log', '-f', '.mina-config/mina-verifier.log', '-f' , '.mina-config/mina-best-tip.log']
)

inactive_loop()
signal.signal(signal.SIGCHLD, handle_child_termination)
signal.signal(signal.SIGUSR1, handle_stop_request)
signal.signal(signal.SIGUSR2, handle_start_request)

Path('.mina-config').mkdir(exist_ok=True)
Path('mina.log').touch()
Path('.mina-config/mina-prover.log').touch()
Path('.mina-config/mina-verifier.log').touch()
Path('.mina-config/mina-best-tip.log').touch()

# currently does not handle tail process dying
tail_process = subprocess.Popen(
['tail', '-q', '-f', 'mina.log', '-f', '.mina-config/mina-prover.log', '-f', '.mina-config/mina-verifier.log', '-f' , '.mina-config/mina-best-tip.log']
)

inactive_loop()
1 change: 1 addition & 0 deletions src/config/debug.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@
[%%import "/src/config/fork.mlh"]
[%%import "/src/config/features/dev.mlh"]
[%%undef compaction_interval]
[%%define vrf_poll_interval 0]
1 change: 1 addition & 0 deletions src/config/dev.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@
[%%import "/src/config/fork.mlh"]
[%%import "/src/config/features/dev.mlh"]
[%%undef compaction_interval]
[%%define vrf_poll_interval 0]
1 change: 1 addition & 0 deletions src/config/dev_medium_curves.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@
[%%import "/src/config/fork.mlh"]
[%%import "/src/config/features/dev.mlh"]
[%%undef compaction_interval]
[%%define vrf_poll_interval 0]
1 change: 1 addition & 0 deletions src/config/dev_snark.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@
[%%import "/src/config/fork.mlh"]
[%%import "/src/config/features/dev.mlh"]
[%%undef compaction_interval]
[%%define vrf_poll_interval 0]
1 change: 1 addition & 0 deletions src/config/devnet.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@
[%%import "/src/config/features/public_testnet.mlh"]
(* 2*block_window_duration *)
[%%define compaction_interval 360000]
[%%define vrf_poll_interval 5000]
1 change: 1 addition & 0 deletions src/config/fake_hash.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@
[%%import "/src/config/fork.mlh"]
[%%import "/src/config/features/dev.mlh"]
[%%undef compaction_interval]
[%%define vrf_poll_interval 0]
1 change: 1 addition & 0 deletions src/config/fuzz_medium.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@
[%%import "/src/config/fork.mlh"]
[%%import "/src/config/features/dev.mlh"]
[%%undef compaction_interval]
[%%define vrf_poll_interval 0]
1 change: 1 addition & 0 deletions src/config/fuzz_small.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@
[%%import "/src/config/fork.mlh"]
[%%import "/src/config/features/dev.mlh"]
[%%undef compaction_interval]
[%%define vrf_poll_interval 0]
1 change: 1 addition & 0 deletions src/config/mainnet.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@
[%%import "/src/config/features/mainnet.mlh"]
(* 2*block_window_duration *)
[%%define compaction_interval 360000]
[%%define vrf_poll_interval 5000]
1 change: 1 addition & 0 deletions src/config/nonconsensus_medium_curves.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@
[%%import "/src/config/fork.mlh"]
[%%import "/src/config/features/dev.mlh"]
[%%undef compaction_interval]
[%%define vrf_poll_interval 5000]
1 change: 1 addition & 0 deletions src/config/print_versioned_types.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@
[%%import "/src/config/fork.mlh"]
[%%import "/src/config/features/dev.mlh"]
[%%undef compaction_interval]
[%%define vrf_poll_interval 0]
1 change: 1 addition & 0 deletions src/config/test_archive_processor.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@
[%%import "/src/config/fork.mlh"]
[%%import "/src/config/features/dev.mlh"]
[%%undef compaction_interval]
[%%define vrf_poll_interval 0]
1 change: 1 addition & 0 deletions src/config/test_postake.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@
[%%import "/src/config/fork.mlh"]
[%%import "/src/config/features/dev.mlh"]
[%%undef compaction_interval]
[%%define vrf_poll_interval 5000]
1 change: 1 addition & 0 deletions src/config/test_postake_catchup.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@
[%%import "/src/config/fork.mlh"]
[%%import "/src/config/features/dev.mlh"]
[%%undef compaction_interval]
[%%define vrf_poll_interval 0]
1 change: 1 addition & 0 deletions src/config/test_postake_five_even_txns.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@
[%%import "/src/config/fork.mlh"]
[%%import "/src/config/features/dev.mlh"]
[%%undef compaction_interval]
[%%define vrf_poll_interval 0]
1 change: 1 addition & 0 deletions src/config/test_postake_full_epoch.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@
[%%import "/src/config/fork.mlh"]
[%%import "/src/config/features/dev.mlh"]
[%%undef compaction_interval]
[%%define vrf_poll_interval 0]
1 change: 1 addition & 0 deletions src/config/test_postake_snarkless.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@
[%%import "/src/config/fork.mlh"]
[%%import "/src/config/features/dev.mlh"]
[%%define compaction_interval 360000]
[%%define vrf_poll_interval 0]
1 change: 1 addition & 0 deletions src/config/test_postake_snarkless_medium_curves.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@
[%%import "/src/config/fork.mlh"]
[%%import "/src/config/features/dev.mlh"]
[%%undef compaction_interval]
[%%define vrf_poll_interval 0]
1 change: 1 addition & 0 deletions src/config/test_postake_split.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@
[%%import "/src/config/fork.mlh"]
[%%import "/src/config/features/dev.mlh"]
[%%undef compaction_interval]
[%%define vrf_poll_interval 0]
1 change: 1 addition & 0 deletions src/config/test_postake_split_medium_curves.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@
[%%import "/src/config/fork.mlh"]
[%%import "/src/config/features/dev.mlh"]
[%%undef compaction_interval]
[%%define vrf_poll_interval 0]
1 change: 1 addition & 0 deletions src/config/test_postake_three_producers.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@
[%%import "/src/config/fork.mlh"]
[%%import "/src/config/features/dev.mlh"]
[%%undef compaction_interval]
[%%define vrf_poll_interval 0]
1 change: 1 addition & 0 deletions src/config/testnet_postake.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@
[%%import "/src/config/fork.mlh"]
[%%import "/src/config/features/dev.mlh"]
[%%undef compaction_interval]
[%%define vrf_poll_interval 5000]
1 change: 1 addition & 0 deletions src/config/testnet_postake_many_producers.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@
[%%import "/src/config/fork.mlh"]
[%%import "/src/config/features/dev.mlh"]
[%%undef compaction_interval]
[%%define vrf_poll_interval 5000]
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@
[%%import "/src/config/fork.mlh"]
[%%import "/src/config/features/dev.mlh"]
[%%undef compaction_interval]
[%%define vrf_poll_interval 5000]
1 change: 1 addition & 0 deletions src/config/testnet_postake_medium_curves.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@
[%%import "/src/config/features/public_testnet.mlh"]
(* 2*block_window_duration *)
[%%define compaction_interval 360000]
[%%define vrf_poll_interval 5000]
1 change: 1 addition & 0 deletions src/config/testnet_postake_snarkless.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@
[%%import "/src/config/fork.mlh"]
[%%import "/src/config/features/dev.mlh"]
[%%undef compaction_interval]
[%%define vrf_poll_interval 0]
1 change: 1 addition & 0 deletions src/config/testnet_postake_snarkless_fake_hash.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@
[%%import "/src/config/fork.mlh"]
[%%import "/src/config/features/dev.mlh"]
[%%undef compaction_interval]
[%%define vrf_poll_interval 0]
1 change: 1 addition & 0 deletions src/config/testnet_public.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@
[%%import "/src/config/fork.mlh"]
[%%import "/src/config/features/dev.mlh"]
[%%undef compaction_interval]
[%%define vrf_poll_interval 5000]
Loading

0 comments on commit 1f98b8b

Please sign in to comment.