Skip to content

Commit

Permalink
Added solidification
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberphysic4l committed Nov 16, 2021
1 parent b3f3f9a commit eccb1ae
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
10 changes: 7 additions & 3 deletions core/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Node:
def __init__(self, Network, NodeID, Genesis, PoWDelay = 1):
self.TipsSet = [Genesis]
self.Ledger = [Genesis]
self.LedgerTranIDs = []
self.LedgerTranIDs = [0]
self.Neighbours = []
self.Network = Network
self.Inbox = Inbox(self)
Expand Down Expand Up @@ -137,13 +137,17 @@ def parse(self, Packet, Time):
Not fully implemented yet
Simply makes a copy of the transaction and then calls the solidifier
"""
Packet.Data = Packet.Data.copy()
self.solidify(Packet, Time)

def solidify(self, Packet, Time):
"""
Not implemented yet, just calls the booker
"""
Packet.Data = Packet.Data.copy(self)
Tran = Packet.Data
assert isinstance(Tran, Transaction)
Tran.solidify()

self.book(Packet, Time)

def book(self, Packet, Time):
Expand Down
32 changes: 29 additions & 3 deletions core/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def __init__(self, IssueTime, Parents, Node, Network, Work=0, Index=None, Visibl
self.Work = Work
self.AWeight = Work
self.LastAWUpdate = self
self.Solid = True
if Node:
self.NodeID = Node.NodeID # signature of issuing node
self.Eligible = False
Expand Down Expand Up @@ -69,14 +70,39 @@ def updateAW(self, Node, updateTran=None, Work=None):
if not p.Confirmed and p.LastAWUpdate != updateTran:
p.updateAW(Node, updateTran, Work)

def copy(self):
def copy(self, Node):
Tran = copy(self)
Tran.Children = []
Tran.Solid = True
parentIDs = [p.Index for p in Tran.Parents]
parents = []
for pID in parentIDs:
if pID in Node.LedgerTranIDs:
parents.append(Node.Ledger[Node.LedgerTranIDs.index(pID)])
Tran.Parents = parents
childrenIDs = [c.Index for c in Tran.Children]
children = []
for cID in childrenIDs:
if cID in Node.LedgerTranIDs:
children.append(Node.Ledger[Node.LedgerTranIDs.index(cID)])
Tran.Children = children
Tran.Eligible = False
Tran.Confirmed = False

return Tran

def solidify(self):
solidParents = [p for p in self.Parents if p.Solid]
if len(solidParents)==1:
if self.Parents[0].Index==0: # if parent is genesis
self.Solid = True
if len(solidParents)==2: # if two solid parents
self.Solid = True
for c in self.Children:
assert isinstance(c, Transaction)
if self not in c.Parents:
c.Parents.append(self)
c.solidify()


def is_ready(self):
for p in self.Parents:
if not p.Eligible:
Expand Down

0 comments on commit eccb1ae

Please sign in to comment.