Compare commits
2 Commits
ff67a6b7e9
...
acb9739a80
Author | SHA1 | Date | |
---|---|---|---|
![]() |
acb9739a80 | ||
![]() |
c422881cd1 |
@ -993,7 +993,20 @@ export default class Services {
|
||||
// This is existing device, we need to catch up if last_scan is lagging behind chain_tip
|
||||
if (device.sp_wallet.last_scan < this.currentBlockHeight) {
|
||||
// We need to catch up
|
||||
try {
|
||||
await this.sdkClient.scan_blocks(this.currentBlockHeight, BLINDBITURL);
|
||||
} catch (e) {
|
||||
console.error(`Failed to scan blocks: ${e}`);
|
||||
return;
|
||||
}
|
||||
|
||||
// If everything went well, we can update our storage
|
||||
try {
|
||||
const device = this.dumpDeviceFromMemory();
|
||||
await this.saveDeviceInDatabase(device);
|
||||
} catch (e) {
|
||||
console.error(`Failed to save updated device: ${e}`);
|
||||
}
|
||||
} else {
|
||||
// Up to date, just returns
|
||||
return;
|
||||
@ -1406,8 +1419,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 +1439,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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user