Ejemplo n.º 1
0
func FaultCheck(pl *ProcessList) {
	faultState := TopPriorityFaultState(pl)
	if !faultState.IsNil() {
		timeElapsed := time.Now().Unix() - faultState.FaultCore.Timestamp.GetTimeSeconds()
		if isMyNegotiation(faultState.FaultCore, pl) {
			if int(timeElapsed) > pl.State.FaultTimeout+1 {
				// Negotiation has timed out; must issue RENEWAL (new negotiation)
				if !faultState.PledgeDone {
					// Now let's set the Audit Server offline (so we don't just re-nominate them over and over)
					auditServerList := pl.State.GetAuditServers(faultState.FaultCore.DBHeight)
					var theAuditReplacement interfaces.IFctServer

					for _, auditServer := range auditServerList {
						if auditServer.GetChainID().IsSameAs(faultState.FaultCore.AuditServerID) {
							theAuditReplacement = auditServer
						}
					}
					if theAuditReplacement != nil {
						theAuditReplacement.SetOnline(false)
					}
				}
				CraftAndSubmitFault(pl, int(faultState.FaultCore.VMIndex), int(faultState.FaultCore.Height))
			} else {
				CraftAndSubmitFullFault(pl, faultState.FaultCore.GetHash().Fixed())
			}
		} else {
			if int(timeElapsed) > pl.State.FaultTimeout*2 {
				// The negotiation has expired; time to fault negotiator
				newVMI := (int(faultState.FaultCore.VMIndex) + 1) % len(pl.FedServers)
				Fault(pl, newVMI, int(faultState.FaultCore.Height))
			}
		}
	}
}