[bug] Failed to update tips

This commit is contained in:
Sosthene 2025-09-02 13:30:05 +02:00
parent 19da967605
commit c422881cd1

View File

@ -1406,8 +1406,17 @@ export default class Services {
let new_states = [];
let roles = [];
for (const state of process.states) {
if (!state.state_id || state.state_id === EMPTY32BYTES) { continue; }
if (!this.lookForStateId(existing, state.state_id)) {
if (!state || !state.state_id) { continue; } // shouldn't happen
if (state.state_id === EMPTY32BYTES) {
// We check that the tip is the same we have, if not we update
const existingTip = existing.states[existing.states.length - 1].commited_in;
if (existingTip !== state.commited_in) {
console.log('Found new tip for process', processId);
// We update the process
new_states.push(state.state_id);
roles.push(state.roles);
}
} else if (!this.lookForStateId(existing, state.state_id)) {
if (this.rolesContainsUs(state.roles)) {
new_states.push(state.state_id);
roles.push(state.roles);
@ -1417,6 +1426,12 @@ export default class Services {
if (new_states.length != 0) {
// We request the new states
// filter out the empty state, if any
// empty state will always be last, so that's easy
if (new_states.findLast(state => state === EMPTY32BYTES)) {
new_states.pop();
roles.pop();
}
await this.requestDataFromPeers(processId, new_states, roles);
toSave[processId] = process;
}