Properly trylock consensus DB writes

This commit is contained in:
Garrett Mills 2021-04-10 14:42:39 -05:00
parent f072d81b5f
commit 1423e1961e
Signed by: garrettmills
GPG Key ID: D2BF5FBA8298F246
2 changed files with 2 additions and 3 deletions

View File

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

View File

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