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

feat: batches info l1 metric #41

Merged
merged 3 commits into from
Aug 8, 2024
Merged

feat: batches info l1 metric #41

merged 3 commits into from
Aug 8, 2024

Conversation

0xkenj1
Copy link
Collaborator

@0xkenj1 0xkenj1 commented Aug 8, 2024

🤖 Linear

Closes ZKS-74

Description

  • Add getBatchesInfo logic on L1MetricsService

Copy link

linear bot commented Aug 8, 2024

ZKS-74 Batches Info

Use multicall or Promise.all to optimize requests.

DiamodProxy address: 0x32400084c286cf3e17e7b677ea9583e60a000324

AC:

  • getBatchesInfo() implemented following figma diagram signature and Notion docs
  • Unit tests

@0xkenj1 0xkenj1 requested review from 0xnigir1 and 0xyaco August 8, 2024 00:16
Comment on lines 159 to 173
if (!Number.isInteger(chainId)) {
throw new InvalidChainId("chain id must be an integer");
}
const chainIdBn = BigInt(chainId);
let diamondProxyAddress: Address | undefined = this.diamondContracts.get(chainId);

if (!diamondProxyAddress) {
diamondProxyAddress = await this.evmProviderService.readContract(
this.bridgeHub.address,
this.bridgeHub.abi,
"getHyperchain",
[chainIdBn],
);
this.diamondContracts.set(chainId, diamondProxyAddress);
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

extracted this logic in the following pr cause i noticed that we need it for chainType and probably others in the future :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

should we handle the case where address returned is the zeroAddress? (this would be the case where chainId is a non-existent chain)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yea, good catch, i will check how is this function implemented, if reverts or returns Address(0)

0xkenj1

This comment was marked as duplicate.

*/
async getBatchesInfo(chainId: number): Promise<BatchesInfo> {
if (!Number.isInteger(chainId)) {
throw new InvalidChainId("chain id must be an integer");
Copy link
Collaborator

Choose a reason for hiding this comment

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

nice 💯

Comment on lines 159 to 173
if (!Number.isInteger(chainId)) {
throw new InvalidChainId("chain id must be an integer");
}
const chainIdBn = BigInt(chainId);
let diamondProxyAddress: Address | undefined = this.diamondContracts.get(chainId);

if (!diamondProxyAddress) {
diamondProxyAddress = await this.evmProviderService.readContract(
this.bridgeHub.address,
this.bridgeHub.abi,
"getHyperchain",
[chainIdBn],
);
this.diamondContracts.set(chainId, diamondProxyAddress);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

should we handle the case where address returned is the zeroAddress? (this would be the case where chainId is a non-existent chain)

0xyaco
0xyaco previously approved these changes Aug 8, 2024
Copy link
Collaborator

@0xyaco 0xyaco left a comment

Choose a reason for hiding this comment

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

Nice!

super(message);
this.name = "L1MetricsServiceException";
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are we ok with two errors in one single file? I'm fine with both single error per file and multi error files, just asking in case you forgot to put the L1MetricsServiceException in its own file

throw new InvalidChainId("chain id must be an integer");
}
const chainIdBn = BigInt(chainId);
let diamondProxyAddress: Address | undefined = this.diamondContracts.get(chainId);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is unrelated to the PR but you got me wondering, why is the type of the diamondContracts keys (ie ChainId) a number? Any tech/business specific reason to not use bigints?

Copy link
Collaborator Author

@0xkenj1 0xkenj1 Aug 8, 2024

Choose a reason for hiding this comment

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

i thought there was no need for using bigints for chainId since they are not gona be huge numbers, but probably its better to keep types consistent with returned values from blockchain, i will change it

Copy link
Collaborator

Choose a reason for hiding this comment

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

@0xkenj1 we can add this revisions to tech debt because i had the same thought as you, maybe the chainId argument can be a bigint directly too 🤔? (then we can remove the isInteger validation)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yep, we wont need that validation, i will fix this one here but will added it to linear to tackle it before moving to api integration

0xnigir1
0xnigir1 previously approved these changes Aug 8, 2024
Copy link
Collaborator

@0xnigir1 0xnigir1 left a comment

Choose a reason for hiding this comment

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

lgtm 🚀

Copy link
Collaborator

@0xyaco 0xyaco left a comment

Choose a reason for hiding this comment

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

Neat 😎

@0xkenj1 0xkenj1 merged commit b154e12 into dev Aug 8, 2024
6 checks passed
@0xkenj1 0xkenj1 deleted the feat/batches-info branch August 8, 2024 15:06
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