Skip to content

Commit a59f038

Browse files
committed
gossip: handle identity change in sampler state
1 parent 61cf654 commit a59f038

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

src/flamenco/gossip/crds/fd_crds.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1100,7 +1100,7 @@ fd_crds_insert( fd_crds_t * crds,
11001100

11011101
crds_contact_info_evict_dlist_ele_push_tail( crds->contact_info.evict_dlist, candidate, crds->pool );
11021102

1103-
if( FD_LIKELY( !is_from_me ) ){
1103+
if( FD_LIKELY( !is_from_me ) ) {
11041104
crds_contact_info_fresh_list_ele_push_tail( crds->contact_info.fresh_dlist, candidate, crds->pool );
11051105
candidate->contact_info.fresh_dlist.in_list = 1;
11061106
} else {
@@ -1225,6 +1225,21 @@ fd_crds_peer_sample( fd_crds_t const * crds,
12251225
return crds_contact_info_pool_ele( crds->contact_info.pool, idx )->contact_info;
12261226
}
12271227

1228+
void
1229+
fd_crds_handle_identity_change( fd_crds_t * crds,
1230+
uchar const * new_identity_pubkey ) {
1231+
fd_crds_key_t old_key[1];
1232+
make_contact_info_key( new_identity_pubkey, old_key );
1233+
fd_crds_entry_t * new_ci = lookup_map_ele_query( crds->lookup_map, old_key, NULL, crds->pool );
1234+
if( FD_UNLIKELY( !new_ci ) ) return;
1235+
1236+
ulong new_idx = crds_contact_info_pool_idx( crds->contact_info.pool, new_ci->contact_info.ci );
1237+
1238+
wpeer_sampler_upd( crds->crds_sampler, 0UL, new_idx );
1239+
crds->change_fn( crds->change_fn_ctx, new_idx, new_ci->stake, FD_CRDS_CONTACT_INFO_CHANGE_IDENTITY_CHANGED, NULL, 0L );
1240+
1241+
}
1242+
12281243
struct fd_crds_mask_iter_private {
12291244
ulong idx;
12301245
ulong end_hash;

src/flamenco/gossip/crds/fd_crds.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ typedef struct fd_crds_mask_iter_private fd_crds_mask_iter_t;
3434
#define FD_CRDS_CONTACT_INFO_CHANGE_TYPE_NEW (0)
3535
#define FD_CRDS_CONTACT_INFO_CHANGE_TYPE_REMOVED (1)
3636
#define FD_CRDS_CONTACT_INFO_CHANGE_TYPE_STAKE_CHANGED (2)
37+
#define FD_CRDS_CONTACT_INFO_CHANGE_IDENTITY_CHANGED (3)
3738

3839
typedef void (*fd_crds_ci_change_fn)( void * ctx,
3940
ulong crds_pool_idx,
@@ -308,6 +309,10 @@ fd_contact_info_t const *
308309
fd_crds_peer_sample( fd_crds_t const * crds,
309310
fd_rng_t * rng );
310311

312+
void
313+
fd_crds_handle_identity_change( fd_crds_t * crds,
314+
uchar const * new_identity_pubkey );
315+
311316
/* fd_crds_mask_iter_{init,next,done,entry} provide an API to
312317
iterate over the CRDS values in the table that whose hashes match
313318
a given mask. In the Gossip CRDS filter, the mask is applied on

src/flamenco/gossip/fd_active_set.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ fd_active_set_rotate( fd_active_set_t * active_set,
285285
last_hit_idx_remove( active_set->last_hit, replace_idx, active_set->entry_pool );
286286

287287
/* Replaced peer needs to be reinserted into bucket's sampler */
288-
peer_meta_t * e = &active_set->peer_metas[ crds_idx ];
288+
peer_meta_t * e = &active_set->peer_metas[ crds_idx ];
289289
ulong score = peer_bucket_score( e->stake, bucket_idx );
290290
e->bucket_idx[ bucket_idx ] = BUCKET_ENTRY_IDX_SENTINEL;
291291
wpeer_sampler_upd( bucket->sampler, score, crds_idx );

src/flamenco/gossip/fd_gossip.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,16 @@ ci_change( void * _ctx,
371371
}
372372
break;
373373
case FD_CRDS_CONTACT_INFO_CHANGE_TYPE_STAKE_CHANGED: fd_active_set_peer_update_stake( ctx->active_set, crds_pool_idx, stake ); break;
374+
case FD_CRDS_CONTACT_INFO_CHANGE_IDENTITY_CHANGED:
375+
{
376+
FD_TEST( stem==NULL );
377+
fd_active_set_push_state_t states_to_reset[ FD_ACTIVE_SET_STAKE_BUCKETS ];
378+
ulong state_cnt = fd_active_set_peer_remove( ctx->active_set, crds_pool_idx, states_to_reset );
379+
for( ulong i=0UL; i<state_cnt; i++ ) {
380+
fd_gossip_txbuild_init( states_to_reset[i].txbuild, FD_GOSSIP_MESSAGE_PUSH );
381+
}
382+
}
383+
break;
374384
default: FD_LOG_ERR(( "Unknown change type %d", change_type )); return;
375385
}
376386
}
@@ -412,6 +422,11 @@ void
412422
fd_gossip_set_my_contact_info( fd_gossip_t * gossip,
413423
fd_contact_info_t const * contact_info,
414424
long now ) {
425+
if( FD_UNLIKELY( memcmp( gossip->identity_pubkey, contact_info->pubkey.uc, 32UL ) ) ){
426+
FD_LOG_WARNING(( "Changing identity pubkey" ));
427+
fd_crds_handle_identity_change( gossip->crds, contact_info->pubkey.uc );
428+
429+
}
415430
fd_memcpy( gossip->identity_pubkey, contact_info->pubkey.uc, 32UL );
416431

417432
*gossip->my_contact_info.ci = *contact_info;

0 commit comments

Comments
 (0)