Properly trylock consensus DB writes

working-state
Garrett Mills 3 years ago
parent f072d81b5f
commit 1423e1961e
Signed by: garrettmills
GPG Key ID: D2BF5FBA8298F246

@ -79,8 +79,6 @@ export class FirebaseResource<T extends FirebaseResourceItem> extends Iterable<T
* @param item
*/
async push(item: T): Promise<T> {
await this.firebase.trylock(this.refName)
await this.ref().transaction((collection) => {
if ( !collection ) collection = []
item.seqID = this.findNextId(collection)
@ -103,7 +101,6 @@ export class FirebaseResource<T extends FirebaseResourceItem> extends Iterable<T
})
})
await this.firebase.unlock(this.refName)
return item
}

@ -281,6 +281,7 @@ export class Blockchain extends Unit {
this.isSubmitting = true
}
await this.firebase.trylock('block')
const validSeqID = (await this.read()).reverse()[0]?.seqID
const peers = await this.getPeers()
@ -347,6 +348,7 @@ export class Blockchain extends Unit {
await this.attemptSubmit()
}
await this.firebase.unlock('block')
this.isSubmitting = false
}

Loading…
Cancel
Save