Skip to content

Commit

Permalink
Merge pull request #3513 from OriginTrail/v8/codeCleanup
Browse files Browse the repository at this point in the history
getBatchSize,getMinAckResponses functions use user provided values
  • Loading branch information
Mihajlo-Pavlovic authored Dec 18, 2024
2 parents 1d69640 + 70dfb66 commit b55bd7f
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 18 deletions.
5 changes: 3 additions & 2 deletions src/commands/local-store/local-store-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class LocalStoreCommand extends Command {
contract,
tokenId,
minimumNumberOfNodeReplications,
batchSize,
} = command.data;

try {
Expand Down Expand Up @@ -233,14 +234,14 @@ class LocalStoreCommand extends Command {
publisherNodeVS,
);

const batchSize = this.operationService.getBatchSize();
const batchSizePar = this.operationService.getBatchSize(batchSize);
const minAckResponses = this.operationService.getMinAckResponses(
minimumNumberOfNodeReplications,
);

const updatedData = {
...command.data,
batchSize,
batchSize: batchSizePar,
minAckResponses,
};

Expand Down
7 changes: 4 additions & 3 deletions src/commands/protocols/common/network-protocol-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ class NetworkProtocolCommand extends Command {
* @param command
*/
async execute(command) {
const { blockchain, operationId, minimumNumberOfNodeReplications } = command.data;
const { blockchain, operationId, minimumNumberOfNodeReplications, batchSize } =
command.data;

this.operationIdService.emitChangeEvent(this.operationStartEvent, operationId, blockchain);

const batchSize = this.operationService.getBatchSize();
const batchSizePar = this.operationService.getBatchSize(batchSize);
const minAckResponses = this.operationService.getMinAckResponses(
minimumNumberOfNodeReplications,
);
Expand All @@ -36,7 +37,7 @@ class NetworkProtocolCommand extends Command {
delay: 0,
data: {
...command.data,
batchSize,
batchSize: batchSizePar,
minAckResponses,
errorType: this.errorType,
},
Expand Down
14 changes: 14 additions & 0 deletions src/constants/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@ export const HTTP_RPC_PROVIDER_PRIORITY = 1;

export const FALLBACK_PROVIDER_QUORUM = 1;

export const PUBLISH_BATCH_SIZE = 20;

export const PUBLISH_MIN_NUM_OF_NODE_REPLICATIONS = 3;

export const GET_BATCH_SIZE = 2;

export const GET_MIN_NUM_OF_NODE_REPLICATIONS = 1;

export const FINALITY_BATCH_SIZE = 1;

export const FINALITY_MIN_NUM_OF_NODE_REPLICATIONS = 1;

export const ASK_BATCH_SIZE = 20;

export const RPC_PROVIDER_STALL_TIMEOUT = 60 * 1000;

export const UINT256_MAX_BN = ethers.constants.MaxUint256;
Expand Down
5 changes: 3 additions & 2 deletions src/service/ask-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
ERROR_TYPE,
OPERATIONS,
OPERATION_REQUEST_STATUS,
ASK_BATCH_SIZE,
} from '../constants/constants.js';

class AskService extends OperationService {
Expand Down Expand Up @@ -102,8 +103,8 @@ class AskService extends OperationService {
}
}

getBatchSize() {
return 20;
getBatchSize(batchSize = null) {
return batchSize ?? ASK_BATCH_SIZE;
}
}

Expand Down
10 changes: 6 additions & 4 deletions src/service/finality-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
ERROR_TYPE,
OPERATIONS,
OPERATION_REQUEST_STATUS,
FINALITY_BATCH_SIZE,
FINALITY_MIN_NUM_OF_NODE_REPLICATIONS,
} from '../constants/constants.js';

class FinalityService extends OperationService {
Expand Down Expand Up @@ -71,12 +73,12 @@ class FinalityService extends OperationService {
}
}

getBatchSize() {
return 1;
getBatchSize(batchSize = null) {
return batchSize ?? FINALITY_BATCH_SIZE;
}

getMinAckResponses() {
return 1;
getMinAckResponses(minimumNumberOfNodeReplications = null) {
return minimumNumberOfNodeReplications ?? FINALITY_MIN_NUM_OF_NODE_REPLICATIONS;
}
}

Expand Down
10 changes: 6 additions & 4 deletions src/service/get-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
ERROR_TYPE,
OPERATIONS,
OPERATION_REQUEST_STATUS,
GET_BATCH_SIZE,
GET_MIN_NUM_OF_NODE_REPLICATIONS,
} from '../constants/constants.js';

class GetService extends OperationService {
Expand Down Expand Up @@ -89,12 +91,12 @@ class GetService extends OperationService {
}
}

getBatchSize() {
return 2;
getBatchSize(batchSize = null) {
return batchSize ?? GET_BATCH_SIZE;
}

getMinAckResponses() {
return 1;
getMinAckResponses(minimumNumberOfNodeReplications = null) {
return minimumNumberOfNodeReplications ?? GET_MIN_NUM_OF_NODE_REPLICATIONS;
}
}

Expand Down
8 changes: 5 additions & 3 deletions src/service/publish-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
NETWORK_PROTOCOLS,
ERROR_TYPE,
OPERATIONS,
PUBLISH_BATCH_SIZE,
PUBLISH_MIN_NUM_OF_NODE_REPLICATIONS,
} from '../constants/constants.js';

class PublishService extends OperationService {
Expand Down Expand Up @@ -100,12 +102,12 @@ class PublishService extends OperationService {
}
}

getBatchSize() {
return 20;
getBatchSize(batchSize = null) {
return batchSize ?? PUBLISH_BATCH_SIZE;
}

getMinAckResponses(minimumNumberOfNodeReplications = null) {
return minimumNumberOfNodeReplications ?? 10;
return minimumNumberOfNodeReplications ?? PUBLISH_MIN_NUM_OF_NODE_REPLICATIONS;
}
}

Expand Down

0 comments on commit b55bd7f

Please sign in to comment.