| 134 | } |
| 135 | |
| 136 | static u64 wait_index_bump(struct lightningd *ld, |
| 137 | struct db *db, |
| 138 | enum wait_subsystem subsystem, |
| 139 | enum wait_index index, |
| 140 | u64 num, |
| 141 | va_list ap_master) |
| 142 | { |
| 143 | struct waiter *i, *n; |
| 144 | u64 *idxval = wait_index_ptr(ld, subsystem, index); |
| 145 | |
| 146 | assert(!add_overflows_u64(*idxval, num)); |
| 147 | (*idxval) += num; |
| 148 | |
| 149 | /* FIXME: We can optimize this! It's always the max of the fields in |
| 150 | * the table, *unless* we delete one. So we can lazily write this on |
| 151 | * delete, and fix it up to MAX() when we startup. */ |
| 152 | db_set_intvar(db, |
| 153 | tal_fmt(tmpctx, "last_%s_%s_index", |
| 154 | wait_subsystem_name(subsystem), |
| 155 | wait_index_name(index)), |
| 156 | *idxval); |
| 157 | |
| 158 | list_for_each_safe(&ld->wait_commands, i, n, list) { |
| 159 | struct json_stream *response; |
| 160 | va_list ap; |
| 161 | |
| 162 | if (*i->subsystem != subsystem) |
| 163 | continue; |
| 164 | if (*i->index != index) |
| 165 | continue; |
| 166 | if (*idxval < *i->nextval) |
| 167 | continue; |
| 168 | |
| 169 | response = json_stream_success(i->cmd); |
| 170 | va_copy(ap, ap_master); |
| 171 | json_add_index(i->cmd, response, subsystem, index, *idxval, &ap); |
| 172 | va_end(ap); |
| 173 | /* Delete before freeing */ |
| 174 | list_del_from(&ld->wait_commands, &i->list); |
| 175 | was_pending(command_success(i->cmd, response)); |
| 176 | } |
| 177 | |
| 178 | return *idxval; |
| 179 | } |
| 180 | |
| 181 | u64 wait_index_increment(struct lightningd *ld, |
| 182 | struct db *db, |
no test coverage detected