@ -38,6 +38,7 @@ struct SI_PEER {
uint64_t node_id ;
uint64_t node_id ;
uint32_t synced_pos ;
uint32_t synced_pos ;
uint8_t sync_state ;
uint8_t sync_state ;
uint8_t sync_retry_count ;
uint64_t sync_start_tb ;
uint64_t sync_start_tb ;
} ;
} ;
@ -400,7 +401,8 @@ static int db_verify_author_sig(struct DB_SYNC_INSTANCE* si,
uint8_t pubkey [ 32 ] ;
uint8_t pubkey [ 32 ] ;
if ( db_get_ed25519_pubkey ( si - > db_sync , author_node_id , pubkey ) ! = 0 ) {
if ( db_get_ed25519_pubkey ( si - > db_sync , author_node_id , pubkey ) ! = 0 ) {
DEBUG_WARN ( DEBUG_CATEGORY_DB_SYNC ,
DEBUG_WARN ( DEBUG_CATEGORY_DB_SYNC ,
" cannot get Ed25519 pubkey for author=%016llx " , ( unsigned long long ) author_node_id ) ;
" cannot get Ed25519 pubkey for author=%016llx — discarding " ,
( unsigned long long ) author_node_id ) ;
return - 1 ;
return - 1 ;
}
}
uint8_t msg [ 8192 ] ; size_t off = 0 ;
uint8_t msg [ 8192 ] ; size_t off = 0 ;
@ -408,8 +410,8 @@ static int db_verify_author_sig(struct DB_SYNC_INSTANCE* si,
if ( jlen > 0 ) { memcpy ( msg + off , json , jlen ) ; off + = jlen ; }
if ( jlen > 0 ) { memcpy ( msg + off , json , jlen ) ; off + = jlen ; }
if ( sc_ed25519_verify ( pubkey , msg , off , sig ) ! = SC_OK ) {
if ( sc_ed25519_verify ( pubkey , msg , off , sig ) ! = SC_OK ) {
DEBUG_WARN ( DEBUG_CATEGORY_DB_SYNC ,
DEBUG_WARN ( DEBUG_CATEGORY_DB_SYNC ,
" author_sig VERIFY FAIL node=%016llx — discarding as forgery " ,
" author_sig VERIFY FAIL author=%016llx ed_pubkey=%016llx... msg_len=%zu sig=%016llx... — discarding as forgery " ,
( unsigned long long ) author_node_id ) ;
( unsigned long long ) author_node_id , * ( uint64_t * ) pubkey , off , * ( uint64_t * ) sig ) ;
return - 1 ;
return - 1 ;
}
}
return 0 ;
return 0 ;
@ -981,14 +983,24 @@ static void db_handle_sync_done(struct DB_SYNC_INSTANCE* si, uint64_t src, const
( mc = = pc & & mch8 = = pch8 ) ? " matched " : " MISMATCH " ) ;
( mc = = pc & & mch8 = = pch8 ) ? " matched " : " MISMATCH " ) ;
if ( mc ! = pc | | mch8 ! = pch8 ) {
if ( mc ! = pc | | mch8 ! = pch8 ) {
struct SI_PEER * sp = si_peer_find ( si , src ) ;
if ( sp ) sp - > sync_retry_count + + ;
if ( sp & & sp - > sync_retry_count > 3 ) {
DEBUG_WARN ( DEBUG_CATEGORY_DB_SYNC ,
" SYNC_DONE mismatch retry limit exceeded (%u/3) with %016llx — giving up " ,
sp - > sync_retry_count , ( unsigned long long ) src ) ;
sp - > sync_state = 2 ; sp - > synced_pos = ( mc > 0 ) ? mc - 1 : 0 ;
return ;
}
DEBUG_INFO ( DEBUG_CATEGORY_DB_SYNC ,
DEBUG_INFO ( DEBUG_CATEGORY_DB_SYNC ,
" SYNC_DONE mismatch with %016llx my_count=%u peer_count=%u my_ch8=%016llx peer_ch8=%016llx — re-initiating " ,
" SYNC_DONE mismatch with %016llx my_count=%u peer_count=%u my_ch8=%016llx peer_ch8=%016llx — re-initiating (retry %u/3) " ,
( unsigned long long ) src , mc , pc , ( unsigned long long ) mch8 , ( unsigned long long ) pch8 ) ;
( unsigned long long ) src , mc , pc , ( unsigned long long ) mch8 , ( unsigned long long ) pch8 ,
sp ? sp - > sync_retry_count : 0 ) ;
db_sync_initiate_sync ( si , src ) ;
db_sync_initiate_sync ( si , src ) ;
return ;
return ;
}
}
struct SI_PEER * sp = si_peer_find ( si , src ) ;
struct SI_PEER * sp = si_peer_find ( si , src ) ;
if ( sp ) { sp - > synced_pos = ( mc > 0 ) ? mc - 1 : 0 ; sp - > sync_state = 2 ; }
if ( sp ) { sp - > synced_pos = ( mc > 0 ) ? mc - 1 : 0 ; sp - > sync_state = 2 ; sp - > sync_retry_count = 0 ; }
DEBUG_INFO ( DEBUG_CATEGORY_DB_SYNC , " sync confirmed with %016llx count=%u ch8=%016llx " ,
DEBUG_INFO ( DEBUG_CATEGORY_DB_SYNC , " sync confirmed with %016llx count=%u ch8=%016llx " ,
( unsigned long long ) src , mc , ( unsigned long long ) mch8 ) ;
( unsigned long long ) src , mc , ( unsigned long long ) mch8 ) ;
}
}
@ -1160,7 +1172,7 @@ static void db_sync_on_conn_up(struct ETCP_CONN* conn, void* arg)
if ( ! p ) continue ;
if ( ! p ) continue ;
if ( p - > sync_state ! = 0 ) { skipped_state + + ; continue ; }
if ( p - > sync_state ! = 0 ) { skipped_state + + ; continue ; }
if ( ! conn - > initialized | | ! conn - > links_up ) { skipped_not_ready + + ; continue ; }
if ( ! conn - > initialized | | ! conn - > links_up ) { skipped_not_ready + + ; continue ; }
p - > sync_state = 1 ;
p - > sync_state = 1 ; p - > sync_retry_count = 0 ;
db_sync_initiate_sync ( si , pid ) ;
db_sync_initiate_sync ( si , pid ) ;
synced + + ;
synced + + ;
}
}
@ -1206,7 +1218,7 @@ static void db_sync_initiate_sync(struct DB_SYNC_INSTANCE* si, uint64_t pid)
uint32_t mc = db_count ( si ) ;
uint32_t mc = db_count ( si ) ;
DEBUG_TRACE ( DEBUG_CATEGORY_DB_SYNC , " pid=%016llx my=%u tbl=%s " , ( unsigned long long ) pid , mc , SI_TBL ( si ) ) ;
DEBUG_TRACE ( DEBUG_CATEGORY_DB_SYNC , " pid=%016llx my=%u tbl=%s " , ( unsigned long long ) pid , mc , SI_TBL ( si ) ) ;
struct SI_PEER * p = si_peer_find ( si , pid ) ;
struct SI_PEER * p = si_peer_find ( si , pid ) ;
if ( p ) p - > sync_start_tb = get_time_tb ( ) ;
if ( p ) { p - > sync_start_tb = get_time_tb ( ) ; p - > sync_retry_count = 0 ; }
uint8_t msg [ 5 ] ;
uint8_t msg [ 5 ] ;
msg [ 0 ] = DB_MSG_INIT_SYNC ;
msg [ 0 ] = DB_MSG_INIT_SYNC ;