*Add mutex lock around syncing to prevent race conditions
This commit is contained in:
parent
9beb2a6c58
commit
236338485b
|
@ -31,6 +31,7 @@ import * as phase0 from "@lodestar/types/phase0";
|
|||
import * as bellatrix from "@lodestar/types/bellatrix";
|
||||
import { init } from "@chainsafe/bls/switchable";
|
||||
import NodeCache from "node-cache";
|
||||
import { Mutex } from "async-mutex";
|
||||
|
||||
export default class Client {
|
||||
latestCommittee?: Uint8Array[];
|
||||
|
@ -46,6 +47,8 @@ export default class Client {
|
|||
private beaconChainAPIURL: string;
|
||||
private store: IStore;
|
||||
|
||||
private syncMutex = new Mutex();
|
||||
|
||||
constructor(prover: IProver, store: IStore, beaconUrl: string) {
|
||||
this.prover = prover;
|
||||
this.store = store;
|
||||
|
@ -228,11 +231,15 @@ export default class Client {
|
|||
}
|
||||
|
||||
protected async _sync() {
|
||||
await this.syncMutex.acquire();
|
||||
|
||||
const currentPeriod = this.getCurrentPeriod();
|
||||
if (currentPeriod > this._latestPeriod) {
|
||||
this.latestCommittee = await this.syncFromGenesis();
|
||||
this._latestPeriod = currentPeriod;
|
||||
}
|
||||
|
||||
this.syncMutex.release();
|
||||
}
|
||||
|
||||
// committee and prover index of the first honest prover
|
||||
|
|
Loading…
Reference in New Issue