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

Reputation Miner Improvements #1168

Closed
wants to merge 1 commit into from
Closed
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
16 changes: 13 additions & 3 deletions packages/reputation-miner/ReputationMiner.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const minStake = ethers.BigNumber.from(10).pow(18).mul(2000);

const DAY_IN_SECONDS = 60 * 60 * 24;

const BLOCK_PAGING_SIZE = 1000000;

class ReputationMiner {
/**
* Constructor for ReputationMiner
Expand Down Expand Up @@ -1359,10 +1361,17 @@ class ReputationMiner {
if (!blockNumber) {
throw new Error("Block number not supplied to sync");
}
// Get the events
let events = [];
const latestBlockNumber = await this.realProvider.getBlockNumber();

const filter = this.colonyNetwork.filters.ReputationMiningCycleComplete(null, null);
filter.fromBlock = blockNumber;
const events = await this.realProvider.getLogs(filter);
filter.toBlock = Math.max(blockNumber - 1, 0);
while (filter.toBlock !== latestBlockNumber) {
filter.fromBlock = filter.toBlock + 1;
filter.toBlock = Math.min(filter.fromBlock + BLOCK_PAGING_SIZE, latestBlockNumber);
const partialEvents = await this.realProvider.getLogs(filter);
events = events.concat(partialEvents);
}
let localHash = await this.reputationTree.getRootHash();
let applyLogs = false;

Expand Down Expand Up @@ -1428,6 +1437,7 @@ class ReputationMiner {
// Some more cycles might have completed since we started syncing
const lastEventBlock = events[events.length - 1].blockNumber
filter.fromBlock = lastEventBlock;
filter.toBlock = "latest";
const sinceEvents = await this.realProvider.getLogs(filter);
if (sinceEvents.length > 1){
console.log("Some more cycles have completed during the sync process. Continuing to sync...")
Expand Down
4 changes: 3 additions & 1 deletion test/reputation-system/client-sync-functionality.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,10 @@ process.env.SOLIDITY_COVERAGE
useJsTree: true,
dbPath: fileName,
});

await reputationMiner3.initialise(colonyNetwork.address);
await reputationMiner3.sync("latest");
const latestBlock = await currentBlock();
await reputationMiner3.sync(parseInt(latestBlock.number, 10));

const loadedState = await reputationMiner3.getRootHash();
expect(loadedState).to.equal(currentState);
Expand Down