示例#1
0
    def initialize_historical_root_hashes(self, root_hash: Hash32, timestamp: Timestamp) -> None:
        validate_is_bytes(root_hash, title='Head Hash')
        validate_historical_timestamp(timestamp, title="timestamp")

        #lets populate the root hash timestamp
        first_root_hash_timestamp = [[timestamp, root_hash]]
        self.save_historical_root_hashes(first_root_hash_timestamp)
示例#2
0
 def save_single_historical_root_hash(self, root_hash: Hash32, timestamp: Timestamp) -> None:
     validate_is_bytes(root_hash, title='Head Hash')
     validate_historical_timestamp(timestamp, title="timestamp")
     
     historical = self.get_historical_root_hashes()
     if historical is not None:
         historical = SortedList(historical)
         historical.add([timestamp, root_hash])
         historical = list(historical)
     else:
         historical = [[timestamp, root_hash]]
         
     self.save_historical_root_hashes(historical)
    def save_single_historical_root_hash(self, root_hash: Hash32,
                                         timestamp: Timestamp) -> None:
        validate_is_bytes(root_hash, title='Head Hash')
        validate_historical_timestamp(timestamp, title="timestamp")

        historical = self.get_historical_root_hashes()
        if historical is not None:
            historical_dict = dict(historical)
            historical_dict[timestamp] = root_hash
            historical = list(historical_dict.items())
        else:
            historical = [[timestamp, root_hash]]

        self.save_historical_root_hashes(historical)
示例#4
0
    def propogate_previous_historical_root_hash_to_timestamp(self, timestamp):
                
        validate_historical_timestamp(timestamp, title="timestamp")
        starting_timestamp, starting_root_hash = self.get_historical_root_hash(timestamp, return_timestamp = True)

        if starting_timestamp == None:
            raise AppendHistoricalRootHashTooOld("tried to propogate previous historical root hash, but there was no previous historical root hash")
        else:
            historical = SortedList(self.get_historical_root_hashes())
            
            if starting_timestamp == timestamp:
                #this means there is already a historical root hash for this time. Make sure it is correct. if not, delete it and all newer ones
                timestamp_for_previous_good_root_hash, previous_good_root_hash = self.get_historical_root_hash(timestamp-TIME_BETWEEN_HEAD_HASH_SAVE, return_timestamp = True)
                if starting_root_hash != previous_good_root_hash:
                    self.logger.debug("the existing historical root hash is incorrect. deleting this one and all future ones")
                    for timestamp_root_hash in reversed(historical.copy()):
                        if timestamp_root_hash[0] >= timestamp:
                            historical.pop()
                        
            for current_timestamp in range(starting_timestamp + TIME_BETWEEN_HEAD_HASH_SAVE, timestamp+TIME_BETWEEN_HEAD_HASH_SAVE, TIME_BETWEEN_HEAD_HASH_SAVE):
                self.logger.debug("propogating previous root hash to time {}".format(current_timestamp))
                historical.add([current_timestamp, starting_root_hash])
            
            self.save_historical_root_hashes(list(historical))