Example #1
0
func (sn *Node) ComputeCombinedMerkleRoot(view, Round int) {
	sn.roundLock.RLock()
	round := sn.Rounds[Round]
	sn.roundLock.RUnlock()
	// add hash of whole log to leaves
	round.Leaves = append(round.Leaves, round.HashedLog)

	// compute MT root based on Log as right child and
	// MT of leaves as left child and send it up to parent
	sort.Sort(hashid.ByHashId(round.Leaves))
	left, proofs := proof.ProofTree(sn.Suite().Hash, round.Leaves)
	right := round.HashedLog
	moreLeaves := make([]hashid.HashId, 0)
	moreLeaves = append(moreLeaves, left, right)
	round.MTRoot, _ = proof.ProofTree(sn.Suite().Hash, moreLeaves)

	// Hashed Log has to come first in the proof; len(sn.CMTRoots)+1 proofs
	round.Proofs = make(map[string]proof.Proof, 0)
	children := sn.Children(view)
	for name := range children {
		round.Proofs[name] = append(round.Proofs[name], right)
	}
	round.Proofs["local"] = append(round.Proofs["local"], right)

	// separate proofs by children (need to send personalized proofs to children)
	// also separate local proof (need to send it to timestamp server)
	sn.SeparateProofs(proofs, round.Leaves, Round)
}
Example #2
0
func (cosi *CosiStruct) ComputeCombinedMerkleRoot() {
	// add hash of whole log to leaves
	cosi.Leaves = append(cosi.Leaves, cosi.HashedLog)

	// compute MT root based on Log as right child and
	// MT of leaves as left child and send it up to parent
	sort.Sort(hashid.ByHashId(cosi.Leaves))
	left, proofs := proof.ProofTree(cosi.Suite.Hash, cosi.Leaves)
	right := cosi.HashedLog
	moreLeaves := make([]hashid.HashId, 0)
	moreLeaves = append(moreLeaves, left, right)
	cosi.MTRoot, _ = proof.ProofTree(cosi.Suite.Hash, moreLeaves)

	// Hashed Log has to come first in the proof; len(sn.CMTRoots)+1 proofs
	cosi.Proofs = make(map[string]proof.Proof, 0)
	for name := range cosi.Children {
		cosi.Proofs[name] = append(cosi.Proofs[name], right)
	}
	cosi.Proofs["local"] = append(cosi.Proofs["local"], right)

	// separate proofs by children (need to send personalized proofs to children)
	// also separate local proof (need to send it to timestamp server)
	cosi.SeparateProofs(proofs, cosi.Leaves)
}