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

add overflow warnings to linear sum, fix max distance calculation #2981

Merged
merged 1 commit into from
Feb 14, 2024
Merged
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
6 changes: 6 additions & 0 deletions src/service/proximity-scoring-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,19 @@ class ProximityScoringService {

let normalizedDistance = scaledDistance.div(adjustedDivisor);
if (normalizedDistance.gt(UINT64_MAX_BN)) {
this.logger.warn(
`Invalid normalized distance: ${normalizedDistance.toString()}. Max value: ${UINT64_MAX_BN.toString()}`,
);
normalizedDistance = normalizedDistance.mod(UINT64_MAX_BN.add(1));
}

let normalizedStake = stakeScaleFactor
.mul(mappedStake.sub(mappedMinStake))
.div(mappedMaxStake.sub(mappedMinStake));
if (normalizedStake.gt(UINT64_MAX_BN)) {
this.logger.warn(
`Invalid normalized stake: ${normalizedDistance.toString()}. Max value: ${UINT64_MAX_BN.toString()}`,
);
normalizedStake = normalizedStake.mod(UINT64_MAX_BN.add(1));
}

Expand Down
11 changes: 5 additions & 6 deletions src/service/service-agreement-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,11 @@ class ServiceAgreementService {
);
let maxNeighborhoodDistance;
if (neighbourhoodEdges) {
maxNeighborhoodDistance = await this.proximityScoringService.callProximityFunction(
blockchainId,
proximityScoreFunctionsPairId,
neighbourhoodEdges.leftEdge[hashFunctionName],
neighbourhoodEdges.rightEdge[hashFunctionName],
);
maxNeighborhoodDistance = neighbourhoodEdges.leftEdge.distance.gt(
neighbourhoodEdges.rightEdge.distance,
)
? neighbourhoodEdges.leftEdge.distance
: neighbourhoodEdges.rightEdge.distance;
}

return this.proximityScoringService.callScoreFunction(
Expand Down
5 changes: 2 additions & 3 deletions src/service/sharding-table-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class ShardingTableService {
const hashFunctionName = this.hashingService.getHashFunctionName(hashFunctionId);
const peersWithDistance = await Promise.all(
peers.map(async (peer) => ({
peer,
...peer,
distance: await this.proximityScoringService.callProximityFunction(
blockchainId,
proximityScoreFunctionsPairId,
Expand All @@ -158,8 +158,7 @@ class ShardingTableService {
}
return 0;
});
const result = peersWithDistance.slice(0, count).map((pd) => pd.peer);
return result;
return peersWithDistance.slice(0, count);
}

async getBidSuggestion(
Expand Down
Loading