-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implementing logic #7
Changes from 3 commits
0dbf21f
9648ecb
6f321c7
23fccc4
290fc3d
1c69b99
6b4abe1
34a9cf7
168de86
8f975a7
7f1873c
4d7fba3
9802e2d
16603b6
6b24602
82e330c
968f045
935c2e6
6ba1675
2ac5dd7
097b2de
dc62a30
c9d3b75
845ec8a
44ebe33
840941e
54de75f
d2bc4a4
030cba1
5e27248
78ad8f2
4af7d75
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -30,25 +30,27 @@ The goal of this project is to implement a distributed and decentralized system | |||||
- Validators can request the connection information of miners from the subtensor network. This information is validated and | ||||||
decrypted locally using the validator's private key. | ||||||
|
||||||
## Communication Flow | ||||||
## Basic Communication Flow | ||||||
|
||||||
<!-- | ||||||
@startuml ./assets/diagrams/CommunicationFlow | ||||||
participant Validator | ||||||
participant Miner | ||||||
participant GitHub | ||||||
participant AddressManager | ||||||
participant Storage | ||||||
participant Bittensor | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
Validator -> Validator: Generate Validator key-pair | ||||||
Validator -> GitHub: Publish public key along with HotKey | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
GitHub -> Miner: Fetch Validator info | ||||||
Miner -> Miner: Encrypt Miner IP/Domain with Validator public key | ||||||
Miner -> Storage: Add/update file with encrypted IPs/Domains for Validators | ||||||
GitHub -> Miner: Fetch new Validator info | ||||||
Miner -> AddressManager: Generate new address | ||||||
Miner -> Miner: Encrypt generated address with Validator public key | ||||||
Miner -> Storage: Update file with encrypted addresses for Validators | ||||||
Miner -> Bittensor: Publish file location | ||||||
Bittensor -> Validator: Fetch file location | ||||||
Storage -> Validator: Fetch Miner file | ||||||
Validator -> Validator: Decrypt Miner file entry encrypted for given Validator | ||||||
Validator -> Miner: Send request using decrypted Miner IP/Domain | ||||||
Validator -> Miner: Send request using decrypted Miner address | ||||||
@enduml | ||||||
--> | ||||||
|
||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -29,24 +29,27 @@ def __init__(self, address_id, address_type: AddressType, address: str, port: in | |||||
self.address = address | ||||||
self.port = port | ||||||
|
||||||
def __repr__(self): | ||||||
return f"Address(id={self.address_id}, type={self.address_type}, address={self.address}:{self.port})" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
@abstractmethod | ||||||
def encrypt(self) -> bytes: | ||||||
def serialize(self) -> bytes: | ||||||
""" | ||||||
Encrypts address data. | ||||||
Serialize address data. | ||||||
|
||||||
Returns: | ||||||
bytes: Encrypted address data. | ||||||
bytes: Serialized address data. | ||||||
""" | ||||||
pass | ||||||
|
||||||
@classmethod | ||||||
@abstractmethod | ||||||
def decrypt(cls, encrypted_data: bytes) -> Address: | ||||||
def deserialize(cls, serialized_data: bytes) -> 'Address': | ||||||
""" | ||||||
Create address from encrypted address data. | ||||||
Deserialize address data. | ||||||
|
||||||
Args: | ||||||
encrypted_data: Encrypted address data. | ||||||
serialized_data: Data serialized before by serialize method. | ||||||
|
||||||
Returns: | ||||||
Address: Created address. | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,33 @@ | ||
from abc import ABC, abstractmethod | ||
|
||
from bt_ddos_shield.utils import Hotkey | ||
|
||
|
||
class AbstractBlockchainManager(ABC): | ||
""" | ||
Abstract base class for manager handling publishing blocks to blockchain. | ||
""" | ||
|
||
@abstractmethod | ||
def publish(self, data: bytes): | ||
def put(self, hotkey: Hotkey, data: bytes): | ||
""" | ||
Puts data to blockchain. | ||
|
||
Args: | ||
hotkey: Hotkey of user for whom we are putting data. | ||
data: Data. | ||
""" | ||
pass | ||
|
||
@abstractmethod | ||
def get(self, hotkey: Hotkey) -> bytes: | ||
""" | ||
Gets data from blockchain. | ||
|
||
Args: | ||
hotkey: Hotkey of user to get data from. | ||
|
||
Returns: | ||
data: Last block of data put by user. | ||
""" | ||
pass |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
from abc import ABC, abstractmethod | ||
from dataclasses import dataclass | ||
import traceback | ||
|
||
|
||
@dataclass | ||
class Event: | ||
class MinerShieldEvent: | ||
""" | ||
Class describing event, which happened in the shield. | ||
""" | ||
|
@@ -12,17 +13,30 @@ class Event: | |
exception: Exception = None # Exception which caused the event. | ||
|
||
|
||
class AbstractEventProcessor(ABC): | ||
class AbstractMinerShieldEventProcessor(ABC): | ||
""" | ||
Abstract base class for processor handling events generated by shield. | ||
""" | ||
|
||
@abstractmethod | ||
def add_event(self, event: Event): | ||
def add_event(self, event: MinerShieldEvent): | ||
""" | ||
Add new event to be handled by processor. | ||
|
||
Args: | ||
event: Event to add. | ||
""" | ||
pass | ||
|
||
|
||
class PrintingMinerShieldEventProcessor(AbstractMinerShieldEventProcessor): | ||
""" | ||
Event processor which logs events to console. | ||
""" | ||
|
||
def add_event(self, event: MinerShieldEvent): | ||
if event.exception is not None: | ||
print(f"MinerShieldEvent: {event.event_description}\nException happened:") | ||
print(traceback.format_exc()) | ||
else: | ||
print(f"MinerShieldEvent: {event.event_description}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This prints, not logs, but I also think it is generally assembled wrong and won't work. No worries, you'll fix it when you start running it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is class mostly (and maybe only) for unit tests. But I change name to PrintingMinerShieldEventProcessor, because probably in the future there will be LoggingMinerShieldEventProcessor. Also it works - just run unit test. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And if we ever print that, we'd rather use stderr. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've changed it already in future commits. But now I'm printing exception captured inside MinerShieldEvent. Probably not, but there is possibility, that it wouldn't be last exception thrown and print_exc calls sys.exception() inside to get the last one. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.