public void registerBlockProduction(lineParser lineObj) { slots.Add(lineObj.signDateTime, lineObj); if (lineObj.blockNumber > hightestBlock) { if ((lineObj.blockNumber - hightestBlock) > 12) { //slots.Add(lineObj.signDateTime, new slotStats()); } hightestBlock = lineObj.blockNumber; } }
public void updateHistory(lineParser line) { DateTime roundDateTimeToUpdate = DateTime.MinValue; //If max is not found yet then we know which ProductionRound to use if (history[startingRound].maxTimeSlot == DateTime.MaxValue) { logger.Debug("Block {0} arrived. We have not found the 1st round min and max yet.", line.blockNumber); roundDateTimeToUpdate = startingRound; history[roundDateTimeToUpdate].updateRound(line); } else { //This is block if (line.signDateTime > maxTimeSlot) { var newMin = maxTimeSlot.AddSeconds(0.5); var newMax = maxTimeSlot.AddSeconds(0.5 + (252 * 0.5)); logger.Debug("Block {0} arrived. The maxTimeSlot that we have in any round is {1}. Create a new round {2}->{3}", line.blockNumber, maxTimeSlot, newMin, newMax); history[getBlockRound(maxTimeSlot)].print(); history.Add(line.signDateTime, new ProductionRound(line.signDateTime, newMin, newMax)); } else { logger.Debug("Block {0} arrived. Looking up the Date of the Round we want to add it to: {1} ", line.blockNumber, roundDateTimeToUpdate); roundDateTimeToUpdate = getBlockRound(line.signDateTime); if (roundDateTimeToUpdate == DateTime.MinValue) { logger.Warn("Drop the record ... we don't have a slot for it."); } else { logger.Debug("Block {0} arrived. Add it to the round: {1} ", line.blockNumber, roundDateTimeToUpdate); history[roundDateTimeToUpdate].updateRound(line); } } } }
public void updateRound(lineParser line) { if (line.signDateTime > maxTimeSlot || line.signDateTime < minTimeSlot) { logger.Error("Round {0} has a min/max of {1}-{2}, block {3} should not be added here", ID, minTimeSlot, maxTimeSlot, line.blockNumber); } if (!producers.ContainsKey(line.part_producer)) { logger.Warn("Round {0}, Producer {1} was not expected. Probably due to a schedule change", ID, line.part_producer); producers.Add(line.part_producer, new ProducerSlotStats(producers.Count + 1)); } var producersSlotStats = producers[line.part_producer]; if (producersSlotStats.slots.Count == 12) { logger.Error("Round {0}, Producer {1} already has 12 block .. this should not be possible", ID, line.part_producer); } producersSlotStats.registerBlockProduction(line); //This is the 1st round and we don't know what the min and max block for the round is yet. if (maxTimeSlot == DateTime.MaxValue) { //As soon as we have 12 blocks from a producer and we know it's position in the production queue we can calc the rest if (producersSlotStats.slots.Count == 12 && producersSlotStats.validateSequentialBlocks()) { var order = producersSlotStats.producerOrder; var totalBlocks = 12 * 21; var blocksAhead = (21 - order) * 12; maxTimeSlot = producersSlotStats.maxTimeSlot.AddSeconds(blocksAhead / 2); minTimeSlot = maxTimeSlot.AddSeconds(-(totalBlocks / 2)); logger.Info("{0} at position {1} has a max block of {2}. There are {3} blocks remaining in this round", line.part_producer, order, producersSlotStats.maxTimeSlot, blocksAhead); logger.Info("Round {0} was the 1st round. We calculated a min/max of {1}-{2}. Basis was producer {3} with a min/max of {4} {5}", ID, maxTimeSlot, minTimeSlot, line.part_producer, producersSlotStats.minTimeSlot, producersSlotStats.maxTimeSlot); } } }