add gossipsub as a parameter in the config file

Signed-off-by: Arunima Chaudhuri <arunimachaudhuri2020@gmail.com>
This commit is contained in:
Arunima Chaudhuri 2024-05-21 08:34:58 +00:00
parent 5718fe14b7
commit 45f773b184
3 changed files with 42 additions and 32 deletions

View File

@ -246,10 +246,10 @@ class Node:
self.statsRxDupInSlot += 1 self.statsRxDupInSlot += 1
self.statsRxInSlot += 1 self.statsRxInSlot += 1
def receiveSegmentViaGossip(self, rID, cID): def receiveSegmentViaGossip(self, rID, cID, source):
"""Receive a segment via gossipsub protocol.""" """Receive a segment via gossipsub protocol from a specific source."""
if not self.amImalicious: if not self.amImalicious:
self.logger.trace("Recv via gossipsub: %d: %d,%d", self.ID, rID, cID, extra=self.format) self.logger.trace("Recv via gossipsub %d-> %d: %d,%d", source, self.ID, rID, cID, extra=self.format)
self.receivedBlock.setSegment(rID, cID) self.receivedBlock.setSegment(rID, cID)
self.sampleRecvCount += 1 self.sampleRecvCount += 1
self.statsRxInSlot += 1 self.statsRxInSlot += 1
@ -526,14 +526,26 @@ class Node:
- It checks if the current node (self) already has the segment. - It checks if the current node (self) already has the segment.
- If the segment is missing, it attempts to receive the segment from other nodes using the Gossipsub protocol via the receiveSegmentViaGossip method. - If the segment is missing, it attempts to receive the segment from other nodes using the Gossipsub protocol via the receiveSegmentViaGossip method.
""" """
for rID in rows: for rID, rSources in rows.items():
for cID in cols: for cID, cSources in cols.items():
if not self.receivedBlock.getSegment(rID, cID): if not self.receivedBlock.getSegment(rID, cID):
self.receiveSegmentViaGossip(rID, cID) sources = list(set(rSources).intersection(cSources))
if sources:
source = sources[0] # Pick the first source from the intersection
self.receiveSegmentViaGossip(rID, cID, source)
self.statsTxInSlot += 1 # request sent to receive segment via gossip
def send(self, rows, cols):
def send(self, gossipsub, rows, cols):
""" Send as much as we can in the timestep, limited by bwUplink.""" """ Send as much as we can in the timestep, limited by bwUplink."""
if gossipsub:
if not self.amImalicious:
self.gossipSub(rows, cols)
if self.statsTxInSlot >= self.bwUplink:
return
else:
# process node level send queue # process node level send queue
if not self.amImalicious: if not self.amImalicious:
self.processSendQueue() self.processSendQueue()
@ -557,11 +569,6 @@ class Node:
if self.statsTxInSlot >= self.bwUplink: if self.statsTxInSlot >= self.bwUplink:
return return
if not self.amImalicious:
self.gossipSub(rows, cols)
if self.statsTxInSlot >= self.bwUplink:
return
def logRows(self): def logRows(self):
"""It logs the rows assigned to the validator.""" """It logs the rows assigned to the validator."""
if self.logger.isEnabledFor(logging.DEBUG): if self.logger.isEnabledFor(logging.DEBUG):

View File

@ -293,7 +293,7 @@ class Simulator:
self.logger.debug("PHASE SEND %d" % steps, extra=self.format) self.logger.debug("PHASE SEND %d" % steps, extra=self.format)
for i in range(0,self.shape.numberNodes): for i in range(0,self.shape.numberNodes):
if not self.validators[i].amImalicious: if not self.validators[i].amImalicious:
self.validators[i].send(rows, cols) self.validators[i].send(self.config.gossipsub, rows, cols)
self.logger.debug("PHASE RECEIVE %d" % steps, extra=self.format) self.logger.debug("PHASE RECEIVE %d" % steps, extra=self.format)
for i in range(1,self.shape.numberNodes): for i in range(1,self.shape.numberNodes):
self.validators[i].receiveRowsColumns() self.validators[i].receiveRowsColumns()

View File

@ -59,6 +59,9 @@ maliciousNodes = range(40,41,20)
# If True, the malicious nodes will be assigned randomly; if False, a predefined pattern may be used # If True, the malicious nodes will be assigned randomly; if False, a predefined pattern may be used
randomizeMaliciousNodes = True randomizeMaliciousNodes = True
# When set to True, nodes will use the Gossipsub protocol for communication
gossipsub = False
# Per-topic mesh neighborhood size # Per-topic mesh neighborhood size
netDegrees = range(8, 9, 2) netDegrees = range(8, 9, 2)