@lodestar/beacon-node
Version:
A Typescript implementation of the beacon chain
38 lines • 1.5 kB
JavaScript
import { Repository } from "@lodestar/db";
import { ssz } from "@lodestar/types";
import { Bucket, getBucketNameByValue } from "../buckets.js";
/**
* AttesterSlashing indexed by root
*
* Added via gossip or api
* Removed when included on chain or old
*/
export class AttesterSlashingRepository extends Repository {
constructor(config, db) {
const bucket = Bucket.allForks_attesterSlashing;
/**
* We are using `ssz.electra.AttesterSlashing` type since it is backward compatible with `ssz.phase0.AttesterSlashing`
* But this also means the length of `attestingIndices` is not checked/enforced here. Need to make sure length
* is correct before writing to db.
*/
const type = ssz.electra.AttesterSlashing;
super(config, db, bucket, type, getBucketNameByValue(bucket));
}
async hasAll(attesterIndices = []) {
const attesterSlashings = (await this.values()) ?? [];
const indices = new Set();
for (const slashing of attesterSlashings) {
for (const index of slashing.attestation1.attestingIndices)
indices.add(index);
for (const index of slashing.attestation2.attestingIndices)
indices.add(index);
}
for (const attesterIndice of attesterIndices) {
if (!indices.has(attesterIndice)) {
return false;
}
}
return true;
}
}
//# sourceMappingURL=attesterSlashing.js.map