Skip to content

Commit

Permalink
chore: rename the default gossip queue to LinearGossipQueue
Browse files Browse the repository at this point in the history
  • Loading branch information
twoeths committed Jul 5, 2023
1 parent 4445e5f commit 256cd4a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {mapValues} from "@lodestar/utils";
import {GossipType} from "../../gossip/interface.js";
import {PendingGossipsubMessage} from "../types.js";
import {getAttDataBase64FromAttestationSerialized} from "../../../util/sszBytes.js";
import {DefaultGossipQueue} from "./default.js";
import {LinearGossipQueue} from "./linear.js";
import {DropType, GossipQueue, GossipQueueOpts, QueueType, isIndexedGossipQueueOpts} from "./types.js";
import {IndexedGossipQueue} from "./indexed.js";

Expand Down Expand Up @@ -96,7 +96,7 @@ export function createGossipQueues(): {[K in GossipType]: GossipQueue<PendingGos
if (isIndexedGossipQueueOpts(opts)) {
return new IndexedGossipQueue(opts);
} else {
return new DefaultGossipQueue<PendingGossipsubMessage>(opts);
return new LinearGossipQueue<PendingGossipsubMessage>(opts);
}
});
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import {LinkedList} from "../../../util/array.js";
import {DefaultGossipQueueOpts, DropType, GossipQueue, QueueType} from "./types.js";
import {LinearGossipQueueOpts, DropType, GossipQueue, QueueType} from "./types.js";

// Having a drop ratio of 1 will empty the queue which is too severe
// Worse case drop 95% of the queue
const MAX_DROP_RATIO = 0.95;

export class DefaultGossipQueue<T> implements GossipQueue<T> {
/**
* Default gossip queue for all topics except for beacon_attestation
* Support LIFO and FIFO type.
*/
export class LinearGossipQueue<T> implements GossipQueue<T> {
private readonly list = new LinkedList<T>();
// Increase _dropRatio gradually, retest its initial value if node is in good status
private _dropRatio = 0;
Expand All @@ -15,7 +19,7 @@ export class DefaultGossipQueue<T> implements GossipQueue<T> {
// set recentDrop to false after we process up to maxLength items
private processedCountSinceDrop = 0;

constructor(private readonly opts: DefaultGossipQueueOpts) {
constructor(private readonly opts: LinearGossipQueueOpts) {
if (opts.dropOpts.type === DropType.ratio) {
const {start, step} = opts.dropOpts;
if (start <= 0 || start > 1) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export type GossipQueueOpts<T> = DefaultGossipQueueOpts | IndexedGossipQueueOpts<T>;
export type GossipQueueOpts<T> = LinearGossipQueueOpts | IndexedGossipQueueOpts<T>;

export type DefaultGossipQueueOpts = {
export type LinearGossipQueueOpts = {
type: QueueType;
maxLength: number;
dropOpts: DropOpts;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {expect} from "chai";
import {DefaultGossipQueue} from "../../../../../src/network/processor/gossipQueues/default.js";
import {LinearGossipQueue} from "../../../../../src/network/processor/gossipQueues/linear.js";
import {DropType} from "../../../../../src/network/processor/gossipQueues/types.js";
import {QueueType} from "../../../../../src/util/queue/index.js";

describe("DefaultGossipQueues - drop by ratio", () => {
const gossipQueue = new DefaultGossipQueue<number>({
const gossipQueue = new LinearGossipQueue<number>({
maxLength: 10,
type: QueueType.LIFO,
dropOpts: {type: DropType.ratio, start: 0.1, step: 0.2},
Expand Down Expand Up @@ -68,7 +68,7 @@ describe("DefaultGossipQueues - drop by ratio", () => {
});

describe("GossipQueues - drop by count", () => {
const gossipQueue = new DefaultGossipQueue<number>({
const gossipQueue = new LinearGossipQueue<number>({
maxLength: 10,
type: QueueType.LIFO,
dropOpts: {type: DropType.count, count: 1},
Expand Down

0 comments on commit 256cd4a

Please sign in to comment.