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

Fix "Top Hat ID is invalid" error that pops up right after new role creation is executed #2103

Merged

Conversation

adamgall
Copy link
Member

@adamgall adamgall commented Jul 8, 2024

Closes #2083

After hearing live event for new Hat Tree Id, pause 10 seconds before adding that to state

@adamgall adamgall self-assigned this Jul 8, 2024
Copy link

netlify bot commented Jul 8, 2024

Deploy Preview for decent-interface-dev ready!

Name Link
🔨 Latest commit 016ca10
🔍 Latest deploy log https://app.netlify.com/sites/decent-interface-dev/deploys/668d320ab8e11c000898383e
😎 Deploy Preview https://deploy-preview-2103.app.dev.decentdao.org
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@@ -79,7 +80,7 @@ const useHatsTree = () => {
}
}
} catch (e) {
setHatsTree(undefined);
setHatsTree(null);
Copy link
Member Author

Choose a reason for hiding this comment

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

This is a sub-fix. The real fix is to not try to fetch from subgraph immediately after receiving event. Give Subgraph a few seconds to index the new Hat Tree.

But, even if we do get to it too early, let's set the hat Tree to null not undefined, so the loading screen goes away and it's as if the Safe has no Roles (which is technically accurate here because the given Tree ID doesn't line up with a valid Tree in the shape that we want (or rather, we can't get it from Subgraph).

Comment on lines +20 to 51
const topHatIdEvent = events
.filter(event => event.args.key && event.args.key === 'topHatId')
.pop();

if (!hatsTreeIdEvent) {
if (!topHatIdEvent) {
return null;
}

if (!hatsTreeIdEvent.args.value) {
if (!topHatIdEvent.args.value) {
logError({
message: "KVPairs 'hatsTreeIdEvent' without a value",
message: "KVPairs 'topHatIdEvent' without a value",
network: chainId,
args: {
transactionHash: hatsTreeIdEvent.transactionHash,
logIndex: hatsTreeIdEvent.logIndex,
transactionHash: topHatIdEvent.transactionHash,
logIndex: topHatIdEvent.logIndex,
},
});
return undefined;
}

try {
const topHatId = BigInt(hatsTreeIdEvent.args.value);
const topHatId = BigInt(topHatIdEvent.args.value);
const treeId = hatIdToTreeId(topHatId);
return treeId;
} catch (e) {
logError({
message: "KVPairs 'hatsTreeIdEvent' value not a number",
message: "KVPairs 'topHatIdEvent' value not a number",
network: chainId,
args: {
transactionHash: hatsTreeIdEvent.transactionHash,
logIndex: hatsTreeIdEvent.logIndex,
transactionHash: topHatIdEvent.transactionHash,
logIndex: topHatIdEvent.logIndex,
},
Copy link
Member Author

Choose a reason for hiding this comment

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

Variable rename

Comment on lines +88 to +95
onLogs: logs => {
// dev: when this event is captured in realtime, give the subgraph
// time to index, and do that most cleanly by not even telling the rest
// of our code that we have the hats tree id until some time has passed.
setTimeout(() => {
setHatsTreeId(getHatsTreeId(logs, chain.id));
}, 10_000);
},
Copy link
Member Author

Choose a reason for hiding this comment

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

Here's the good stuff. If we're getting the new Hat Tree ID from a live event, then pause 10 seconds before setting the hats tree id in state. Setting hats tree id in state is what triggers fetching the Tree from Subgraph.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice

Copy link
Contributor

@mudrila mudrila left a comment

Choose a reason for hiding this comment

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

Approving assuming that existing tree would still show up "immediately"

// time to index, and do that most cleanly by not even telling the rest
// of our code that we have the hats tree id until some time has passed.
setTimeout(() => {
setHatsTreeId(getHatsTreeId(logs, chain.id));
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume that's not the case but just wanna make sure - won't it prevent loading existing tree and not the one that just created from appearing for 10 secs?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah this timeout is just for when capturing events from the live event listener. It doesn't affect loading data from past events like will be the majority of loads

src/hooks/DAO/useKeyValuePairs.ts Show resolved Hide resolved
Comment on lines +88 to +95
onLogs: logs => {
// dev: when this event is captured in realtime, give the subgraph
// time to index, and do that most cleanly by not even telling the rest
// of our code that we have the hats tree id until some time has passed.
setTimeout(() => {
setHatsTreeId(getHatsTreeId(logs, chain.id));
}, 10_000);
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice

@adamgall adamgall merged commit 848f79e into roles-0.1.1/desktop-and-other-updates Jul 9, 2024
7 checks passed
@adamgall adamgall deleted the roles-0.1.0/subgraph-catchup branch July 9, 2024 13:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants