MCPcopy Create free account
hub / github.com/ElementsProject/lightning / layer_trim_constraints

Function layer_trim_constraints

plugins/askrene/layer.c:1046–1100  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1044}
1045
1046size_t layer_trim_constraints(struct layer *layer, u64 cutoff)
1047{
1048 size_t num_removed = 0;
1049 struct constraint_hash_iter conit;
1050 struct constraint *con;
1051 struct bias_hash_iter biasit;
1052 struct bias *bias;
1053 struct node_bias_hash_iter node_it;
1054 struct node_bias *node_bias;
1055
1056 for (con = constraint_hash_first(layer->constraints, &conit);
1057 con;
1058 con = constraint_hash_next(layer->constraints, &conit)) {
1059 if (con->timestamp < cutoff) {
1060 constraint_hash_delval(layer->constraints, &conit);
1061 tal_free(con);
1062 num_removed++;
1063 }
1064 }
1065
1066 for (bias = bias_hash_first(layer->biases, &biasit); bias;
1067 bias = bias_hash_next(layer->biases, &biasit)) {
1068 if (bias->timestamp < cutoff) {
1069 bias_hash_delval(layer->biases, &biasit);
1070 tal_free(bias);
1071 num_removed++;
1072 }
1073 }
1074
1075 /* FIXME:
1076 * Having both in_bias and out_bias bundled in the same node bias
1077 * package help us save space. However we end up having a timestamp that
1078 * applies to both biases and we lose precision in that.
1079 * A possible pathological case is the following:
1080 * - in a certain moment we highly penalize a node A's outgoing
1081 * channels,
1082 * - then we often add or substract a small amount of bias to the
1083 * same node's incoming channels,
1084 * As long as we keep updating the incoming channels biases the data
1085 * timestamp will never grow old and we will never decay the outgoing
1086 * bias that we set at the begining.
1087 **/
1088 for (node_bias = node_bias_hash_first(layer->node_biases, &node_it);
1089 node_bias;
1090 node_bias = node_bias_hash_next(layer->node_biases, &node_it)) {
1091 if (node_bias->timestamp < cutoff) {
1092 node_bias_hash_delval(layer->node_biases, &node_it);
1093 tal_free(node_bias);
1094 num_removed++;
1095 }
1096 }
1097
1098 save_complete_layer(layer);
1099 return num_removed;
1100}
1101
1102void layer_add_disabled_node(struct layer *layer, const struct node_id *node)
1103{

Callers 1

json_askrene_ageFunction · 0.85

Calls 2

tal_freeFunction · 0.85
save_complete_layerFunction · 0.85

Tested by

no test coverage detected