@ -525,44 +525,6 @@ int gossip_store_readonly_fd(struct gossip_store *gs)
return fd ;
}
/* If we ever truncated, we might have a dangling entries. */
static void cleanup_truncated_store ( struct routing_state * rstate ,
struct gossip_store * gs ,
u32 chan_ann_off )
{
size_t num ;
u32 index ;
/* channel_announce with no channel_amount. */
if ( chan_ann_off ) {
status_unusual ( " Deleting un-amounted channel_announcement @%u " ,
chan_ann_off ) ;
delete_by_index ( gs , chan_ann_off , WIRE_CHANNEL_ANNOUNCEMENT ) ;
}
num = 0 ;
while ( ( index = remove_unfinalized_node_announce ( rstate ) ) ! = 0 ) {
delete_by_index ( gs , index , WIRE_NODE_ANNOUNCEMENT ) ;
num + + ;
}
if ( num )
status_unusual ( " Deleted %zu unfinalized node_announcements " ,
num ) ;
num = 0 ;
while ( ( index = remove_unupdated_channel_announce ( rstate ) ) ! = 0 ) {
u32 next ;
/* Delete announcement and channel amount, too */
next = delete_by_index ( gs , index , WIRE_CHANNEL_ANNOUNCEMENT ) ;
delete_by_index ( gs , next , WIRE_GOSSIP_STORE_CHANNEL_AMOUNT ) ;
num + + ;
}
if ( num )
status_unusual ( " Deleted %zu unupdated channel_announcements " ,
num ) ;
}
bool gossip_store_load ( struct routing_state * rstate , struct gossip_store * gs )
{
struct gossip_hdr hdr ;
@ -672,25 +634,36 @@ bool gossip_store_load(struct routing_state *rstate, struct gossip_store *gs)
clean_tmpctx ( ) ;
}
if ( chan_ann ) {
status_unusual ( " gossip_store: dangling channel_announcement " ) ;
goto truncate_nomsg ;
}
bad = unfinalized_entries ( tmpctx , rstate ) ;
if ( bad ) {
status_unusual ( " gossip_store: %s " , bad ) ;
goto truncate_nomsg ;
}
/* If last timestamp is within 24 hours, say we're OK. */
contents_ok = ( last_timestamp > = time_now ( ) . ts . tv_sec - 24 * 3600 ) ;
goto out ;
truncate :
status_unusual ( " gossip_store: %s (%s) truncating to % " PRIu64 ,
bad , tal_hex ( msg , msg ) , gs - > len ) ;
status_unusual ( " gossip_store: %s (%s) truncating " ,
bad , tal_hex ( msg , msg ) ) ;
truncate_nomsg :
/* FIXME: We would like to truncate to known_good, except we would
* miss channel_delete msgs . If we put block numbers into the store
* as we process them , we can know how far we need to roll back if we
* truncate the store */
if ( ftruncate ( gs - > fd , gs - > len ) ! = 0 )
/* FIXME: Debug partial truncate case. */
if ( ftruncate ( gs - > fd , 1 ) ! = 0 )
status_failed ( STATUS_FAIL_INTERNAL_ERROR ,
" Truncating store: %s " , strerror ( errno ) ) ;
remove_all_gossip ( rstate ) ;
gs - > count = gs - > deleted = 0 ;
gs - > len = 1 ;
contents_ok = false ;
out :
gs - > writable = true ;
cleanup_truncated_store ( rstate , gs , chan_ann ? chan_ann_off : 0 ) ;
status_trace ( " total store load time: % " PRIu64 " msec " ,
time_to_msec ( time_between ( time_now ( ) , start ) ) ) ;
status_trace ( " gossip_store: Read %zu/%zu/%zu/%zu cannounce/cupdate/nannounce/cdelete from store (%zu deleted) in % " PRIu64 " bytes " ,