Exemplo n.º 1
0
// This routine is called once we have everything to create a Directory Block.
// It is called by the follower code.  It is requried to build the Directory Block
// to validate the signatures we will get with the DirectoryBlockSignature messages.
func (s *State) ProcessEndOfBlock() {
	s.PreviousDirectoryBlock = s.CurrentDirectoryBlock
	previousECBlock := s.GetCurrentEntryCreditBlock()

	s.FactoidState.ProcessEndOfBlock(s) // Clean up Factoids

	db, err := s.CreateDBlock()
	if err != nil {
		panic("Failed to create a Directory Block")
	}

	if previousECBlock != nil {
		s.DB.ProcessECBlockBatch(previousECBlock)
	}

	s.SetCurrentDirectoryBlock(db)

	if s.PreviousDirectoryBlock != nil {
		if err = s.DB.SaveDirectoryBlockHead(s.PreviousDirectoryBlock); err != nil {
			panic(err.Error())
		}
		s.Anchor.UpdateDirBlockInfoMap(dbInfo.NewDirBlockInfoFromDirBlock(s.PreviousDirectoryBlock))
	} else {
		log.Println("No old db")
	}

	s.ProcessList = make([][]interfaces.IMsg, 1)

}
Exemplo n.º 2
0
func (a *Anchor) checkMissingDirBlockInfo() {
	anchorLog.Debug("checkMissingDirBlockInfo for those unsaved DirBlocks in database")
	dblocks, _ := a.db.FetchAllDBlocks()
	dirBlockInfos, _ := a.db.FetchAllDirBlockInfos() //FetchAllDirBlockInfos()
	for _, dblock := range dblocks {
		var found = false
		for i, dbinfo := range dirBlockInfos {
			if dbinfo.GetDatabaseHeight() == dblock.GetDatabaseHeight() {
				dirBlockInfos = append(dirBlockInfos[:i], dirBlockInfos[i+1:]...)
				found = true
				break
			}
		}
		if !found {
			if dblock.GetKeyMR() == nil || bytes.Compare(dblock.GetKeyMR().Bytes(), primitives.NewZeroHash().Bytes()) == 0 {
				dblock.BuildKeyMerkleRoot()
			}
			dirBlockInfo := dbInfo.NewDirBlockInfoFromDirBlock(dblock)
			dirBlockInfo.SetTimestamp(primitives.NewTimestampNow())
			anchorLog.Debug("add missing dirBlockInfo to map: ", spew.Sdump(dirBlockInfo))
			a.db.SaveDirBlockInfo(dirBlockInfo)
			a.dirBlockInfoSlice = append(a.dirBlockInfoSlice, dirBlockInfo)
		}
	}
}