Skip to content

Commit

Permalink
Merge pull request #2643 from OriginTrail/v6/prerelease/mainnet
Browse files Browse the repository at this point in the history
Mainnet 6.0.12 Release
  • Loading branch information
zeroxbt authored Jul 12, 2023
2 parents 4c92a61 + e3eff2e commit ace965d
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 49 deletions.
2 changes: 1 addition & 1 deletion ot-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ class OTNode {
const validationModuleManager = this.container.resolve('validationModuleManager');

const migration = new PullBlockchainShardingTableMigration(
'pullShardingTableMigrationV604',
'pullShardingTableMigrationV612',
this.logger,
this.config,
repositoryModuleManager,
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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.11",
"version": "6.0.12",
"description": "OTNode V6",
"main": "index.js",
"type": "module",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,11 @@ class ShardRepository {
this.model = models.shard;
}

async createManyPeerRecords(peers) {
return this._bulkUpdatePeerRecords(peers, ['ask', 'stake', 'sha256']);
}

async _bulkUpdatePeerRecords(peerRecords, updateColumns) {
return this.model.bulkCreate(
peerRecords.map((peerRecord) => ({
ask: 0,
stake: 0,
sha256: '',
...peerRecord,
})),
{
validate: true,
updateOnDuplicate: updateColumns,
},
);
async createManyPeerRecords(peerRecords) {
return this.model.bulkCreate(peerRecords, {
validate: true,
updateOnDuplicate: ['ask', 'stake', 'sha256'],
});
}

async removeShardingTablePeerRecords(blockchainId) {
Expand Down Expand Up @@ -95,12 +83,28 @@ class ShardRepository {
return (result ?? []).map((record) => ({ peerId: record.peer_id }));
}

async updatePeersAsk(peerRecords) {
return this._bulkUpdatePeerRecords(peerRecords, ['ask']);
async updatePeerAsk(peerId, blockchainId, ask) {
return this.model.update(
{ ask },
{
where: {
peerId,
blockchainId,
},
},
);
}

async updatePeersStake(peerRecords) {
return this._bulkUpdatePeerRecords(peerRecords, ['stake']);
async updatePeerStake(peerId, blockchainId, stake) {
return this.model.update(
{ stake },
{
where: {
peerId,
blockchainId,
},
},
);
}

async updatePeerRecordLastDialed(peerId, timestamp) {
Expand Down
8 changes: 4 additions & 4 deletions src/modules/repository/repository-module-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,12 @@ class RepositoryModuleManager extends BaseModuleManager {
return this.getRepository('shard').updatePeerRecordLastSeenAndLastDialed(peerId, timestamp);
}

async updatePeersAsk(peerRecords) {
return this.getRepository('shard').updatePeersAsk(peerRecords);
async updatePeerAsk(peerId, blockchainId, ask) {
return this.getRepository('shard').updatePeerAsk(peerId, blockchainId, ask);
}

async updatePeersStake(peerRecords) {
return this.getRepository('shard').updatePeersStake(peerRecords);
async updatePeerStake(peerId, blockchainId, stake) {
return this.getRepository('shard').updatePeerStake(peerId, blockchainId, stake);
}

async getNeighbourhood(assertionId, r2) {
Expand Down
33 changes: 13 additions & 20 deletions src/service/blockchain-event-listener-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,13 +313,13 @@ class BlockchainEventListenerService {

this.logger.trace(`Removing peer id: ${nodeId} from sharding table.`);

this.repositoryModuleManager.removePeerRecord(event.blockchainId, nodeId);
await this.repositoryModuleManager.removePeerRecord(event.blockchainId, nodeId);
}),
);
}

async handleStakeIncreasedEvents(blockEvents) {
const peerRecords = await Promise.all(
await Promise.all(
blockEvents.map(async (event) => {
const eventData = JSON.parse(event.data);

Expand All @@ -330,26 +330,24 @@ class BlockchainEventListenerService {

this.logger.trace(`Updating stake value for peer id: ${nodeId} in sharding table.`);

return {
peerId: nodeId,
blockchainId: event.blockchainId,
stake: this.blockchainModuleManager.convertFromWei(
await this.repositoryModuleManager.updatePeerStake(
nodeId,
event.blockchainId,
this.blockchainModuleManager.convertFromWei(
event.blockchainId,
eventData.newStake,
),
};
);
}),
);

await this.repositoryModuleManager.updatePeersStake(peerRecords);
}

async handleStakeWithdrawalStartedEvents(blockEvents) {
await this.handleStakeIncreasedEvents(blockEvents);
}

async handleAskUpdatedEvents(blockEvents) {
const peerRecords = await Promise.all(
await Promise.all(
blockEvents.map(async (event) => {
const eventData = JSON.parse(event.data);

Expand All @@ -360,18 +358,13 @@ class BlockchainEventListenerService {

this.logger.trace(`Updating ask value for peer id: ${nodeId} in sharding table.`);

return {
peerId: nodeId,
blockchainId: event.blockchainId,
ask: this.blockchainModuleManager.convertFromWei(
event.blockchainId,
eventData.ask,
),
};
await this.repositoryModuleManager.updatePeerAsk(
nodeId,
event.blockchainId,
this.blockchainModuleManager.convertFromWei(event.blockchainId, eventData.ask),
);
}),
);

await this.repositoryModuleManager.updatePeersAsk(peerRecords);
}

async handleServiceAgreementV1ExtendedEvents(blockEvents) {
Expand Down

0 comments on commit ace965d

Please sign in to comment.