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

Make fields not nullable #137

Merged
merged 4 commits into from
Jan 20, 2025
Merged

Make fields not nullable #137

merged 4 commits into from
Jan 20, 2025

Conversation

fracek
Copy link
Contributor

@fracek fracek commented Jan 20, 2025

Summary

This PR makes all non-nullable fields non-nullable.

Previously, the packages followed the Protobuf wisdom of marking all fields as nullable to enable backward and forward compatibility of the protocol.
In practice, this degraded the user experience since they had to perform null checks themselves.

Copy link

coderabbitai bot commented Jan 20, 2025

📝 Walkthrough

Walkthrough

This pull request introduces comprehensive changes across multiple Apibara packages, focusing on making various data structure properties required instead of optional. The modifications span three main packages: Beaconchain, EVM, and Starknet. The changes primarily involve updating type definitions in block-related files, enforcing stricter type requirements by converting optional properties to required ones. Additionally, new prerelease JSON configuration files were added for each package, indicating a coordinated update process.

Changes

File Change Summary
change/* Added prerelease JSON configurations for @apibara/beaconchain, @apibara/evm, and @apibara/starknet packages
packages/*/src/block.ts Converted numerous optional properties to required across Beaconchain, EVM, and Starknet block structures
examples/*/src/main.ts Updated stream configurations and filter structures for Beaconchain, EVM, and Starknet clients

Possibly related PRs

Poem

🐰 Schemas tightened, types aligned,
Optional fields now redefined.
Beaconchain, EVM, Starknet dance,
Strict typing takes its rightful stance!
CodeRabbit's precision shines bright. 🔍

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • 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 testing code 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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.

Actionable comments posted: 3

🧹 Nitpick comments (3)
examples/starknet-client/src/main.ts (1)

57-62: Consider performance implications of broad filtering.

The filter configuration now includes all possible data types with minimal filtering. While this provides comprehensive data access, it might impact performance due to increased data volume. Consider:

  1. Adding specific filters based on your actual data needs
  2. Implementing pagination or batch processing for large datasets
examples/beaconchain-client/src/main.ts (1)

41-42: Consider adding type validation for filter objects.

The empty objects in the filter arrays (validators: [{}], transactions: [{}]) will match all records without any filtering. While this might be intentional for the example, it could be helpful to:

  1. Add comments explaining that this configuration matches all records
  2. Show examples of actual filter criteria for better developer guidance
-      validators: [{}],
-      transactions: [{}],
-      blobs: [{}],
+      // Match all validators, transactions, and blobs
+      // For specific filtering, use criteria like:
+      validators: [{ validatorIndex: 123 }],
+      transactions: [{ from: "0x..." }],
+      blobs: [{ blobIndex: 0 }],
packages/beaconchain/src/block.ts (1)

74-91: Review mixed optionality in Transaction structure.

The Transaction structure has an inconsistent mix of required and optional fields:

  • Required: filterIds, transactionHash, nonce, from, value, input, accessList, transactionType
  • Optional: to, gasPrice, gasLimit, maxFeePerGas, maxPriorityFeePerGas, signature, chainId, maxFeePerBlobGas

Please document the rationale for keeping certain fields optional while making others required.

Consider grouping optional fields based on their relationship to specific transaction types or scenarios to improve code maintainability.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e0b831c and a6b4ba5.

📒 Files selected for processing (9)
  • change/@apibara-beaconchain-c34099f9-dc52-429f-ab71-d12ed169b2cc.json (1 hunks)
  • change/@apibara-evm-792c8a2f-e1df-4606-9ba7-a2dacb1264aa.json (1 hunks)
  • change/@apibara-starknet-50e54de7-179b-4570-bbb1-ce0627ba8466.json (1 hunks)
  • examples/beaconchain-client/src/main.ts (1 hunks)
  • examples/evm-client/src/main.ts (2 hunks)
  • examples/starknet-client/src/main.ts (3 hunks)
  • packages/beaconchain/src/block.ts (1 hunks)
  • packages/evm/src/block.ts (2 hunks)
  • packages/starknet/src/block.ts (17 hunks)
✅ Files skipped from review due to trivial changes (2)
  • change/@apibara-starknet-50e54de7-179b-4570-bbb1-ce0627ba8466.json
  • change/@apibara-beaconchain-c34099f9-dc52-429f-ab71-d12ed169b2cc.json
🔇 Additional comments (25)
examples/starknet-client/src/main.ts (2)

67-67: Document finality change implications.

Switching to "pending" finality means processing unconfirmed data, which could lead to:

  • Potential data inconsistencies
  • Need for reorg handling
  • Different behavior in production vs testing

Consider adding a comment explaining the rationale for this change and any necessary error handling.

Also applies to: 69-69


3-3: Verify cleanup of unused imports.

The imports have been simplified to match the current functionality. Let's verify no other unused imports remain in the codebase.

✅ Verification successful

Import cleanup verified successfully

The removed imports are properly cleaned up in examples/starknet-client/src/main.ts. The only remaining references to these imports are in commented-out code, which is acceptable.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining references to the removed imports
rg "decodeEvent|getSelector|formatUnits" --type ts

Length of output: 1600

packages/evm/src/block.ts (6)

87-89: ⚠️ Potential issue

Ensure Signature properties are correctly provided

All properties in Signature (r, s, v) are now required. Confirm that signature handling code provides these values to prevent deserialization errors.

To check for any instances where Signature might be missing required fields:

✅ Verification successful

Signature handling is properly implemented

While the Signature schema in block.ts now requires all fields, the underlying proto implementation in proto/data.ts properly handles partial objects and undefined values through:

  • Null-safe initialization in createBaseSignature()
  • Proper undefined checks in serialization methods
  • Safe partial object handling in fromPartial()
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for usage of Signature where properties might be missing

ast-grep --pattern 'Signature {
  r: $_,
  s: $_,
  v: $_,
  $$$
}'

Length of output: 69


Script:

#!/bin/bash
# Find Signature type definition and usages
rg -l "Signature" --type ts

# Find object literals that might be Signature instances
ast-grep --pattern '{
  r: $_,
  s: $_,
  v: $_
}'

# Find potential Signature construction or assignments
rg "Signature.*[{]" -A 3 --type ts

Length of output: 5928


47-58: ⚠️ Potential issue

Verify that making fields required in BlockHeader does not introduce breaking changes

Changing previously optional fields to required in BlockHeader may cause issues if any data sources or deserialization processes provide incomplete data. Ensure that all data providers supply these fields consistently to prevent runtime errors.

To verify that all usages of BlockHeader in the codebase handle these required fields appropriately, please run the following script:

✅ Verification successful

Making fields required in BlockHeader is safe and does not introduce breaking changes

The codebase implements a robust two-layer architecture where:

  • Protocol buffer definitions maintain backward compatibility with optional fields
  • Schema definitions enforce type safety with required fields
  • Transformation methods handle the conversion safely with default values
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for all deserialization of BlockHeader and check for handling of required fields

# Find all files that import BlockHeader
fd --type f ".*\.ts$" | xargs grep -l "BlockHeader"

# Alternatively, check for any instances where BlockHeader is constructed without these fields
ast-grep --pattern 'BlockHeader {
  blockHash: $_,
  parentBlockHash: $_,
  unclesHash: $_,
  miner: $_,
  stateRoot: $_,
  transactionsRoot: $_,
  receiptsRoot: $_,
  logsBloom: $_,
  difficulty: $_,
  gasLimit: $_,
  gasUsed: $_,
  timestamp: $_,
  $$$
}'

Length of output: 508


Script:

#!/bin/bash
# Check proto files for BlockHeader definitions and optional fields
echo "=== Checking proto/data.ts files ==="
for f in packages/*/src/proto/data.ts; do
  echo "=== $f ==="
  rg "BlockHeader" -A 10 -B 10 "$f"
