def save_snapshot(serialization_file, raiden): all_channels = [ ChannelSerialization(channel) for network in raiden.token_to_channelgraph.values() for channel in network.address_to_channel.values() ] all_queues = list() for key, queue in raiden.protocol.channel_queue.items(): queue_data = { 'receiver_address': key[0], 'token_address': key[1], 'messages': queue.copy(), } all_queues.append(queue_data) data = { 'channels': all_channels, 'queues': all_queues, 'receivedhashes_to_acks': raiden.protocol.receivedhashes_to_acks, 'nodeaddresses_to_nonces': raiden.protocol.nodeaddresses_to_nonces, 'transfers': raiden.identifier_to_statemanagers, 'registry_address': ROPSTEN_REGISTRY_ADDRESS, } with open(serialization_file, 'wb') as handler: # __slots__ without __getstate__ require `-1` pickle.dump( data, handler, protocol=-1, )
def stop(self): wait_for = [self.alarm] wait_for.extend(self.greenlet_task_dispatcher.stop()) self.alarm.stop_async() wait_for.extend(self.protocol.greenlets) self.pyethapp_blockchain_events.uninstall_all_event_listeners() self.protocol.stop_and_wait() if self.channels_serialization_path: with open(self.channels_serialization_path, 'wb') as handler: for network in self.channelgraphs.values(): for channel in network.address_channel.values(): pickle.dump( ChannelSerialization(channel), handler, ) if self.channels_queue_path: with open(self.channels_queue_path, 'wb') as handler: queues = list() for key, queue in self.protocol.channel_queue.iteritems(): queue_data = { 'receiver_address': key[0], 'token_address': key[1], 'messages': [ queue_item.messagedata for queue_item in queue ] } queues.append(queue_data) pickle.dump( { 'channel_queues': queues, 'receivedhashes_acks': self.protocol.receivedhashes_acks, 'nodeaddresses_nonces': self.protocol.nodeaddresses_nonces, }, handler, ) gevent.wait(wait_for)