一.DAG的算法逻辑
假设有网络中有4个节点(A,B,C,D),每个节点都发送一笔交易,交易被包含在一个event里gossip到其他节点,一次gossip会把本节点的所知道的对方不知道的交易随机发送给其他节点,每个节点维护一个完整的图谱,通过投票算法,最后对每个event打一个时间戳,讲解具体逻辑前,我们先看一下event的数据结构:
type Event struct {
Transactions [][]byte //the payload
selfParent string
otherParent string
Creator []byte //creator's public key
Timestamp time.Time //creator's claimed timestamp of the event's creation
roundReceived *int
consensusTimestamp time.Time
}
Transactions字段是Event里包含的所有交易,selfParent和otherParent是该Event父Event的hash,包括了自己创建的父Event和其他节点创建的父Event,Creator是创建者的公钥,Timestamp是创建Event时的时间戳,roundRecevied是Event被第几层round里的famous witnesses 所共识的,consensusTimestamp是Event被共识时的时间戳。