Skip to content

Commit

Permalink
Slow down the dynamic batch size recovery for eth1 deposit tracker (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
g11tech committed Sep 23, 2022
1 parent 8cac35f commit 1708e4a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
12 changes: 10 additions & 2 deletions packages/beacon-node/src/eth1/eth1DepositDataTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,11 @@ export class Eth1DepositDataTracker {
let depositEvents;
try {
depositEvents = await this.eth1Provider.getDepositEvents(fromBlock, toBlock);
this.eth1GetLogsBatchSizeDynamic = Math.min(MAX_BLOCKS_PER_LOG_QUERY, this.eth1GetLogsBatchSizeDynamic * 2);
// Increase the batch size linearly even if we scale down exponentioanlly (half each time)
this.eth1GetLogsBatchSizeDynamic = Math.min(
MAX_BLOCKS_PER_LOG_QUERY,
this.eth1GetLogsBatchSizeDynamic + MIN_BLOCKS_PER_LOG_QUERY
);
} catch (e) {
if (isJsonRpcTruncatedError(e as Error) || e instanceof TimeoutError) {
this.eth1GetLogsBatchSizeDynamic = Math.max(
Expand Down Expand Up @@ -289,7 +293,11 @@ export class Eth1DepositDataTracker {
let blocksRaw;
try {
blocksRaw = await this.eth1Provider.getBlocksByNumber(fromBlock, toBlock);
this.eth1GetBlocksBatchSizeDynamic = Math.min(MAX_BLOCKS_PER_BLOCK_QUERY, this.eth1GetBlocksBatchSizeDynamic * 2);
// Increase the batch size linearly even if we scale down exponentioanlly (half each time)
this.eth1GetBlocksBatchSizeDynamic = Math.min(
MAX_BLOCKS_PER_BLOCK_QUERY,
this.eth1GetBlocksBatchSizeDynamic + MIN_BLOCKS_PER_BLOCK_QUERY
);
} catch (e) {
if (isJsonRpcTruncatedError(e as Error) || e instanceof TimeoutError) {
this.eth1GetBlocksBatchSizeDynamic = Math.max(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ describe("Eth1DepositDataTracker", function () {
expect(expectedSize).to.be.equal(10);

getBlocksByNumberStub.resolves([]);
for (let i = 0; i < 10; i++) {
expectedSize = Math.min(expectedSize * 2, 1000);
// Should take a whole longer to get back to the orignal batch size
for (let i = 0; i < 100; i++) {
expectedSize = Math.min(expectedSize + 10, 1000);
await eth1DepositDataTracker["updateBlockCache"](3000);
expect(eth1DepositDataTracker["eth1GetBlocksBatchSizeDynamic"]).to.be.equal(expectedSize);
}
Expand All @@ -83,8 +84,9 @@ describe("Eth1DepositDataTracker", function () {
expect(expectedSize).to.be.equal(10);

getDepositEventsStub.resolves([]);
for (let i = 0; i < 10; i++) {
expectedSize = Math.min(expectedSize * 2, 1000);
// Should take a whole longer to get back to the orignal batch size
for (let i = 0; i < 100; i++) {
expectedSize = Math.min(expectedSize + 10, 1000);
await eth1DepositDataTracker["updateDepositCache"](3000);
expect(eth1DepositDataTracker["eth1GetLogsBatchSizeDynamic"]).to.be.equal(expectedSize);
}
Expand Down

0 comments on commit 1708e4a

Please sign in to comment.