done

echo -e "\n=== Checking block.ts files ==="
for f in packages/*/src/block.ts; do
  echo "=== $f ==="
  rg "BlockHeader" -A 10 -B 10 "$f"
done

# Look specifically for optional fields
echo -e "\n=== Checking for optional fields ==="
rg "\?: " packages/*/src/proto/data.ts packages/*/src/block.ts

Length of output: 59144


73-78: ⚠️ Potential issue

Ensure all Withdrawal instances provide required fields

The properties filterIds, address, and amount in Withdrawal are now required. Verify that all parts of the application creating or processing Withdrawal instances supply these fields to avoid runtime errors.

Here is a script to help verify that all Withdrawal instances have these fields:


133-141: ⚠️ Potential issue

Ensure Log instances include new required fields

Fields filterIds, address, transactionHash, and transactionStatus in Log are now required. Verify that all logs include these fields to prevent issues during processing.

Use the following script to check Log usage:

✅ Verification successful

Schema system enforces required Log fields

The Schema-based type system ensures that all Log instances must include the required fields with correct types. The logs array in the Block schema validates this structure at runtime.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that all Log instances have required fields

ast-grep --pattern 'Log {
  filterIds: $_,
  address: $_,
  topics: $_,
  data: $_,
  logIndex: $_,
  logIndexInTransaction: $_,
  transactionIndex: $_,
  transactionHash: $_,
  transactionStatus: $_,
  $$$
}'

Length of output: 211


Script:

#!/bin/bash
# Find Log definition and usage
echo "=== Log Definition ==="
ast-grep --pattern 'type Log = $_'
ast-grep --pattern 'interface Log $_'
ast-grep --pattern 'class Log $_'

echo -e "\n=== Log Usage ==="
rg "new Log\(" -A 5 -B 5

echo -e "\n=== Log References ==="
rg "\blog\b.*:.*Log\b" -A 2 -B 2

Length of output: 406


Script:

#!/bin/bash
# Find Log.Type definition and usage patterns
echo "=== Log Type Definition ==="
rg "Log\.Type" -A 10 -B 10

echo -e "\n=== Object Literals with Log Fields ==="
rg "filterIds.*address.*topics.*data.*logIndex" -A 10

echo -e "\n=== Schema Usage with Log ==="
rg "Schema\.Object\(\{.*Log" -A 15 -B 2

Length of output: 1455


147-147: ⚠️ Potential issue

Verify that Block objects always include header

The header property in Block is now required. Ensure that all blocks include a header and that any code constructing Block instances provides the header field.

To find instances where Block might be constructed without a header:

✅ Verification successful

Block schema correctly enforces required header field

The Block schema is defined using Effect Schema's Schema.Struct which enforces the presence of all required fields at runtime. The header field is correctly marked as required (non-optional) in the schema definition, ensuring that all Block instances must include a header.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for Block instances missing required header field

ast-grep --pattern 'Block {
  header: $_,
  $$$
}'

Length of output: 52


Script:

#!/bin/bash
# Search for Block type definitions and instantiations
echo "=== Block type/interface definitions ==="
ast-grep --pattern 'interface Block {
  $$$
}'

echo -e "\n=== Block class definitions ==="
ast-grep --pattern 'class Block {
  $$$
}'

echo -e "\n=== Block type assignments ==="
ast-grep --pattern 'type Block = {
  $$$
}'

echo -e "\n=== Block instantiations ==="
rg "new Block\(" -A 5

echo -e "\n=== Block object literals ==="
rg "as Block" -A 5

Length of output: 4895


Script:

#!/bin/bash
# Check the specific Block type in the EVM package
echo "=== Block type in packages/evm/src/block.ts ==="
cat packages/evm/src/block.ts

echo -e "\n=== Usage of Block from block.ts ==="
rg -l "from ['\"].*block['\"]" --type ts

Length of output: 5149


94-112: ⚠️ Potential issue

Review required fields in Transaction schema for potential impacts

Several fields in Transaction are now required, including filterIds, transactionHash, from, value, gas, and transactionType. This may affect code that constructs Transaction objects or processes them. Ensure that these fields are always available and supplied properly.

To verify that all Transaction instances provide the required fields, run:

✅ Verification successful

Required fields in Transaction schema are properly handled

The review comment's concern has been investigated and no issues were found. The required fields in the Transaction schema are properly handled through:

  1. Schema validation via the Schema.Struct definition
  2. Proper initialization in protobuf implementations
  3. Default values provided where appropriate
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find all instances of Transaction creation and ensure required fields are provided

ast-grep --pattern 'Transaction {
  filterIds: $_,
  transactionIndex: $_,
  transactionHash: $_,
  nonce: $_,
  from: $_,
  to: $_,
  value: $_,
  gasPrice: $_,
  gas: $_,
  maxFeePerGas: $_,
  maxPriorityFeePerGas: $_,
  input: $_,
  signature: $_,
  chainId: $_,
  accessList: $_,
  transactionType: $_,
  $$$
}'

Length of output: 317


Script:

#!/bin/bash
# Find Transaction-related files and their context
rg -l "Transaction" --type ts

# Look for Transaction object creation or usage patterns
ast-grep --pattern 'new Transaction($_)'

# Look for object creation patterns that might match Transaction
ast-grep --pattern '{
  filterIds: $_,
  from: $_,
  gas: $_,
  $$$
}'

# Search for schema validation code
rg "Schema\." -A 5 --type ts

Length of output: 75282


Script:

#!/bin/bash
# Find Transaction construction and usage patterns
rg -A 5 "new Transaction\(" --type ts
rg -A 5 "Transaction\.make" --type ts
rg -A 5 "Transaction\(" --type ts

# Look for test files that might show Transaction usage
rg -l "Transaction" --type test

# Search for validation or error handling
rg -A 5 "validateTransaction|validateFields|validate.*Transaction" --type ts

Length of output: 21441

packages/starknet/src/block.ts (12)

84-85: ⚠️ Potential issue

Verify ResourceBoundsMapping includes required l1Gas and l2Gas

The fields l1Gas and l2Gas in ResourceBoundsMapping are now required. Ensure these are provided in all instances where ResourceBoundsMapping is used.

Use the following script to verify:

✅ Verification successful

Required fields l1Gas and l2Gas are properly enforced

The ResourceBoundsMapping Schema.Struct in block.ts correctly enforces both l1Gas and l2Gas as required fields. The implementation is consistent across all usages in the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check that ResourceBoundsMapping includes l1Gas and l2Gas

ast-grep --pattern 'ResourceBoundsMapping {
  l1Gas: $_,
  l2Gas: $_,
  $$$
}'

Length of output: 80


Script:

#!/bin/bash
# Find ResourceBoundsMapping definition and usages
echo "=== Finding ResourceBoundsMapping definition ==="
rg "type\s+ResourceBoundsMapping" -A 5

echo -e "\n=== Finding ResourceBoundsMapping usages ==="
rg "ResourceBoundsMapping" -B 2 -A 2

echo -e "\n=== Finding interface/type patterns ==="
ast-grep --pattern 'type ResourceBoundsMapping = {
  $$$
}'

ast-grep --pattern 'interface ResourceBoundsMapping {
  $$$
}'

Length of output: 14507


467-475: ⚠️ Potential issue

Confirm required fields in MessageToL1 are provided

The MessageToL1 schema now requires fields filterIds, fromAddress, toAddress, payload, messageIndex, transactionIndex, transactionHash, transactionStatus, and messageIndexInTransaction. Ensure these fields are included in all MessageToL1 instances.

Check with:

✅ Verification successful

All required fields in MessageToL1 are properly defined

The schema correctly defines all required fields without using optional markers. The implementation is consistent across the codebase, including the protobuf definitions and TypeScript interfaces.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify MessageToL1 instances include required fields

ast-grep --pattern 'MessageToL1 {
  filterIds: $_,
  fromAddress: $_,
  toAddress: $_,
  payload: $_,
  messageIndex: $_,
  transactionIndex: $_,
  transactionHash: $_,
  transactionStatus: $_,
  messageIndexInTransaction: $_,
  $$$
}'

Length of output: 237


Script:

#!/bin/bash
# First find all relevant files
echo "=== Files containing MessageToL1 ==="
rg "MessageToL1" --type ts

echo -e "\n=== Type definitions ==="
# Search for type/interface definitions
ast-grep --pattern 'type MessageToL1 = {
  $$$
}'

ast-grep --pattern 'interface MessageToL1 {
  $$$
}'

echo -e "\n=== Object creations ==="
# Search for object creations with MessageToL1 type
rg "MessageToL1" -A 10 -B 2

Length of output: 41547


373-377: ⚠️ Potential issue

Ensure TransactionReceiptMeta required fields are provided

Fields transactionIndex, transactionHash, actualFee, executionResources, and executionResult are now required in TransactionReceiptMeta. Verify that all receipt instances include these fields.

Check usage with:

✅ Verification successful

Required fields in TransactionReceiptMeta are properly enforced

The fields are correctly required through:

  • Schema.Struct definition in block.ts
  • Required fields in the Protocol Buffer message
  • Proper encoding/decoding implementation

The apparent optionality in the TypeScript interface is due to protobuf-ts generation patterns and doesn't affect the runtime requirements.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify TransactionReceiptMeta includes required fields

ast-grep --pattern 'TransactionReceiptMeta {
  transactionIndex: $_,
  transactionHash: $_,
  actualFee: $_,
  executionResources: $_,
  executionResult: $_,
  $$$
}'

Length of output: 168


Script:

#!/bin/bash
# Find TransactionReceiptMeta definition and usages

# Find the type/interface definition
echo "=== TransactionReceiptMeta Definition ==="
ast-grep --pattern 'type TransactionReceiptMeta = $_'
ast-grep --pattern 'interface TransactionReceiptMeta $_'

# Find usages of TransactionReceiptMeta
echo -e "\n=== TransactionReceiptMeta Usages ==="
rg "TransactionReceiptMeta" -A 5 -B 5

# Look for object creation or assignments
echo -e "\n=== Object Creation/Assignment Patterns ==="
rg "as TransactionReceiptMeta|: TransactionReceiptMeta" -A 10

Length of output: 22248


442-450: ⚠️ Potential issue

Ensure Event objects include new required fields

Fields filterIds, address, keys, data, eventIndex, transactionIndex, transactionHash, transactionStatus, and eventIndexInTransaction in Event are now required. Confirm that all events include these fields to avoid issues during event processing.

Use the following script to check Event usage:

✅ Verification successful

Event fields are correctly identified as required

The review comment is accurate. The Event schema in packages/starknet/src/block.ts enforces all fields (filterIds, address, keys, data, eventIndex, transactionIndex, transactionHash, transactionStatus, and eventIndexInTransaction) as required through runtime validation. While the TypeScript interface in proto/data.ts marks these fields as optional for type-checking purposes, the schema validation ensures they are present at runtime.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that all Event instances have required fields

ast-grep --pattern 'Event {
  filterIds: $_,
  address: $_,
  keys: $_,
  data: $_,
  eventIndex: $_,
  transactionIndex: $_,
  transactionHash: $_,
  transactionStatus: $_,
  eventIndexInTransaction: $_,
  $$$
}'

Length of output: 215


Script:

#!/bin/bash
# Find Event type/interface definition and usage
echo "=== Event Definition ==="
ast-grep --pattern 'interface Event {
  $$$
}'

echo -e "\n=== Event Type Definition ==="
ast-grep --pattern 'type Event = {
  $$$
}'

echo -e "\n=== Event Usage ==="
rg "Event" -A 5 -B 5

echo -e "\n=== Event Object Creation ==="
ast-grep --pattern 'const $_ : Event = {
  $$$
}'

Length of output: 66636


586-586: ⚠️ Potential issue

Verify that Block objects include the required header field

The header property in Block is now required. Ensure that all block instances provide the header field to avoid issues during block processing.

To find instances where Block might be missing the header:

✅ Verification successful

Block header field is correctly marked as required

The implementation in packages/starknet/src/block.ts confirms that the header field is required in the Block schema. This matches the review comment's assertion and ensures type safety for block processing.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for Block instances missing required header field

ast-grep --pattern 'Block {
  header: $_,
  $$$
}'

Length of output: 52


Script:

#!/bin/bash
# Find Block type/interface definition and usages
echo "=== Block type definition ==="
ast-grep --pattern 'interface Block {
  $$$
}'

echo -e "\n=== Block type usages ==="
rg "new Block" -A 2

echo -e "\n=== Block header references ==="
rg "Block.*header" -A 2

Length of output: 9952


Script:

#!/bin/bash
# Check Block implementation in block.ts
echo "=== Block class definition ==="
cat packages/starknet/src/block.ts

echo -e "\n=== Other Block class definitions ==="
ast-grep --pattern 'class Block {
  $$$
}'

Length of output: 18035


498-500: ⚠️ Potential issue

Ensure StorageDiff instances provide required fields

Fields filterIds, contractAddress, and storageEntries in StorageDiff are now required. Verify that all storage diffs include these fields.

Use the following script:

✅ Verification successful

Schema validation ensures required fields are present

The Schema definition in block.ts correctly enforces that all StorageDiff instances must include filterIds, contractAddress, and storageEntries fields. The Schema.Struct definition does not use Schema.optional, making these fields required. While the protobuf-generated interface shows these as optional, the Schema validation layer ensures compliance with the requirements.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check StorageDiff instances for required fields

ast-grep --pattern 'StorageDiff {
  filterIds: $_,
  contractAddress: $_,
  storageEntries: $_,
  $$$
}'

Length of output: 106


Script:

#!/bin/bash
# Search for StorageDiff type definitions and usages
echo "=== StorageDiff type definitions ==="
ast-grep --pattern 'type StorageDiff = $_'

echo -e "\n=== StorageDiff interface/class definitions ==="
ast-grep --pattern 'interface StorageDiff {
  $$$
}'

echo -e "\n=== StorageDiff object creations ==="
rg "StorageDiff" -A 5 -B 5

echo -e "\n=== Files containing StorageDiff ==="
fd . -t f -x grep -l "StorageDiff" {} \;

Length of output: 30662


556-557: ⚠️ Potential issue

Verify ContractChange includes required filterIds and change

Fields filterIds and change in ContractChange are now required. Ensure that all contract changes include these fields to maintain data integrity.

Check usage with:

✅ Verification successful

Schema definition confirms required fields

The Schema definition in packages/starknet/src/block.ts enforces both filterIds and change as required fields in ContractChange, validating the review comment's concern.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify ContractChange instances have required fields

ast-grep --pattern 'ContractChange {
  filterIds: $_,
  change: $_,
  $$$
}'

Length of output: 78


Script:

#!/bin/bash
# Search for ContractChange definition and usages
echo "=== ContractChange Definition ==="
rg "ContractChange" -A 5 -B 5

echo -e "\n=== ContractChange Type/Interface Definition ==="
ast-grep --pattern 'interface ContractChange {
  $$$
}'

ast-grep --pattern 'type ContractChange = {
  $$$
}'

echo -e "\n=== ContractChange Schema Definition ==="
ast-grep --pattern 'const ContractChange = Schema.$$$'

echo -e "\n=== ContractChange Usages ==="
rg "ContractChange\(" -A 2

Length of output: 30676


292-305: ⚠️ Potential issue

Verify that Transaction instances correctly provide required fields

The Transaction schema now requires filterIds, meta, and specifies required fields in transaction variants. Ensure that all transaction instances comply with the updated schema and that any code constructing transactions includes the required fields.

To verify usage:

✅ Verification successful

Transaction schema requirements are properly enforced

The implementation ensures that all Transaction instances comply with the schema requirements through:

  • Schema.Struct validation enforcing the required fields
  • Proper initialization through proto methods that handle all required fields
  • No evidence of direct object creation bypassing the schema validation
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check that all Transaction instances conform to the new required fields

ast-grep --pattern 'Transaction {
  filterIds: $_,
  meta: $_,
  transaction: $_,
  $$$
}'

Length of output: 92


Script:

#!/bin/bash
# Find Transaction type usage and creation patterns
echo "=== Transaction type usage ==="
rg "Transaction[^a-zA-Z]" --type ts -A 2

echo -e "\n=== Transaction object creation ==="
rg "new Transaction|as Transaction|: Transaction =" --type ts -A 2

echo -e "\n=== Transaction imports ==="
rg "import.*Transaction" --type ts

Length of output: 56571


Script:

#!/bin/bash
# Find transaction construction and usage in tests and implementation
echo "=== Transaction construction in tests ==="
rg "filterIds.*meta.*transaction" --type ts -A 5

echo -e "\n=== Transaction usage in implementation ==="
rg "createBaseTransaction|Transaction\.fromPartial|Transaction\.create" --type ts -A 2

Length of output: 11113


123-131: ⚠️ Potential issue

Confirm all BlockHeader required fields are provided

Fields like parentBlockHash, sequencerAddress, timestamp, starknetVersion, l1GasPrice, l1DataGasPrice, and l1DataAvailabilityMode are now required in BlockHeader. Verify that these fields are always present in BlockHeader instances.

Check with:

✅ Verification successful

Required fields are correctly enforced in BlockHeader schema

The BlockHeader schema in packages/starknet/src/block.ts properly enforces all the mentioned fields as required through the Schema.Struct definition. Only newRoot is explicitly marked as optional, while parentBlockHash, sequencerAddress, timestamp, starknetVersion, l1GasPrice, l1DataGasPrice, and l1DataAvailabilityMode are all required fields.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Ensure BlockHeader instances include all required fields

ast-grep --pattern 'BlockHeader {
  blockHash: $_,
  parentBlockHash: $_,
  blockNumber: $_,
  sequencerAddress: $_,
  newRoot: $_,
  timestamp: $_,
  starknetVersion: $_,
  l1GasPrice: $_,
  l1DataGasPrice: $_,
  l1DataAvailabilityMode: $_,
  $$$
}'

Length of output: 252


Script:

#!/bin/bash
# Find BlockHeader definition
ast-grep --pattern 'interface BlockHeader {
  $$$
}'

echo "=== Searching for class definition ==="
ast-grep --pattern 'class BlockHeader {
  $$$
}'

echo "=== Searching for type definition ==="
ast-grep --pattern 'type BlockHeader = {
  $$$
}'

echo "=== Looking for BlockHeader instantiations ==="
rg "new BlockHeader" -A 5

echo "=== Looking for potential factory methods ==="
rg "BlockHeader" -B 2 -A 5

Length of output: 42876


568-570: ⚠️ Potential issue

Ensure NonceUpdate instances provide required fields

Fields filterIds, contractAddress, and nonce in NonceUpdate are now required. Confirm that all nonce updates include these fields to prevent inconsistencies.

Use the following script to verify:

✅ Verification successful

Schema enforces required fields for NonceUpdate

The NonceUpdate schema in block.ts explicitly requires all fields (filterIds, contractAddress, and nonce) through Schema.Struct without any optional fields. The implementation ensures that all nonce updates must include these fields to pass schema validation.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check NonceUpdate instances for required fields

ast-grep --pattern 'NonceUpdate {
  filterIds: $_,
  contractAddress: $_,
  nonce: $_,
  $$$
}'

Length of output: 97


Script:

#!/bin/bash
# Search for NonceUpdate in various contexts
echo "=== Searching for NonceUpdate type/class definitions ==="
rg "NonceUpdate" -A 5 -B 5

echo -e "\n=== Searching for NonceUpdate instantiation patterns ==="
ast-grep --pattern "new NonceUpdate"

echo -e "\n=== Searching for NonceUpdate as a type annotation ==="
ast-grep --pattern ": NonceUpdate"

echo -e "\n=== Looking for files containing NonceUpdate ==="
fd -t f | xargs rg "NonceUpdate" -l

Length of output: 27934


79-80: ⚠️ Potential issue

Ensure required fields in ResourceBounds are always provided

Fields maxAmount and maxPricePerUnit in ResourceBounds are now required. Confirm that all instances of ResourceBounds provide these fields to avoid runtime errors.

To check the usage of ResourceBounds:

✅ Verification successful

Schema correctly enforces required fields while maintaining compatibility

The implementation is well-designed:

  • Schema validation ensures required fields are present at runtime
  • Protocol layer maintains backward compatibility with optional fields
  • Encoding/decoding logic properly handles all cases
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that ResourceBounds instances have required fields

ast-grep --pattern 'ResourceBounds {
  maxAmount: $_,
  maxPricePerUnit: $_,
  $$$
}'

Length of output: 87


Script:

#!/bin/bash
# First, find all relevant files
echo "=== Files containing ResourceBounds ==="
rg -l "ResourceBounds"

echo -e "\n=== ResourceBounds type usage ==="
rg "ResourceBounds" -A 5 -B 5

echo -e "\n=== Object creation patterns ==="
# Try different object creation patterns
ast-grep --pattern 'resourceBounds: {
  $$$
}'

ast-grep --pattern 'resourceBounds = {
  $$$
}'

# Look for type annotations
ast-grep --pattern ': ResourceBounds = {
  $$$
}'

Length of output: 35737


Script:

#!/bin/bash
# Look for test files and actual usage
echo "=== Test files containing ResourceBounds ==="
rg -l "ResourceBounds" --glob "**/*test*.*"

echo -e "\n=== ResourceBounds instantiation in tests ==="
rg "ResourceBounds" -A 10 -B 10 --glob "**/*test*.*"

echo -e "\n=== Direct object creation patterns ==="
rg "resourceBounds.*=.*{" -A 5
rg "ResourceBounds.*=.*{" -A 5

Length of output: 671


Script:

#!/bin/bash
# Search for object literals and field usage
echo "=== Object literals with required fields ==="
rg "maxAmount.*maxPricePerUnit|maxPricePerUnit.*maxAmount" -A 5 -B 5

echo -e "\n=== Resource bounds assignments ==="
rg "resourceBounds" -A 5 -B 5

echo -e "\n=== Function calls with resource bounds ==="
ast-grep --pattern 'resourceBounds: $_'

Length of output: 23298


145-147: ⚠️ Potential issue

Ensure TransactionMeta includes required fields

Fields transactionIndex, transactionHash, and transactionStatus are now required in TransactionMeta. Confirm these are provided in all transactions.

Check with:

✅ Verification successful

TransactionMeta fields are properly enforced by Schema validation

The Schema.Struct definition in block.ts ensures that transactionIndex, transactionHash, and transactionStatus are required fields. While the proto interface marks these fields as optional for wire format compatibility, the Schema validation layer enforces their presence when the data is processed through the application's type system.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify TransactionMeta includes required fields

ast-grep --pattern 'TransactionMeta {
  transactionIndex: $_,
  transactionHash: $_,
  transactionStatus: $_,
  $$$
}'

Length of output: 120


Script:

#!/bin/bash
# Find TransactionMeta definition
echo "=== Finding TransactionMeta definition ==="
rg "type\s+TransactionMeta|interface\s+TransactionMeta" -A 10

echo -e "\n=== Finding TransactionMeta usage ==="
rg "TransactionMeta" --type ts -C 2

Length of output: 8010


Script:

#!/bin/bash
# Look for transformation or validation logic between proto and schema
echo "=== Searching for proto to schema transformations ==="
rg -B 3 -A 3 "fromProto|toProto|validate" packages/starknet/src/

echo -e "\n=== Searching for Transaction usage patterns ==="
rg "new\s+Transaction|Transaction\(" --type ts -C 2

Length of output: 18197


Script:

#!/bin/bash
# Search for Schema validation and error handling
echo "=== Searching for Schema validation and error handling ==="
rg "Schema\.(validate|parse|check)" packages/starknet/src/ -B 2 -A 2

echo -e "\n=== Looking for TransactionMeta usage in tests ==="
rg "TransactionMeta" packages/starknet/src/**/*test*

Length of output: 441


Script:

#!/bin/bash
# Find test files and Schema usage
echo "=== Finding test files ==="
fd "test" packages/starknet/src/

echo -e "\n=== Looking for Schema imports and usage ==="
rg "import.*Schema" packages/starknet/src/ -B 1 -A 3

echo -e "\n=== Looking for TransactionMeta in tests (adjusted path) ==="
fd "test" packages/starknet/src/ -x rg "TransactionMeta" {}

Length of output: 1821


Script:

#!/bin/bash
# Look for Schema.Struct usage patterns
echo "=== Finding Schema.Struct usage patterns ==="
rg "Schema\.Struct" packages/starknet/src/ -B 2 -A 2

echo -e "\n=== Looking for validation or parsing code ==="
rg "parse|decode|fromJSON|fromPartial" packages/starknet/src/block.ts -C 2

Length of output: 23443

examples/evm-client/src/main.ts (2)

23-23: Update to the default EVM stream URL

The default stream URL has been changed to "https://ethereum-sepolia.preview.apibara.org". Ensure this endpoint is valid, accessible, and updated throughout the documentation or related code if necessary.

If the old URL is deprecated, consider updating any references to it elsewhere.


39-41: Update filter configuration for transactions

The filter now includes detailed transaction options to include receipts, logs, and all transaction statuses:

transactions: [
  { includeReceipt: true, transactionStatus: "all", includeLogs: true },
],

Ensure that this configuration aligns with the expected data from the stream and that the application handles the additional data appropriately.

packages/beaconchain/src/block.ts (3)

64-69: Consider the implications of optional signature fields.

While other structures are being made more strict, the new Signature structure introduces optional fields. This seems inconsistent with the PR's objective. Is there a specific reason these fields need to be optional?

Could we make some of these fields required based on the transaction type or chain requirements?


Line range hint 97-101: LGTM: Block structure changes.

The changes to make header required and keep arrays for validators, blobs, and transactions are appropriate. Empty arrays can represent the absence of these elements while maintaining type safety.


9-16: Verify backward compatibility for ExecutionPayload.

Making these fields required is a breaking change. While it improves type safety, we need to ensure that all data sources (especially historical data) always provide these fields.

Comment on lines +89 to +96
// const { args, transactionHash } = decodeEvent({
// abi,
// eventName: "Transfer",
// event,
// });
// consola.info(
// `${prettyAddress(args.from)} -> ${prettyAddress(args.to)} ${formatUnits(args.value, 6)} ${colors.gray(transactionHash ?? "")}`,
// );
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Remove commented code.

Instead of keeping commented code in the codebase:

  1. Remove it if it's no longer needed
  2. If it's for reference, move it to documentation
  3. If it's temporary, create a TODO issue to track its restoration

Comment on lines +116 to +129
filterIds: Schema.Array(Schema.Number),
transactionIndex: Schema.Number,
transactionHash: B256,
cumulativeGasUsed: U128,
gasUsed: U128,
effectiveGasPrice: U128,
from: Address,
to: Schema.optional(Address),
contractAddress: Schema.optional(Address),
logsBloom: Schema.optional(Bloom),
transactionType: Schema.optional(Schema.BigIntFromSelf),
logsBloom: Bloom,
transactionType: Schema.BigIntFromSelf,
blobGasUsed: Schema.optional(U128),
blobGasPrice: Schema.optional(U128),
transactionStatus: Schema.optional(TransactionStatus),
transactionStatus: TransactionStatus,
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

⚠️ Potential issue

Schema and Implementation Mismatch for Required Fields in TransactionReceipt

The verification reveals a critical mismatch between the schema requirements and the implementation:

  • The schema in block.ts correctly defines required fields (filterIds, transactionIndex, transactionHash, etc.)
  • However, the implementation in proto/data.ts doesn't enforce these requirements:
    • createBaseTransactionReceipt initializes required fields as undefined
    • fromPartial method doesn't validate the presence of required fields

This needs to be fixed to prevent potential runtime validation errors.

🔗 Analysis chain

Confirm that TransactionReceipt required fields are handled

With filterIds, transactionIndex, transactionHash, cumulativeGasUsed, gasUsed, effectiveGasPrice, and from now required in TransactionReceipt, ensure that all instances where TransactionReceipt is used provide these fields.

Check for proper handling by running:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that all TransactionReceipt instances provide required fields

ast-grep --pattern 'TransactionReceipt {
  filterIds: $_,
  transactionIndex: $_,
  transactionHash: $_,
  cumulativeGasUsed: $_,
  gasUsed: $_,
  effectiveGasPrice: $_,
  from: $_,
  to: $_,
  contractAddress: $_,
  logsBloom: $_,
  transactionType: $_,
  transactionStatus: $_,
  $$$
}'

Length of output: 290


Script:

#!/bin/bash
# Find TransactionReceipt imports and usages
echo "=== TransactionReceipt imports ==="
rg "import.*TransactionReceipt" -l

echo -e "\n=== TransactionReceipt type annotations ==="
rg ":\s*TransactionReceipt\b" -A 2

echo -e "\n=== TransactionReceipt instantiations ==="
# Less strict pattern matching for object creation
ast-grep --pattern 'new TransactionReceipt($_)'

# Alternative object creation pattern
ast-grep --pattern 'TransactionReceipt({$$$})'

echo -e "\n=== Spread operations with TransactionReceipt ==="
rg "\.\.\." -A 3 -B 3 $(rg "TransactionReceipt" -l)

Length of output: 4756


Script:

#!/bin/bash
# Check implementation details
echo "=== TransactionReceipt base implementation ==="
rg -A 20 "function createBaseTransactionReceipt\(\)" packages/evm/src/proto/data.ts

echo -e "\n=== Schema validation ==="
rg -A 10 "TransactionReceipt.*Schema\." packages/evm/src/

echo -e "\n=== fromPartial implementation ==="
rg -A 20 "fromPartial.*TransactionReceipt" packages/evm/src/proto/data.ts

Length of output: 3030

Comment on lines +2 to +6
"type": "prerelease",
"comment": "evm: make more fields required",
"packageName": "@apibara/evm",
"email": "[email protected]",
"dependentChangeType": "patch"
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Consider using a major version bump instead of patch.

The changes to make fields required are breaking changes that affect backward compatibility. According to semver:

  • A patch should only contain backward compatible bug fixes
  • Breaking changes should trigger a major version bump
-  "type": "prerelease",
-  "dependentChangeType": "patch"
+  "type": "prerelease",
+  "dependentChangeType": "major"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"type": "prerelease",
"comment": "evm: make more fields required",
"packageName": "@apibara/evm",
"email": "[email protected]",
"dependentChangeType": "patch"
"type": "prerelease",
"comment": "evm: make more fields required",
"packageName": "@apibara/evm",
"email": "[email protected]",
"dependentChangeType": "major"

@fracek fracek merged commit 854fcc7 into apibara:main Jan 20, 2025
2 checks passed
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.

1 participant