7
7
import re
8
8
import sys
9
9
import threading
10
- import time
11
10
from http .client import HTTPConnection
12
- from http .server import BaseHTTPRequestHandler , HTTPServer
13
11
from subprocess import PIPE , STDOUT , Popen
14
12
15
13
from pyth_utils import *
36
34
"WORMHOLE_ADDRESS" , "Bridge1p5gheXUvJ6jGWGeCsgPKgnE3YgdGKRVCMY9o"
37
35
)
38
36
39
- P2W_MAX_LOG_LINES = int (os .environ .get ("P2W_MAX_LOG_LINES" , 1000 ))
40
-
41
37
# attester needs string, but we validate as int first
42
38
P2W_RPC_TIMEOUT_SECS = str (int (os .environ .get ("P2W_RPC_TIMEOUT_SECS" , "20" )))
43
39
44
- ATTESTATIONS = {
45
- "pendingSeqnos" : [],
46
- }
47
-
48
- SEQNO_REGEX = re .compile (r"Sequence number: (\d+)" )
49
-
50
-
51
-
52
- class P2WAutoattestStatusEndpoint (BaseHTTPRequestHandler ):
53
- """
54
- A dumb endpoint for last attested price metadata.
55
- """
56
-
57
- def do_GET (self ):
58
- logging .info (f"Got path { self .path } " )
59
- sys .stdout .flush ()
60
- data = json .dumps (ATTESTATIONS ).encode ("utf-8" )
61
- logging .debug (f"Sending: { data } " )
62
-
63
- ATTESTATIONS ["pendingSeqnos" ] = []
64
-
65
- self .send_response (200 )
66
- self .send_header ("Content-Type" , "application/json" )
67
- self .send_header ("Content-Length" , str (len (data )))
68
- self .end_headers ()
69
- self .wfile .write (data )
70
- self .wfile .flush ()
71
-
72
-
73
- def serve_attestations ():
74
- """
75
- Run a barebones HTTP server to share Pyth2wormhole attestation history
76
- """
77
- server_address = ("" , P2W_ATTESTATIONS_PORT )
78
- httpd = HTTPServer (server_address , P2WAutoattestStatusEndpoint )
79
- httpd .serve_forever ()
80
-
81
-
82
40
if SOL_AIRDROP_AMT > 0 :
83
41
# Fund the p2w owner
84
42
sol_run_or_die (
@@ -92,17 +50,6 @@ def serve_attestations():
92
50
],
93
51
)
94
52
95
- def find_and_log_seqnos (s ):
96
- # parse seqnos
97
- matches = SEQNO_REGEX .findall (s )
98
-
99
- seqnos = list (map (lambda m : int (m ), matches ))
100
-
101
- ATTESTATIONS ["pendingSeqnos" ] += seqnos
102
-
103
- if len (seqnos ) > 0 :
104
- logging .info (f"{ len (seqnos )} batch seqno(s) received: { seqnos } )" )
105
-
106
53
if P2W_INITIALIZE_SOL_CONTRACT is not None :
107
54
# Get actor pubkeys
108
55
P2W_OWNER_ADDRESS = sol_run_or_die (
@@ -272,12 +219,6 @@ def find_and_log_seqnos(s):
272
219
273
220
logging .info ("p2w_autoattest ready to roll!" )
274
221
275
- find_and_log_seqnos (first_attest_result .stdout )
276
-
277
- # Serve p2w endpoint
278
- endpoint_thread = threading .Thread (target = serve_attestations , daemon = True )
279
- endpoint_thread .start ()
280
-
281
222
# Let k8s know the service is up
282
223
readiness_thread = threading .Thread (target = readiness , daemon = True )
283
224
readiness_thread .start ()
@@ -303,31 +244,12 @@ def find_and_log_seqnos(s):
303
244
"-d" ,
304
245
"--timeout" ,
305
246
P2W_RPC_TIMEOUT_SECS ,
306
- ],
307
- stdout = PIPE ,
308
- stderr = STDOUT ,
309
- text = True ,
310
- )
311
-
312
- saved_log_lines = []
247
+ ]
248
+ )
313
249
314
- # Keep listening for seqnos until the program exits
250
+ # Wait for an unexpected process exit
315
251
while p2w_client_process .poll () is None :
316
- line = p2w_client_process .stdout .readline ()
317
-
318
- # Always pass output to the debug level
319
- logging .debug (f"pyth2wormhole-client: { line } " )
320
-
321
- find_and_log_seqnos (line )
322
-
323
- # Extend with new line
324
- saved_log_lines .append (line )
325
-
326
- # trim back to specified maximum
327
- if len (saved_log_lines ) > P2W_MAX_LOG_LINES :
328
- saved_log_lines .pop (0 )
329
-
252
+ pass
330
253
331
254
# Yell if the supposedly non-stop attestation process exits
332
255
logging .warn (f"pyth2wormhole-client stopped unexpectedly with code { p2w_client_process .retcode } " )
333
- logging .warn (f"Last { len (saved_log_lines )} log lines:\n { (saved_log_lines )} " )
0 commit comments