From 9c6aeb3ff3314be26cc75b10578a95cb594c7e54 Mon Sep 17 00:00:00 2001 From: Uladzislau Hubar Date: Thu, 18 Apr 2024 10:42:18 +0200 Subject: [PATCH 1/2] Fixed migration of the ShardingTableStorage in the deployment script --- contracts/v2/ShardingTable.sol | 6 ++++- deploy/027_deploy_sharding_table_v2.ts | 3 ++- deployments/otp_devnet_contracts.json | 32 +++++++++++++------------- 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/contracts/v2/ShardingTable.sol b/contracts/v2/ShardingTable.sol index 77f1458e..2a6ee896 100644 --- a/contracts/v2/ShardingTable.sol +++ b/contracts/v2/ShardingTable.sol @@ -85,11 +85,15 @@ contract ShardingTableV2 is Named, Versioned, ContractStatus, Initializable { ShardingTableStructsV1.Node[] memory nodes = stsv1.getMultipleNodes(startingIdentityId, numberOfNodes); - for (uint i = 0; i < nodes.length; i++) { + for (uint i; i < nodes.length; ) { if (!stsv2.nodeExists(nodes[i].identityId)) { uint256 nodeHashRingPosition = uint256(profileStorage.getNodeAddress(nodes[i].identityId, 1)); _insertNode(_binarySearchForIndex(nodeHashRingPosition), nodes[i].identityId, nodeHashRingPosition); } + + unchecked { + i++; + } } } diff --git a/deploy/027_deploy_sharding_table_v2.ts b/deploy/027_deploy_sharding_table_v2.ts index b9f05055..f7227dd6 100644 --- a/deploy/027_deploy_sharding_table_v2.ts +++ b/deploy/027_deploy_sharding_table_v2.ts @@ -71,8 +71,9 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { console.log( `Migration COMPLETED iteration: ${iteration} with starting identityId: ${identityId}, number of nodes in batch: ${numberOfNodesInBatch}, ShardingTableStorage: ${shardingTableStorageAddress}`, ); - iteration += 1; + identityId = nodes[iteration * numberOfNodesInBatch]?.identityId; + iteration += 1; } hre.helpers.setParametersEncodedData.push(['ShardingTable', encodedDataArray]); diff --git a/deployments/otp_devnet_contracts.json b/deployments/otp_devnet_contracts.json index 2c7fc249..3a0f56c2 100644 --- a/deployments/otp_devnet_contracts.json +++ b/deployments/otp_devnet_contracts.json @@ -181,13 +181,13 @@ "version": "1.1.1" }, "ShardingTable": { - "evmAddress": "0x89822851D2A5b5256Fd19fa3b52538CAaE1f0acb", - "substrateAddress": "5EMjsczojCiGD9qj1tN9JPu3Q1NZzBq9e4fQmCRHarD5agFZ", + "evmAddress": "0xb7fCc4718CF2d0a5289714D15AeB89D5988Cd678", + "substrateAddress": "5EMjsczy3N53B3xEonMGeTYgYSxHT3ZyJjhFTsodgELN77fB", "version": "2.0.1", - "gitBranch": "release/4.2.6", - "gitCommitHash": "731dc92083f8c8e705050f9da8d8d9be649e7465", - "deploymentBlock": 4434349, - "deploymentTimestamp": 1713367726304, + "gitBranch": "main", + "gitCommitHash": "f0e94c17b8faca2ebc0ac226bf6188f14577264e", + "deploymentBlock": 4439322, + "deploymentTimestamp": 1713429610407, "deployed": true }, "Staking": { @@ -230,16 +230,6 @@ "deploymentTimestamp": 1713367652683, "deployed": true }, - "ShardingTableStorage": { - "evmAddress": "0xe1B302A7cAC8241620ED0e901aA0f76529C31864", - "substrateAddress": "5EMjsd17Q8ApLnR56hxkhH6pDpBz4u83wZLk3sB4um7jutVC", - "version": "2.0.0", - "gitBranch": "release/4.2.6", - "gitCommitHash": "731dc92083f8c8e705050f9da8d8d9be649e7465", - "deploymentBlock": 4434345, - "deploymentTimestamp": 1713367674764, - "deployed": true - }, "NodeOperatorFeesStorage": { "evmAddress": "0x74982203A596469c252E12dE91571d3A2a65Ac73", "substrateAddress": "5EMjsczjY9RSBkFnCVKPrP2QvtyvKNKuCsSZ4W7S2AMVKPDr", @@ -249,6 +239,16 @@ "deploymentBlock": 4434347, "deploymentTimestamp": 1713367700400, "deployed": true + }, + "ShardingTableStorage": { + "evmAddress": "0x000Fa4Cfe3593D7aF43c0c88E9171367e44F501f", + "substrateAddress": "5EMjsczLBqgPivrGW33v4uAGTT7dRV5vihYRZ2GTLfZMG2Uq", + "version": "2.0.0", + "gitBranch": "main", + "gitCommitHash": "f0e94c17b8faca2ebc0ac226bf6188f14577264e", + "deploymentBlock": 4439320, + "deploymentTimestamp": 1713429584529, + "deployed": true } }, "deployedTimestamp": 1689863125519 From 1f34be56c1256387c22e7b22720afb3562b30aa7 Mon Sep 17 00:00:00 2001 From: Uladzislau Hubar Date: Thu, 18 Apr 2024 10:56:06 +0200 Subject: [PATCH 2/2] Added missing condition in the Sharding Table migration --- contracts/v2/ShardingTable.sol | 2 +- deployments/otp_devnet_contracts.json | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/contracts/v2/ShardingTable.sol b/contracts/v2/ShardingTable.sol index 2a6ee896..6d5becfb 100644 --- a/contracts/v2/ShardingTable.sol +++ b/contracts/v2/ShardingTable.sol @@ -86,7 +86,7 @@ contract ShardingTableV2 is Named, Versioned, ContractStatus, Initializable { ShardingTableStructsV1.Node[] memory nodes = stsv1.getMultipleNodes(startingIdentityId, numberOfNodes); for (uint i; i < nodes.length; ) { - if (!stsv2.nodeExists(nodes[i].identityId)) { + if (nodes[i].identityId != 0 && !stsv2.nodeExists(nodes[i].identityId)) { uint256 nodeHashRingPosition = uint256(profileStorage.getNodeAddress(nodes[i].identityId, 1)); _insertNode(_binarySearchForIndex(nodeHashRingPosition), nodes[i].identityId, nodeHashRingPosition); } diff --git a/deployments/otp_devnet_contracts.json b/deployments/otp_devnet_contracts.json index 3a0f56c2..f93de13c 100644 --- a/deployments/otp_devnet_contracts.json +++ b/deployments/otp_devnet_contracts.json @@ -181,13 +181,13 @@ "version": "1.1.1" }, "ShardingTable": { - "evmAddress": "0xb7fCc4718CF2d0a5289714D15AeB89D5988Cd678", - "substrateAddress": "5EMjsczy3N53B3xEonMGeTYgYSxHT3ZyJjhFTsodgELN77fB", + "evmAddress": "0x92B7d406B7A7E85Ed2A52708Ea9b5310107abb20", + "substrateAddress": "5EMjsczqaEXFUVk3yEJEfSzYevmKxnKouhEehGjygJis2RGQ", "version": "2.0.1", - "gitBranch": "main", - "gitCommitHash": "f0e94c17b8faca2ebc0ac226bf6188f14577264e", - "deploymentBlock": 4439322, - "deploymentTimestamp": 1713429610407, + "gitBranch": "fix/sharding-table-migration", + "gitCommitHash": "9c6aeb3ff3314be26cc75b10578a95cb594c7e54", + "deploymentBlock": 4439394, + "deploymentTimestamp": 1713430498176, "deployed": true }, "Staking": { @@ -241,13 +241,13 @@ "deployed": true }, "ShardingTableStorage": { - "evmAddress": "0x000Fa4Cfe3593D7aF43c0c88E9171367e44F501f", - "substrateAddress": "5EMjsczLBqgPivrGW33v4uAGTT7dRV5vihYRZ2GTLfZMG2Uq", + "evmAddress": "0x72837c4842601Ac4a2b30c50427Ef1798ffCDf57", + "substrateAddress": "5EMjsczj7xwtqtcMxW6csrBVKGbfdz1hqqxbgKB3QXa6sxiy", "version": "2.0.0", - "gitBranch": "main", - "gitCommitHash": "f0e94c17b8faca2ebc0ac226bf6188f14577264e", - "deploymentBlock": 4439320, - "deploymentTimestamp": 1713429584529, + "gitBranch": "fix/sharding-table-migration", + "gitCommitHash": "9c6aeb3ff3314be26cc75b10578a95cb594c7e54", + "deploymentBlock": 4439392, + "deploymentTimestamp": 1713430472547, "deployed": true } },