Skip to content
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

Dispersal Protocol's Executor Behaviour Logic #918

Open
TakeASwing-420 opened this issue Nov 12, 2024 · 0 comments
Open

Dispersal Protocol's Executor Behaviour Logic #918

TakeASwing-420 opened this issue Nov 12, 2024 · 0 comments

Comments

@TakeASwing-420
Copy link
Contributor

@danielSanchezQ

fn find_subnetworks_candidates_excluding_peer(

The python equivalent for the above function is almost like this

from typing import Set, Any

def find_subnetworks_candidates_excluding_peer(
    self,
    peer_id: Any,
    subnetworks: Set[Any]
) -> Set[Any]:
    # Attempt to find common peers across all subnetworks
    peers = set.intersection(
        *(
            self.filter_peers_for_subnetworks(peer_id, {subnetwork})
            for subnetwork in subnetworks
        )
    ) or set()  # Default to empty set if no intersection is found

    # If no common peers, take the union of all subnetworks' peers
    if not peers:
        peers = set.union(
            *(
                self.filter_peers_for_subnetworks(peer_id, {subnetwork})
                for subnetwork in subnetworks
            )
        ) 

    return peers

I might be wrong but I believe that you want to disperse the cancelled blobs into the target subnetworks in a optimal fashion but the second part (i.e. the union part) is concerning.

let's say you have three subnets like this with executors
X : a, b
Y : c, d
Z : e, f

Clearly you don't have any common validator in these cases so you take the union as a whole (a, b, c, d, e, f) but you could have also taken (a, c, e) and still would have achieved your goal of sending blobs to the respective networks.
The equivalent python code is like this

from itertools import combinations

def minimum_covering_set(tuples):
    # Convert each tuple to a set
    sets = [set(t) for t in tuples]
    
    # Collect all unique elements
    all_elements = set.union(*sets)
    
    # Try all combinations from size 1 up to the total unique elements
    for size in range(1, len(all_elements) + 1):
        for combo in combinations(all_elements, size):
            # Check if the combination has at least one element in each set
            if all(any(e in s for e in combo) for s in sets):
                return combo  # Return the first minimum combo found

# Example usage
tuples = [('a', 'b', 'c'), ('d', 'e', 'f'), ('a', 'g')]
result = minimum_covering_set(tuples)
print(result)

Please check into this one.

@TakeASwing-420 TakeASwing-420 changed the title Dispersal Protocol's Executor Behaviour Dispersal Protocol's Executor Behaviour Logic Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant