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

Balances Consistency Fix #2699

Merged
merged 1 commit into from
Mar 5, 2024
Merged
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
100 changes: 99 additions & 1 deletion test/suites/smoke/test-balances-consistency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ enum ReserveType {
ReferendumInfo = "11",
Asset = "12",
AssetMetadata = "13",
LocalAsset = "14",
LocalAssetMetadata = "15",
LocalAssetDeposit = "16",
Named = "17",
SubIdentity = "18",
PreimageStatus = "19",
Expand Down Expand Up @@ -583,6 +586,72 @@ describeSuite({
});
});

if (specVersion < 2800) {
await new Promise((resolve, reject) => {
apiAt.query.localAssets.asset
.entries()
.then(async (localAssets) => {
localAssets.forEach((localAsset) => {
updateReserveMap(localAsset[1].unwrap().owner.toHex().slice(-40), {
[ReserveType.LocalAsset]: localAsset[1].unwrap().deposit.toBigInt(),
});
});

await new Promise((resolve, reject) => {
apiAt.query.localAssets.metadata
.entries()
.then((localAssetMetadata) => {
localAssetMetadata.forEach((localAssetMetadata) => {
updateReserveMap(
localAssets
.find(
(localAsset) =>
localAsset[0].toHex().slice(-64) ==
localAssetMetadata[0].toHex().slice(-64)
)![1]
.unwrap()
.owner.toHex()
.slice(-40),
{
[ReserveType.LocalAssetMetadata]:
localAssetMetadata[1].deposit.toBigInt(),
}
);
});
resolve("localAssetsMetadata scraped");
})
.catch((error) => {
console.error("Error fetching localAssetsMetadata:", error);
reject(error);
});
});

resolve("localAssets scraped");
})
.catch((error) => {
console.error("Error fetching localAssets :", error);
reject(error);
});
});

await new Promise((resolve, reject) => {
apiAt.query.assetManager.localAssetDeposit
.entries()
.then((localAssetDeposits) => {
localAssetDeposits.forEach((assetDeposit) => {
updateReserveMap(assetDeposit[1].unwrap().creator.toHex(), {
[ReserveType.LocalAssetDeposit]: assetDeposit[1].unwrap().deposit.toBigInt(),
});
});
resolve("localAssetDeposits scraped");
})
.catch((error) => {
console.error("Error fetching localAssetDeposits:", error);
reject(error);
});
});
}

await new Promise((resolve, reject) => {
apiAt.query.balances.reserves
.entries()
Expand Down Expand Up @@ -846,14 +915,26 @@ describeSuite({
checkReservedBalance(userId, user.data.reserved.toBigInt());
totalAccounts++;
} else {
const chainName = (await paraApi.rpc.system.chain()).toString();
const shortFallExists = AccountShortfalls[chainName];
const runtimeVersion = paraApi.consts.system.version.specVersion.toNumber();

await processAllStorage(paraApi, keyPrefix, blockHash, (items) => {
for (const { key, value } of items) {
const accountId = key.slice(-40);
const accountInfo = value;
const freeBal = hexToBigInt(accountInfo.slice(34, 66), { isLe: true });
const reservedBalance = hexToBigInt(accountInfo.slice(66, 98), { isLe: true });
let reservedBalance = hexToBigInt(accountInfo.slice(66, 98), { isLe: true });
totalIssuance += freeBal + reservedBalance;
totalAccounts++;

if (
shortFallExists?.[`0x${accountId}`] &&
shortFallExists[`0x${accountId}`].brokenIn <= runtimeVersion
) {
reservedBalance -= shortFallExists[`0x${accountId}`].reserved;
}

checkReservedBalance(accountId, reservedBalance);
}
});
Expand Down Expand Up @@ -945,3 +1026,20 @@ describeSuite({
});
},
});

const AccountShortfalls = {
"Moonbase Stage": {
"0x7cb3790906f902a02f0d6784058362db929c5f3f": {
comment: "localAssetDeposit to be manually returned",
brokenIn: 2801,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we change this to 2800?

Copy link
Contributor Author

@timbrinded timbrinded Mar 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not broken Since but In.

The distinction being we want it to do the adjustment in RT2801 but to no longer apply in RT2900 (where hopefully we've applied remediation).

reserved: 300000000000000000000n,
locks: 0n,
},
"0x56c97e8fb7faebebe643473d5c9adaeb3fb2538e": {
comment: "localAssetDeposit to be manually returned",
brokenIn: 2801,
reserved: 1009200000000000000n,
locks: 0n,
},
},
} as const;
Loading