Skip to content

Commit

Permalink
Fix proxy scan, #919 (#944)
Browse files Browse the repository at this point in the history
* Fix removeProxy call args check, #919

* Fix pure proxy check, #919
  • Loading branch information
wliyongfeng authored Aug 20, 2024
1 parent 31c6329 commit 4c29a49
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
19 changes: 19 additions & 0 deletions backend/packages/mongo/src/palletProxy/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,27 @@ async function getAllActiveProxiesOfDelegator(delegator) {
return await col.find({ delegator, isRemoved: false }).toArray();
}

async function isPureProxyDelegator(delegator) {
if (!delegator) {
return false;
}

const col = await getProxyCol();
const proxies = await col
.find({ delegator })
.sort({ "indexer.blockHeight": 1 })
.toArray();
if ((proxies || []).length <= 0) {
return false;
}

const firstProxy = proxies[0];
return firstProxy.isPure;
}

module.exports = {
upsertProxyIfNo,
markProxyRemoved,
getAllActiveProxiesOfDelegator,
isPureProxyDelegator,
};
2 changes: 1 addition & 1 deletion backend/packages/pallet-proxy-scan/src/play.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const {
(async () => {
await initPalletProxyScanDb();
await subscribeFinalizedHeight();
const blockHeights = [2748906];
const blockHeights = [247043, 2727281];

const api = await getApi();
for (const height of blockHeights) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const {
} = require("@osn/scan-common");
const { generateProxyId } = require("../../common/hash");
const {
palletProxy: { upsertProxyIfNo, getProxyTimelineCol },
palletProxy: { upsertProxyIfNo, getProxyTimelineCol, isPureProxyDelegator },
} = require("@statescan/mongo");
const {
store: { setKnownHeightMark },
Expand Down Expand Up @@ -35,14 +35,15 @@ async function handleAddProxy(call, signer, extrinsicIndexer) {
const type = call.args[1].toString();
const proxyId = generateProxyId(signer, delegatee, type, delay);

const isPure = await isPureProxyDelegator(signer);
await upsertProxyIfNo({
proxyId,
delegator: signer,
delegatee,
type,
delay,
isRemoved: false,
isPure: false,
isPure,
indexer: extrinsicIndexer,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ async function handleRemoveProxy(call, signer, extrinsicIndexer) {
setKnownHeightMark(extrinsicIndexer.blockHeight);
const blockApi = await findBlockApi(extrinsicIndexer.blockHash);
if (
blockApi.events.proxy?.ProxyRemoved || // handle this call only when there is no `ProxyRemoved` event
call.args.length !== 2
blockApi.events.proxy?.ProxyRemoved // handle this call only when there is no `ProxyRemoved` event
) {
return;
}
Expand All @@ -42,7 +41,12 @@ async function handleRemoveProxy(call, signer, extrinsicIndexer) {
return;
}

const proxyId = generateProxyId(signer, delegatee, type, targetProxy.delay);
const proxyId = generateProxyId(
signer,
delegatee,
type,
targetProxy.delay || 0,
);
const { proxies: nowOnChainProxies } = await queryAllProxiesOf(
signer,
extrinsicIndexer.blockHash,
Expand Down

0 comments on commit 4c29a49

Please sign in to comment.