Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add rebalance interval #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ import humanizeDuration from "humanize-duration";
import pTimeout from "p-timeout";

import { formatCTSI } from "./util";
import { CONFIRMATIONS, CONFIRMATION_TIMEOUT } from "./config";
import {
CONFIRMATIONS,
CONFIRMATION_TIMEOUT,
REBALANCE_INTERVAL,
} from "./config";
import { ProtocolClient } from "./pos";
import * as monitoring from "./monitoring";
import { constants } from "ethers";
Expand All @@ -23,8 +27,8 @@ const explorerUrl = "https://explorer.cartesi.io/staking";

export class BlockProducer {
private address: string;

private client: ProtocolClient;
private lastRebalanceCall = 0;

constructor(address: string, client: ProtocolClient) {
this.address = address;
Expand Down Expand Up @@ -185,7 +189,10 @@ export class BlockProducer {
}

async rebalance() {
// XXX: what should we do with the boolean return value?
await this.client.rebalance();
const currentTimestamp = new Date().getTime();
if (currentTimestamp < this.lastRebalanceCall + REBALANCE_INTERVAL)
return;
if (await this.client.rebalance())
this.lastRebalanceCall = currentTimestamp;
}
}
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { parseEther } from "@ethersproject/units";
export const TIMEOUT = 24 * 60 * 60 * 1000;
export const RETRY_INTERVAL = 10000;
export const POLLING_INTERVAL = 30000;
export const REBALANCE_INTERVAL = 0;
export const CONFIRMATIONS = 1;
export const CONFIRMATION_TIMEOUT = 10 * 60 * 1000; // 10 minutes
export const GAS_LIMIT_MULTIPLIER = 160;
Expand Down
4 changes: 3 additions & 1 deletion src/pos/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,10 @@ export class PoolProtocolImpl extends AbstractProtocolClient {

// increment rebalance counter
monitoring.rebalance.inc();

return true;
}

return true;
return false;
}
}