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

Adding batch timestamp to the public tx API #1740

Merged
merged 3 commits into from
Jan 11, 2024

Conversation

otherview
Copy link
Contributor

@otherview otherview commented Jan 10, 2024

Why this change is needed

  • Transactions Request should have batch timestamp along side with batch number
  • Update the folder and test name from obscuro to ten
  • Update tenscan to display the timestamps

What changes were made as part of this PR

Please provide a high level list of the changes made

PR checks pre-merging

Please indicate below by ticking the checkbox that you have read and performed the required
PR checks

  • PR checks reviewed and performed

Copy link

coderabbitai bot commented Jan 10, 2024

Walkthrough

The system has been updated to track the batch timestamp for transactions. The PublicTransaction data structure now includes a BatchTimestamp field to hold this information. Accompanying this change, the database queries have been adjusted to retrieve the batch.header, decode it, and fill in the new BatchTimestamp field when selecting public transactions based on the sender.

Changes

File(s) Change Summary
.../common/query_types.go Added BatchTimestamp field of type uint64 to PublicTransaction struct.
.../enclave/storage/enclavedb/batch.go Modified queryTxList SQL query to include batch.header; updated selectPublicTxsBySender to decode batchHeader and populate BatchTimestamp.
.../frontend/src/components/modules/dashboard/recent-transactions.tsx,
.../frontend/src/components/modules/transactions/columns.tsx,
.../frontend/src/types/interfaces/TransactionInterfaces.ts
Added support for displaying and handling the BatchTimestamp field in the frontend components and transaction interfaces.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between f72e986 and e6ea0ec.
Files selected for processing (2)
  • go/common/query_types.go (1 hunks)
  • go/enclave/storage/enclavedb/batch.go (2 hunks)
Additional comments: 3
go/common/query_types.go (1)
  • 36-36: The addition of the BatchTimestamp field to the PublicTransaction struct is consistent with the PR objectives and is correctly typed as uint64. This change should enhance the transaction metadata as intended.
go/enclave/storage/enclavedb/batch.go (2)
  • 47-47: The modification to the queryTxList SQL query to include batch.header is correct and aligns with the PR objectives to enhance transaction metadata.

  • 512-526: The changes to the selectPublicTxsBySender function, including the decoding of the batchHeader and populating the BatchTimestamp field in the PublicTransaction struct, are correctly implemented using rlp.DecodeBytes.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between e6ea0ec and 9d92f63.
Files selected for processing (3)
  • tools/tenscan/frontend/src/components/modules/dashboard/recent-transactions.tsx (1 hunks)
  • tools/tenscan/frontend/src/components/modules/transactions/columns.tsx (1 hunks)
  • tools/tenscan/frontend/src/types/interfaces/TransactionInterfaces.ts (1 hunks)
Files skipped from review due to trivial changes (1)
  • tools/tenscan/frontend/src/components/modules/dashboard/recent-transactions.tsx
Additional comments: 1
tools/tenscan/frontend/src/types/interfaces/TransactionInterfaces.ts (1)
  • 5-5: The addition of the BatchTimestamp field to the Transaction type is correctly implemented and aligns with the PR objectives to provide additional context to transactions.

@otherview
Copy link
Contributor Author

@Jennievon the timestamp that's displayed doesn't have any treatment (it's a unix timestamp). I wonder if you have some wizard trick to display these nicely ?

@Jennievon
Copy link
Contributor

@Jennievon the timestamp that's displayed doesn't have any treatment (it's a unix timestamp). I wonder if you have some wizard trick to display these nicely ?

sure, I'll push an update for it.

Copy link
Collaborator

@BedrockSquirrel BedrockSquirrel left a comment

Choose a reason for hiding this comment

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

LGTM but maybe Jennie can advise on the formatting comment.

@@ -17,6 +17,11 @@ export function RecentTransactions({ transactions }: { transactions: any }) {
#{transaction?.BatchHeight}
</p>
</div>
<div className="ml-4 space-y-1">
<p className="text-sm font-medium leading-none">
{transaction?.BatchTimestamp}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would it work to use {formatTimeAgo(batch?.timestamp)} here, like @Jennievon did in recent-batches.tsx? To get the 'x mins ago' formatting.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 9d92f63 and f946cc6.
Files selected for processing (3)
  • tools/tenscan/frontend/src/components/modules/dashboard/recent-transactions.tsx (2 hunks)
  • tools/tenscan/frontend/src/components/modules/transactions/columns.tsx (2 hunks)
  • tools/tenscan/frontend/src/lib/utils.ts (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • tools/tenscan/frontend/src/components/modules/dashboard/recent-transactions.tsx
  • tools/tenscan/frontend/src/components/modules/transactions/columns.tsx

Comment on lines +9 to +12
export function formatTimeAgo(unixTimestampSeconds: string | number) {
if (!unixTimestampSeconds) {
return "Unknown";
}
Copy link

Choose a reason for hiding this comment

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

The update to formatTimeAgo to accept both string and number types for unixTimestampSeconds adds flexibility. However, ensure that the type conversion with Number() is safe and won't lead to unexpected behavior with different input types. The addition of a falsy check to return "Unknown" is a good defensive programming practice.

Copy link
Contributor

@Jennievon Jennievon left a comment

Choose a reason for hiding this comment

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

LGTM!

@otherview otherview merged commit cdc02eb into main Jan 11, 2024
2 checks passed
@otherview otherview deleted the pedro/tx_api_batch_timestamp branch January 11, 2024 10:31
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