Skip to content

Commit

Permalink
Improve fast-failure of oracle endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
area authored and kronosapiens committed Jul 25, 2022
1 parent 694d6fc commit 53afbe4
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions packages/reputation-miner/ReputationMiner.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ class ReputationMiner {
);

this.queries.getReputationStateCount = this.db.prepare(`SELECT COUNT ( * ) AS "n" FROM reputation_states WHERE root_hash=? AND n_leaves=?`);
this.queries.getReputationHashCount = this.db.prepare(`SELECT COUNT ( * ) AS "n" FROM reputation_states WHERE root_hash=?`);
}

/**
Expand Down Expand Up @@ -901,8 +902,8 @@ class ReputationMiner {

// Not in the accepted or next tree, so let's look at the DB

const allReputations = await this.queries.getAllReputationsInHash.all(rootHash);
if (allReputations.length === 0) {
const res = await this.queries.getReputationHashCount.get(rootHash);
if (res.n === 0){
return new Error("No such reputation state");
}

Expand All @@ -922,6 +923,8 @@ class ReputationMiner {
const tree = new PatriciaTree();
// Load all reputations from that state.

const allReputations = await this.queries.getAllReputationsInHash.all(rootHash);

for (let i = 0; i < allReputations.length; i += 1) {
const row = allReputations[i];
const rowKey = ReputationMiner.getKey(row.colony_address, row.skill_id, row.user_address);
Expand Down Expand Up @@ -955,10 +958,11 @@ class ReputationMiner {
return new Error("Requested reputation does not exist")
}

let res = await this.queries.getAllReputationsInHash.all(rootHash);
if (res.length === 0) {
let res = await this.queries.getReputationHashCount.get(rootHash);
if (res.n === 0){
return new Error("No such reputation state");
}

const keyElements = ReputationMiner.breakKeyInToElements(key);
const [colonyAddress, , userAddress] = keyElements;
const skillId = parseInt(keyElements[1], 16);
Expand Down

0 comments on commit 53afbe4

Please sign in to comment.