Clawdbot commited on
Commit Β·
c412eea
1
Parent(s): a890f8f
Rename mep_miner to mep_provider for legal safety
Browse files- node/{mep_miner.py β mep_provider.py} +5 -5
- node/race_test.py +17 -17
- node/race_test_fixed.py +24 -24
- node/test_auction.py +5 -5
node/{mep_miner.py β mep_provider.py}
RENAMED
|
@@ -17,7 +17,7 @@ sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
| 17 |
HUB_URL = "http://localhost:8000"
|
| 18 |
WS_URL = "ws://localhost:8000"
|
| 19 |
|
| 20 |
-
class
|
| 21 |
def __init__(self, node_id: str):
|
| 22 |
self.node_id = node_id
|
| 23 |
self.balance = 0.0
|
|
@@ -154,18 +154,18 @@ Would you like me to elaborate on any specific aspect?"""
|
|
| 154 |
|
| 155 |
async def main():
|
| 156 |
# Create a miner with unique ID
|
| 157 |
-
|
| 158 |
-
miner =
|
| 159 |
|
| 160 |
try:
|
| 161 |
await miner.connect()
|
| 162 |
except KeyboardInterrupt:
|
| 163 |
miner.stop()
|
| 164 |
-
print("\n[MEP]
|
| 165 |
|
| 166 |
if __name__ == "__main__":
|
| 167 |
print("=" * 60)
|
| 168 |
print("Miao Exchange Protocol (MEP) Miner")
|
| 169 |
-
print("Earn SECONDS by
|
| 170 |
print("=" * 60)
|
| 171 |
asyncio.run(main())
|
|
|
|
| 17 |
HUB_URL = "http://localhost:8000"
|
| 18 |
WS_URL = "ws://localhost:8000"
|
| 19 |
|
| 20 |
+
class MEPProvider:
|
| 21 |
def __init__(self, node_id: str):
|
| 22 |
self.node_id = node_id
|
| 23 |
self.balance = 0.0
|
|
|
|
| 154 |
|
| 155 |
async def main():
|
| 156 |
# Create a miner with unique ID
|
| 157 |
+
provider_id = f"mep-provider-{uuid.uuid4().hex[:8]}"
|
| 158 |
+
miner = MEPProvider(provider_id)
|
| 159 |
|
| 160 |
try:
|
| 161 |
await miner.connect()
|
| 162 |
except KeyboardInterrupt:
|
| 163 |
miner.stop()
|
| 164 |
+
print("\n[MEP] Contribution stopped by user")
|
| 165 |
|
| 166 |
if __name__ == "__main__":
|
| 167 |
print("=" * 60)
|
| 168 |
print("Miao Exchange Protocol (MEP) Miner")
|
| 169 |
+
print("Earn SECONDS by contributing idle compute")
|
| 170 |
print("=" * 60)
|
| 171 |
asyncio.run(main())
|
node/race_test.py
CHANGED
|
@@ -13,7 +13,7 @@ import time
|
|
| 13 |
HUB_URL = "http://localhost:8000"
|
| 14 |
WS_URL = "ws://localhost:8000"
|
| 15 |
|
| 16 |
-
class
|
| 17 |
def __init__(self, name, location):
|
| 18 |
self.name = name
|
| 19 |
self.location = location
|
|
@@ -43,7 +43,7 @@ class RacingMiner:
|
|
| 43 |
self.response_time = time.time() - start_time
|
| 44 |
print(f"[{self.name}] π GOT THE TASK! Response: {self.response_time:.3f}s")
|
| 45 |
|
| 46 |
-
# Simulate processing (faster
|
| 47 |
process_time = 0.1 if "fast" in self.name.lower() else 0.5
|
| 48 |
await asyncio.sleep(process_time)
|
| 49 |
|
|
@@ -76,12 +76,12 @@ async def run_race():
|
|
| 76 |
consumer_id = "race-test-consumer"
|
| 77 |
requests.post(f"{HUB_URL}/register", json={"pubkey": consumer_id})
|
| 78 |
|
| 79 |
-
# Create 4
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
]
|
| 86 |
|
| 87 |
# Submit a task
|
|
@@ -101,9 +101,9 @@ async def run_race():
|
|
| 101 |
task_id = task_data["task_id"]
|
| 102 |
print(f" Task ID: {task_id[:8]}...")
|
| 103 |
|
| 104 |
-
# Start all
|
| 105 |
-
print("\nπ Starting
|
| 106 |
-
tasks = [
|
| 107 |
await asyncio.gather(*tasks)
|
| 108 |
|
| 109 |
# Results
|
|
@@ -112,13 +112,13 @@ async def run_race():
|
|
| 112 |
print("=" * 60)
|
| 113 |
|
| 114 |
winner = None
|
| 115 |
-
for
|
| 116 |
-
status = "π WINNER" if
|
| 117 |
-
time_str = f"{
|
| 118 |
-
print(f"{status} {
|
| 119 |
|
| 120 |
-
if
|
| 121 |
-
winner =
|
| 122 |
|
| 123 |
if winner:
|
| 124 |
print(f"\nπ― The market chose: {winner.name} from {winner.location}")
|
|
|
|
| 13 |
HUB_URL = "http://localhost:8000"
|
| 14 |
WS_URL = "ws://localhost:8000"
|
| 15 |
|
| 16 |
+
class RacingProvider:
|
| 17 |
def __init__(self, name, location):
|
| 18 |
self.name = name
|
| 19 |
self.location = location
|
|
|
|
| 43 |
self.response_time = time.time() - start_time
|
| 44 |
print(f"[{self.name}] π GOT THE TASK! Response: {self.response_time:.3f}s")
|
| 45 |
|
| 46 |
+
# Simulate processing (faster providers win)
|
| 47 |
process_time = 0.1 if "fast" in self.name.lower() else 0.5
|
| 48 |
await asyncio.sleep(process_time)
|
| 49 |
|
|
|
|
| 76 |
consumer_id = "race-test-consumer"
|
| 77 |
requests.post(f"{HUB_URL}/register", json={"pubkey": consumer_id})
|
| 78 |
|
| 79 |
+
# Create 4 providers in different "locations"
|
| 80 |
+
providers = [
|
| 81 |
+
RacingProvider("FastProvider-USA", "New York"),
|
| 82 |
+
RacingProvider("SlowProvider-EU", "Berlin"),
|
| 83 |
+
RacingProvider("QuickProvider-Asia", "Singapore"),
|
| 84 |
+
RacingProvider("SteadyProvider-AU", "Sydney")
|
| 85 |
]
|
| 86 |
|
| 87 |
# Submit a task
|
|
|
|
| 101 |
task_id = task_data["task_id"]
|
| 102 |
print(f" Task ID: {task_id[:8]}...")
|
| 103 |
|
| 104 |
+
# Start all providers simultaneously
|
| 105 |
+
print("\nπ Starting providers...")
|
| 106 |
+
tasks = [provider.compete(task_id, task_payload, bounty) for provider in providers]
|
| 107 |
await asyncio.gather(*tasks)
|
| 108 |
|
| 109 |
# Results
|
|
|
|
| 112 |
print("=" * 60)
|
| 113 |
|
| 114 |
winner = None
|
| 115 |
+
for provider in providers:
|
| 116 |
+
status = "π WINNER" if provider.won_race else "β Lost"
|
| 117 |
+
time_str = f"{provider.response_time:.3f}s" if provider.response_time else "N/A"
|
| 118 |
+
print(f"{status} {provider.name:20} {provider.location:15} Response: {time_str:8} Balance: {provider.balance}")
|
| 119 |
|
| 120 |
+
if provider.won_race:
|
| 121 |
+
winner = provider
|
| 122 |
|
| 123 |
if winner:
|
| 124 |
print(f"\nπ― The market chose: {winner.name} from {winner.location}")
|
node/race_test_fixed.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
"""
|
| 3 |
-
MEP Race Test FIXED: Ensure task is broadcast AFTER all
|
| 4 |
"""
|
| 5 |
import asyncio
|
| 6 |
import websockets
|
|
@@ -12,7 +12,7 @@ import time
|
|
| 12 |
HUB_URL = "http://localhost:8000"
|
| 13 |
WS_URL = "ws://localhost:8000"
|
| 14 |
|
| 15 |
-
class
|
| 16 |
def __init__(self, name, location):
|
| 17 |
self.name = name
|
| 18 |
self.location = location
|
|
@@ -71,18 +71,18 @@ async def run_race():
|
|
| 71 |
print("MEP GLOBAL RACE TEST: Real Competition")
|
| 72 |
print("=" * 60)
|
| 73 |
|
| 74 |
-
# Create
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
]
|
| 81 |
|
| 82 |
-
# Connect ALL
|
| 83 |
-
print("\nπ Connecting
|
| 84 |
-
for
|
| 85 |
-
await
|
| 86 |
|
| 87 |
await asyncio.sleep(0.5) # Ensure all connected
|
| 88 |
|
|
@@ -90,10 +90,10 @@ async def run_race():
|
|
| 90 |
consumer_id = "race-consumer-v2"
|
| 91 |
requests.post(f"{HUB_URL}/register", json={"pubkey": consumer_id})
|
| 92 |
|
| 93 |
-
task_payload = "Which
|
| 94 |
bounty = 7.5
|
| 95 |
|
| 96 |
-
print(f"\nπ€ Broadcasting task to {len(
|
| 97 |
print(f" Task: {task_payload}")
|
| 98 |
print(f" Bounty: {bounty} SECONDS")
|
| 99 |
|
|
@@ -106,20 +106,20 @@ async def run_race():
|
|
| 106 |
task_id = resp.json()["task_id"]
|
| 107 |
print(f" Task ID: {task_id[:8]}...")
|
| 108 |
|
| 109 |
-
# All
|
| 110 |
-
print("\nπ ALL
|
| 111 |
-
results = await asyncio.gather(*[
|
| 112 |
|
| 113 |
# Close connections
|
| 114 |
-
for
|
| 115 |
-
await
|
| 116 |
|
| 117 |
# Results
|
| 118 |
print("\n" + "=" * 60)
|
| 119 |
print("RACE RESULTS:")
|
| 120 |
print("=" * 60)
|
| 121 |
|
| 122 |
-
winners = [m for m in
|
| 123 |
|
| 124 |
if winners:
|
| 125 |
winner = winners[0] # First to finish
|
|
@@ -130,10 +130,10 @@ async def run_race():
|
|
| 130 |
|
| 131 |
# Show all times
|
| 132 |
print(f"\nπ All response times:")
|
| 133 |
-
for
|
| 134 |
-
if
|
| 135 |
-
status = "β
WON" if
|
| 136 |
-
print(f" {status} {
|
| 137 |
else:
|
| 138 |
print("β No winner - check hub logs")
|
| 139 |
|
|
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
"""
|
| 3 |
+
MEP Race Test FIXED: Ensure task is broadcast AFTER all providers connect.
|
| 4 |
"""
|
| 5 |
import asyncio
|
| 6 |
import websockets
|
|
|
|
| 12 |
HUB_URL = "http://localhost:8000"
|
| 13 |
WS_URL = "ws://localhost:8000"
|
| 14 |
|
| 15 |
+
class RacingProvider:
|
| 16 |
def __init__(self, name, location):
|
| 17 |
self.name = name
|
| 18 |
self.location = location
|
|
|
|
| 71 |
print("MEP GLOBAL RACE TEST: Real Competition")
|
| 72 |
print("=" * 60)
|
| 73 |
|
| 74 |
+
# Create providers
|
| 75 |
+
providers = [
|
| 76 |
+
RacingProvider("FastProvider-USA", "New York"),
|
| 77 |
+
RacingProvider("SlowProvider-EU", "Berlin"),
|
| 78 |
+
RacingProvider("QuickProvider-Asia", "Singapore"),
|
| 79 |
+
RacingProvider("SteadyProvider-AU", "Sydney")
|
| 80 |
]
|
| 81 |
|
| 82 |
+
# Connect ALL providers first
|
| 83 |
+
print("\nπ Connecting providers to hub...")
|
| 84 |
+
for provider in providers:
|
| 85 |
+
await provider.connect()
|
| 86 |
|
| 87 |
await asyncio.sleep(0.5) # Ensure all connected
|
| 88 |
|
|
|
|
| 90 |
consumer_id = "race-consumer-v2"
|
| 91 |
requests.post(f"{HUB_URL}/register", json={"pubkey": consumer_id})
|
| 92 |
|
| 93 |
+
task_payload = "Which provider is fastest in the MEP race?"
|
| 94 |
bounty = 7.5
|
| 95 |
|
| 96 |
+
print(f"\nπ€ Broadcasting task to {len(providers)} connected providers...")
|
| 97 |
print(f" Task: {task_payload}")
|
| 98 |
print(f" Bounty: {bounty} SECONDS")
|
| 99 |
|
|
|
|
| 106 |
task_id = resp.json()["task_id"]
|
| 107 |
print(f" Task ID: {task_id[:8]}...")
|
| 108 |
|
| 109 |
+
# All providers listen simultaneously
|
| 110 |
+
print("\nπ ALL PROVIDERS LISTENING... RACE STARTS!")
|
| 111 |
+
results = await asyncio.gather(*[provider.listen_for_task(task_id, bounty) for provider in providers])
|
| 112 |
|
| 113 |
# Close connections
|
| 114 |
+
for provider in providers:
|
| 115 |
+
await provider.close()
|
| 116 |
|
| 117 |
# Results
|
| 118 |
print("\n" + "=" * 60)
|
| 119 |
print("RACE RESULTS:")
|
| 120 |
print("=" * 60)
|
| 121 |
|
| 122 |
+
winners = [m for m in providers if m.won_race]
|
| 123 |
|
| 124 |
if winners:
|
| 125 |
winner = winners[0] # First to finish
|
|
|
|
| 130 |
|
| 131 |
# Show all times
|
| 132 |
print(f"\nπ All response times:")
|
| 133 |
+
for provider in providers:
|
| 134 |
+
if provider.response_time:
|
| 135 |
+
status = "β
WON" if provider.won_race else "β Lost"
|
| 136 |
+
print(f" {status} {provider.name:20} {provider.response_time:.3f}s")
|
| 137 |
else:
|
| 138 |
print("β No winner - check hub logs")
|
| 139 |
|
node/test_auction.py
CHANGED
|
@@ -7,9 +7,9 @@ import uuid
|
|
| 7 |
HUB_URL = "http://localhost:8000"
|
| 8 |
|
| 9 |
async def test():
|
| 10 |
-
|
| 11 |
-
requests.post(f'{HUB_URL}/register', json={'pubkey':
|
| 12 |
-
async with websockets.connect(f'ws://localhost:8000/ws/{
|
| 13 |
consumer = 'test-consumer'
|
| 14 |
requests.post(f'{HUB_URL}/register', json={'pubkey': consumer})
|
| 15 |
requests.post(f'{HUB_URL}/tasks/submit', json={'consumer_id': consumer, 'payload': 'Test payload', 'bounty': 1.0})
|
|
@@ -20,12 +20,12 @@ async def test():
|
|
| 20 |
|
| 21 |
if data['event'] == 'rfc':
|
| 22 |
task_id = data['data']['id']
|
| 23 |
-
resp = requests.post(f'{HUB_URL}/tasks/bid', json={'task_id': task_id, 'provider_id':
|
| 24 |
print('Bid response:', resp.json())
|
| 25 |
|
| 26 |
complete_resp = requests.post(f'{HUB_URL}/tasks/complete', json={
|
| 27 |
'task_id': task_id,
|
| 28 |
-
'provider_id':
|
| 29 |
'result_payload': 'Done!'
|
| 30 |
})
|
| 31 |
print('Complete response:', complete_resp.json())
|
|
|
|
| 7 |
HUB_URL = "http://localhost:8000"
|
| 8 |
|
| 9 |
async def test():
|
| 10 |
+
provider = f'mep-provider-{uuid.uuid4().hex[:6]}'
|
| 11 |
+
requests.post(f'{HUB_URL}/register', json={'pubkey': provider})
|
| 12 |
+
async with websockets.connect(f'ws://localhost:8000/ws/{provider}') as ws:
|
| 13 |
consumer = 'test-consumer'
|
| 14 |
requests.post(f'{HUB_URL}/register', json={'pubkey': consumer})
|
| 15 |
requests.post(f'{HUB_URL}/tasks/submit', json={'consumer_id': consumer, 'payload': 'Test payload', 'bounty': 1.0})
|
|
|
|
| 20 |
|
| 21 |
if data['event'] == 'rfc':
|
| 22 |
task_id = data['data']['id']
|
| 23 |
+
resp = requests.post(f'{HUB_URL}/tasks/bid', json={'task_id': task_id, 'provider_id': provider})
|
| 24 |
print('Bid response:', resp.json())
|
| 25 |
|
| 26 |
complete_resp = requests.post(f'{HUB_URL}/tasks/complete', json={
|
| 27 |
'task_id': task_id,
|
| 28 |
+
'provider_id': provider,
|
| 29 |
'result_payload': 'Done!'
|
| 30 |
})
|
| 31 |
print('Complete response:', complete_resp.json())
|