Skip to content

Commit

Permalink
update operator from OR to AND
Browse files Browse the repository at this point in the history
  • Loading branch information
AnaDjokovic committed Aug 18, 2023
2 parents acb847a + 0b7dd5f commit 4c7f821
Show file tree
Hide file tree
Showing 13 changed files with 87 additions and 37 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "origintrail_node",
"version": "6.0.12",
"version": "6.0.13",
"description": "OTNode V6",
"main": "index.js",
"type": "module",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@ class HandleProtocolMessageCommand extends Command {
.mul(epochsLeft)
.mul(blockchainAssertionSize);

const serviceAgreementBid = this.blockchainModuleManager
.toBigNumber(blockchain, agreementData.tokenAmount)
const serviceAgreementBid = agreementData.tokenAmount
.add(agreementData.updateTokenAmount)
.mul(1024)
.div(divisor)
Expand Down
6 changes: 3 additions & 3 deletions src/modules/network/implementation/libp2p-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ class Libp2pService {
*/
this.sessions = {};
this.node = await libp2p.create(initializationObject);
const port = parseInt(this.node.multiaddrs.toString().split('/')[4], 10);
const peerId = this.node.peerId.toB58String();
this.config.id = peerId;
this.logger.info(`Network ID is ${peerId}, connection port is ${port}`);
}

async start() {
this.node.start();
await this.node.start();
const port = parseInt(this.node.multiaddrs.toString().split('/')[4], 10);
this.logger.info(`Network ID is ${this.config.id}, connection port is ${port}`);
}

async onPeerConnected(listener) {
Expand Down
31 changes: 22 additions & 9 deletions src/service/sharding-table-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ class ShardingTableService {
firstAssertionId,
hashFunctionId,
) {
const kbSize = assertionSize < BYTES_IN_KILOBYTE ? BYTES_IN_KILOBYTE : assertionSize;
const peerRecords = await this.findNeighbourhood(
blockchainId,
this.blockchainModuleManager.encodePacked(
Expand All @@ -164,20 +163,34 @@ class ShardingTableService {
hashFunctionId,
true,
);

const sorted = peerRecords.sort((a, b) => a.ask - b.ask);

const { ask } = sorted[Math.floor(sorted.length * 0.75)];
const r1 = await this.blockchainModuleManager.getR1(blockchainId);
// todo remove this line once we implement logic for storing assertion in publish node if it's in neighbourhood
const myPeerId = this.networkModuleManager.getPeerId().toB58String();
const filteredPeerRecords = peerRecords.filter((peer) => peer.peerId !== myPeerId);
const sorted = filteredPeerRecords.sort((a, b) => a.ask - b.ask);
let ask;
if (sorted.length > r1) {
ask = sorted[r1 - 1].ask;
} else {
ask = sorted[sorted.length - 1].ask;
}

const r0 = await this.blockchainModuleManager.getR0(blockchainId);

return this.blockchainModuleManager
const minBidSuggestion = this.blockchainModuleManager
.toBigNumber(blockchainId, '1')
.mul(epochsNumber)
.mul(r0);

const bidSuggestion = this.blockchainModuleManager
.toBigNumber(blockchainId, this.blockchainModuleManager.convertToWei(blockchainId, ask))
.mul(kbSize)
.mul(assertionSize)
.mul(epochsNumber)
.mul(r0)
.div(BYTES_IN_KILOBYTE)
.toString();
.div(BYTES_IN_KILOBYTE);
return bidSuggestion.lte(minBidSuggestion)
? minBidSuggestion.toString()
: bidSuggestion.toString();
}

async findEligibleNodes(neighbourhood, bid, r1, r0) {
Expand Down
12 changes: 6 additions & 6 deletions test/bdd/features/get-errors.feature
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ Feature: Get errors test
@get-errors
Scenario: Getting non-existent UAL
Given I setup 4 nodes
And I wait for 2 seconds
And I wait for 5 seconds

When I call Get directly on the node 1 with nonExistentUAL
And I wait for latest resolve to finalize
Then Latest Get operation finished with status: GetRouteError

@get-errors
Scenario: Getting invalid UAL
Given I setup 4 nodes
And I wait for 2 seconds
And I wait for 5 seconds

When I call Get directly on the node 1 with invalidUAL
And I wait for latest resolve to finalize
Expand All @@ -26,7 +26,7 @@ Feature: Get errors test
Given I setup 4 nodes
And I set R0 to be 1
And I set R1 to be 2
And I wait for 2 seconds
And I wait for 5 seconds

When I call Publish on the node 1 with validAssertion
And I wait for latest Publish to finalize
Expand All @@ -38,7 +38,7 @@ Feature: Get errors test
Given I setup 4 nodes
And I set R0 to be 1
And I set R1 to be 2
And I wait for 2 seconds
And I wait for 5 seconds

When I call Publish on the node 1 with validAssertion
And I wait for latest Publish to finalize
Expand Down
6 changes: 3 additions & 3 deletions test/bdd/features/get.feature
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Feature: Get asset states test
And I set R1 to be 2
And I set finalizationCommitsNumber to be 2
And I setup 4 nodes
And I wait for 2 seconds
And I wait for 5 seconds

When I call Publish on the node 4 with validPublish_1ForValidUpdate_1
And I wait for latest Publish to finalize
Expand All @@ -29,7 +29,7 @@ Feature: Get asset states test
And I set R1 to be 2
And I set finalizationCommitsNumber to be 2
And I setup 4 nodes
And I wait for 2 seconds
And I wait for 5 seconds

When I call Publish on the node 4 with validPublish_1ForValidUpdate_1
And I wait for latest Publish to finalize
Expand All @@ -49,7 +49,7 @@ Feature: Get asset states test
And I set R1 to be 2
And I set finalizationCommitsNumber to be 2
And I setup 4 nodes
And I wait for 2 seconds
And I wait for 5 seconds

When I call Publish on the node 4 with validPublish_1ForValidUpdate_1
And I wait for latest Publish to finalize
Expand Down
6 changes: 3 additions & 3 deletions test/bdd/features/publish-errors.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ Feature: Publish errors test

@publish-errors
Scenario: Publish on a node with minimum replication factor greater than the number of nodes
Given I setup 1 nodes
And I wait for 2 seconds
Given I setup 2 nodes
And I wait for 5 seconds

When I call Publish on the node 1 with validAssertion
And I wait for latest Publish to finalize
Expand All @@ -15,7 +15,7 @@ Feature: Publish errors test
@publish-errors
Scenario: Publish a knowledge asset directly on the node
Given I setup 1 nodes
And I wait for 2 seconds
And I wait for 5 seconds

When I call Publish directly on the node 1 with validPublishRequestBody
And I wait for latest Publish to finalize
Expand Down
2 changes: 1 addition & 1 deletion test/bdd/features/publish.feature
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Feature: Release related tests
Given I set R0 to be 1
And I set R1 to be 2
And I setup 4 nodes
And I wait for 2 seconds
And I wait for 5 seconds

When I call Publish on the node 4 with validAssertion
And I wait for latest Publish to finalize
Expand Down
2 changes: 1 addition & 1 deletion test/bdd/features/update-errors.feature
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Feature: Update errors test
@update-errors
Scenario: Update knowledge asset that was not previously published
Given I setup 1 node
And I wait for 2 seconds
And I wait for 5 seconds

When I call Update directly on the node 1 with validUpdateRequestBody
And I wait for latest Update to finalize
Expand Down
2 changes: 1 addition & 1 deletion test/bdd/features/update.feature
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Feature: Update asset test
And I set R1 to be 2
And I set finalizationCommitsNumber to be 2
And I setup 4 nodes
And I wait for 2 seconds
And I wait for 5 seconds

When I call Publish on the node 4 with validPublish_1ForValidUpdate_1
And I wait for latest Publish to finalize
Expand Down
4 changes: 4 additions & 0 deletions test/unit/mock/blockchain-module-manager-mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ class BlockchainModuleManagerMock {
return 20;
}

getR1() {
return 8;
}

getR0() {
return 3;
}
Expand Down
8 changes: 7 additions & 1 deletion test/unit/mock/network-module-manager-mock.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
class NetworkModuleManagerMock {}
class NetworkModuleManagerMock {
getPeerId() {
return {
toB58String: () => 'myPeerId',
};
}
}

export default NetworkModuleManagerMock;
40 changes: 34 additions & 6 deletions test/unit/service/sharding-table-service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,56 @@ describe('Sharding table service test', async () => {
expect(bidSuggestions).to.be.equal('3788323225298705400');
});

it('Get bid suggestion, returns same token amount for size 1 Kb and size < 1 Kb', async () => {
it('Get bid suggestion, returns valid value for assertion size 1b and ask 1 wei', async () => {
const epochsNumber = 5;
const contentAssetStorageAddress = '0xABd59A9aa71847F499d624c492d3903dA953d67a';
const firstAssertionId =
'0xb44062de45333119471934bc0340c05ff09c0b463392384bc2030cd0a20c334b';
const hashFunctionId = 1;
const bidSuggestion1Kb = await shardingTableService.getBidSuggestion(
const askInWei = '0.000000000000000001';
const peers = shardingTableService.repositoryModuleManager.getAllPeerRecords();
shardingTableService.repositoryModuleManager.getAllPeerRecords = () => {
peers.forEach((peer) => {
// eslint-disable-next-line no-param-reassign
peer.ask = askInWei;
});
return peers;
};
const bidSuggestion1B = await shardingTableService.getBidSuggestion(
'ganache',
epochsNumber,
BYTES_IN_KILOBYTE,
1,
contentAssetStorageAddress,
firstAssertionId,
hashFunctionId,
);
const bidSuggestion1B = await shardingTableService.getBidSuggestion(
expect(bidSuggestion1B).to.be.equal('15');
const bidSuggestion10B = await shardingTableService.getBidSuggestion(
'ganache',
epochsNumber,
1,
10,
contentAssetStorageAddress,
firstAssertionId,
hashFunctionId,
);
expect(bidSuggestion10B).to.be.equal('15');
const bidSuggestion1024B = await shardingTableService.getBidSuggestion(
'ganache',
epochsNumber,
1024,
contentAssetStorageAddress,
firstAssertionId,
hashFunctionId,
);
expect(bidSuggestion1024B).to.be.equal('15');
const bidSuggestion2048B = await shardingTableService.getBidSuggestion(
'ganache',
epochsNumber,
2048,
contentAssetStorageAddress,
firstAssertionId,
hashFunctionId,
);
expect(bidSuggestion1B).to.be.equal(bidSuggestion1Kb);
expect(bidSuggestion2048B).to.be.equal('30');
});
});

0 comments on commit 4c7f821

Please sign in to comment.