Skip to content

Commit

Permalink
feat(role): bootstrap role
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianLusina committed Mar 14, 2023
1 parent 554fb0f commit 4c2b966
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
41 changes: 41 additions & 0 deletions konsensus/models/roles/bootstrap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from typing import List, Callable
from itertools import cycle
from . import Role
from .replica import Replica
from .acceptor import Acceptor
from .leader import Leader
from .commander import Commander
from .scout import Scout
from ..node import Node
from konsensus.entities.messages_types import Join
from konsensus.constants import JOIN_RETRANSMIT


class Bootstrap(Role):
"""
When a node joins the cluster, it must determine the current cluster state before it can participate.
The bootstrap role handles this by sending Join messages to each peer in turn until it receives a Welcome.
"""
def __init__(self, node: Node, peers: List, execute_fn: Callable, replica: Replica=Replica, acceptor: Acceptor=Acceptor, leader: Leader=Leader, commander: Commander=Commander, scout: Scout=Scout) -> None:
super().__init__(node)
self.execute_fn = execute_fn
self.peers = peers
self.peers_cycle = cycle(peers)
self.replica = replica
self.acceptor = acceptor
self.leader = leader
self.commander = commander
self.scout = scout

def start(self):
self.join()

def join(self):
self.node.send([next(self.peers_cycle)], Join())
self.set_timer(JOIN_RETRANSMIT, self.join)

def do_welcome(self, sender, state, slot: int, decisions):
self.acceptor(self.node)
self.replica(self.node, execute_fn=self.execute_fn, peers=self.peers, state=self.state, slot=self.slot, decision=self.decisions)
self.leader(self.node, peers=self.peers, commander=self.commander, scout=self.scout).start()
self.stop
6 changes: 3 additions & 3 deletions konsensus/models/roles/commander.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from typing import List, Dict
from typing import List
from . import Role
from ..node import Node
from konsensus.entities.data_types import Ballot, Proposal
from konsensus.entities.messages_types import Prepare, Adopted, Preempted, Accept, Decided, Decision
from konsensus.constants import PREPARE_RETRANSMIT, ACCEPT_RETRANSMIT
from konsensus.entities.messages_types import Preempted, Accept, Decided, Decision
from konsensus.constants import ACCEPT_RETRANSMIT


class Commander(Role):
Expand Down

0 comments on commit 4c2b966

Please sign in to comment.