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

Empty miner field on eth_getBlockByNumber #463

Merged
merged 7 commits into from
Aug 23, 2024
Merged

Conversation

m-Peter
Copy link
Collaborator

@m-Peter m-Peter commented Aug 22, 2024

Closes: #454

Description

Note: The version bump of the flow-go dependency, comes with a backwards incompatible change on the block hash calculation.
If we want to deploy this change on testnet, we'll have to add some custom logic to accommodate that breaking change.


For contributor use:

  • Targeted PR against master branch
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the standards mentioned here.
  • Updated relevant documentation
  • Re-reviewed Files changed in the Github PR explorer
  • Added appropriate labels

Summary by CodeRabbit

  • New Features

    • Added a Miner field to block response, providing crucial miner address information.
    • Introduced a PrevRandao field in block events for enhanced event tracking.
    • Enhanced the Block structure with a new hash field and a method to return the block's hash.
    • Enhanced test cases to validate new Miner field and updated block sizes.
  • Bug Fixes

    • Adjusted expected block size in tests to reflect correct values.
  • Chores

    • Updated various dependencies to newer, stable versions for improved performance and security.

Copy link
Contributor

coderabbitai bot commented Aug 22, 2024

Walkthrough

The changes involve updates to the blockchain API to include a Miner field in the block response, reflecting the address of the miner who produced the block. Additionally, the PrevRandao field was added to the block data structure in event handling. Dependency updates were made to ensure compatibility with newer versions of libraries, and test cases were improved to validate these changes.

Changes

Files Change Summary
api/api.go Added Miner field to prepareBlockResponse function to include the miner's address.
models/block.go Introduced PrevRandao field in the returned Block structure and backward compatibility handling in NewBlockFromBytes.
models/block_test.go, models/events_test.go Enhanced tests by adding PrevRandao to block structures, updating expected hash values, and modifying the newBlock function for additional parameters.
go.mod, tests/go.mod Updated various dependencies to newer versions for stability and compatibility improvements.
tests/web3js/eth_non_interactive_test.js Modified assertions to include checks for block.size and added verification for the block.miner field.

Assessment against linked issues

Objective Addressed Explanation
Empty miner field on eth_getBlockByNumber (#454)
Ensure PrevRandao field is included in block data
Update tests to validate miner address

🐰 In the meadow where code does bloom,
Changes sprout and dispel the gloom.
A miner's address now shines so bright,
Validating blocks with newfound light.
Jumping through tests, we dance in delight! 🌼✨


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 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

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

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
Contributor

@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: 0

Outside diff range, codebase verification and nitpick comments (1)
api/api.go (1)

969-969: Issue Found: CoinbaseAddress is not defined in the codebase.

The CoinbaseAddress used in api/api.go does not have a corresponding definition within the codebase. This could lead to runtime errors. Please ensure that CoinbaseAddress is correctly defined or imported from the appropriate package.

  • File: api/api.go
  • Line: 969
Analysis chain

LGTM! Verify the correctness of CoinbaseAddress.

The addition of the Miner field to the block response is a positive change that aligns with the PR objectives. Ensure that evmTypes.CoinbaseAddress correctly represents the miner's address in all contexts.

Run the following script to verify the definition and usage of CoinbaseAddress:

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the definition and usage of `CoinbaseAddress`.

# Test: Search for the definition and usage of `CoinbaseAddress`. Expect: Correct definition and usage.
rg --type go 'CoinbaseAddress'

Length of output: 98


Script:

#!/bin/bash
# Description: Search for the definition of `CoinbaseAddress` in the codebase.

# Test: Locate the definition of `CoinbaseAddress`. Expect: Definition found.
rg --type go 'CoinbaseAddress'

Length of output: 98

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between daa037a and a24b07d.

Files ignored due to path filters (2)
  • go.sum is excluded by !**/*.sum
  • tests/go.sum is excluded by !**/*.sum
Files selected for processing (7)
  • api/api.go (2 hunks)
  • go.mod (5 hunks)
  • models/block.go (1 hunks)
  • models/block_test.go (4 hunks)
  • models/events_test.go (1 hunks)
  • tests/go.mod (4 hunks)
  • tests/web3js/eth_non_interactive_test.js (1 hunks)
Additional comments not posted (17)
models/block.go (1)

63-63: Addition of PrevRandao field in Block structure.

The addition of the PrevRandao field enhances the block data structure by providing additional information. Ensure that this change is consistently handled across the codebase.

models/block_test.go (4)

23-23: Inclusion of PrevRandao in Test_DecodeBlockExecutedEvent.

The addition of PrevRandao in this test case ensures that the new field is correctly decoded and validated.


48-48: Update of hash constant in Test_Hash.

The updated hash value reflects changes in the block data or hashing algorithm. Ensure that this change is intentional and documented.


57-57: Inclusion of PrevRandao in Test_Hash.

The addition of PrevRandao in this test case ensures that the hash calculation accounts for the new field.


75-75: Inclusion of PrevRandao in Test_EncodingDecoding.

The addition of PrevRandao in this test case ensures that encoding and decoding processes handle the new field correctly.

models/events_test.go (1)

178-183: Inclusion of PrevRandao in newBlock function.

The addition of the PrevRandao parameter in the newBlock function ensures that block creation includes the new field, maintaining consistency with the updated block structure.

tests/web3js/eth_non_interactive_test.js (2)

28-28: Update to block size assertion.

The expected block size has been updated to 3994n. Ensure this matches the actual block size returned by the API.


29-29: Addition of miner assertion.

The test now verifies the block.miner field. Ensure that the miner address '0x0000000000000000000000030000000000000000' is correct and consistent with the expected data.

go.mod (5)

10-12: Dependency updates for atree, cadence, and flow-go.

These updates reflect a shift to newer versions. Ensure compatibility with the rest of the codebase and check for any breaking changes introduced by these updates.


24-24: Update to golang.org/x/sync.

The version has been updated to v0.8.0. Verify that this update does not introduce any breaking changes.


42-42: Update to btcsuite/btcd/btcec/v2.

The version has been updated to v2.3.4. Ensure this update is compatible with the existing code.


137-137: Update to onflow/crypto.

The version has been updated to v0.25.2. Verify compatibility with the codebase.


196-200: Updates to golang.org/x packages.

The versions for crypto, net, sys, and text have been updated. Ensure these updates do not introduce breaking changes.

tests/go.mod (4)

7-11: Dependency updates for cadence, crypto, and flow-go.

These updates reflect a shift to newer versions. Ensure compatibility with the test code and check for any breaking changes introduced by these updates.


34-34: Update to btcsuite/btcd/btcec/v2.

The version has been updated to v2.3.4. Ensure this update is compatible with the test code.


148-148: Update to onflow/atree.

The version has been updated to v0.8.0-rc.6. Verify compatibility with the test code.


215-222: Updates to golang.org/x packages.

The versions for crypto, net, sync, sys, term, and text have been updated. Ensure these updates do not introduce breaking changes in the test code.

@sideninja
Copy link
Contributor

We should add logic for backward compatibility. Best, if you make it part of this PR

Copy link
Contributor

@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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a24b07d and a3be967.

Files ignored due to path filters (2)
  • go.sum is excluded by !**/*.sum
  • tests/go.sum is excluded by !**/*.sum
Files selected for processing (2)
  • go.mod (5 hunks)
  • tests/go.mod (4 hunks)
Files skipped from review due to trivial changes (1)
  • tests/go.mod
Files skipped from review as they are similar to previous changes (1)
  • go.mod

@m-Peter
Copy link
Collaborator Author

m-Peter commented Aug 23, 2024

We should add logic for backward compatibility. Best, if you make it part of this PR

I have added such a logic in this commit: 5b33fe1.
But now that we're in testnet, these changes are no longer temporary, as was the case with previewnet. Because we have to support them for as long as testnet is running 😅
Let me know if you have some alternative solution in mind.

Copy link
Contributor

@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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a3be967 and 5b33fe1.

Files selected for processing (2)
  • models/block.go (3 hunks)
  • models/block_test.go (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • models/block_test.go
Additional comments not posted (9)
models/block.go (9)

12-12: Imports look good.

The import statements are appropriate for the operations performed in the file.


32-41: Backward compatibility logic is well-implemented.

The function NewBlockFromBytes correctly handles backward compatibility by attempting to decode previous block versions.


49-49: Addition of hash field is appropriate.

The hash field in the Block struct is a necessary addition for storing the block's hash.


53-58: Efficient hash retrieval method.

The Hash method provides a clear and efficient way to retrieve the block's hash.


81-81: Decoding block event is correctly implemented.

The decodeBlockEvent function accurately decodes a block event into the Block type.


86-94: Backward compatibility struct blockV0 is appropriate.

The blockV0 struct is necessary for handling older block versions.


96-106: Inclusion of PrevRandao field in blockV1 is correct.

The blockV1 struct is necessary for handling newer block versions with the PrevRandao field.


108-111: Hash computation for past block is correctly implemented.

The pastBlockHash function correctly encodes the block and computes its hash.


113-148: Backward compatibility decoding is well-implemented.

The decodeBlockBreakingChanges function correctly handles decoding of previous block versions.

Comment on lines +53 to +58
func (b *Block) Hash() (gethCommon.Hash, error) {
if b.hash != nil {
return *b.hash, nil
}
return b.Block.Hash()
}
Copy link
Member

Choose a reason for hiding this comment

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

Do we need the caching ?

Copy link
Member

Choose a reason for hiding this comment

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

Is this Block object serialized? if yes are we worried about caching the hash?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This Block object is indeed serialized, but the hash field is only set for past blocks. Where past block means a block that fails to decode with the current format.

// decodeBlockBreakingChanges will try to decode the bytes into all
// previous versions of block type, if it succeeds it will return the
// migrated block, otherwise it will return nil.
func decodeBlockBreakingChanges(encoded []byte) *Block {
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this a cop of the code from flow go?
should we just export those methods?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, this is a copy from that code in flow-go. Though I am not sure if it still exists in the flow-go repo 🤔 .
We used to have these file changes for PreviewNet: 0e520ac. But removed them for testnet launch.

models/block.go Outdated
Comment on lines 132 to 146
b1 := &blockV1{}
if err := rlp.DecodeBytes(encoded, b1); err == nil {
return &Block{
Block: &types.Block{
ParentBlockHash: b1.ParentBlockHash,
Height: b1.Height,
Timestamp: b1.Timestamp,
TotalSupply: b1.TotalSupply,
ReceiptRoot: b1.ReceiptRoot,
TransactionHashRoot: b1.TransactionHashRoot,
TotalGasUsed: b1.TotalGasUsed,
PrevRandao: b1.PrevRandao,
},
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Do we need this, given the Block itself ? is similar to BlockV1

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

BlockV1 has the addition of the PrevRandao field, which BlockV0 does not have. Unless you mean something else which I'm missing 😅

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah right, now I see what you mean 😇

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed in 2f97be1

Copy link
Member

@ramtinms ramtinms left a comment

Choose a reason for hiding this comment

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

Just added some questions

Copy link
Contributor

@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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 5b33fe1 and 4952c93.

Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
Files selected for processing (1)
  • go.mod (5 hunks)
Additional comments not posted (10)
go.mod (10)

10-10: Dependency update approved for github.com/onflow/atree.

The update from v0.8.0-rc.5 to v0.8.0-rc.6 is likely to include minor improvements or bug fixes.


11-11: Dependency update approved for github.com/onflow/cadence.

The update from v1.0.0-preview.48 to v1.0.0-preview.49 is likely to include minor improvements or bug fixes.


12-12: Dependency update approved for github.com/onflow/flow-go.

The update from v0.37.1 to v0.37.6 might include bug fixes or improvements. However, ensure backward compatibility due to the mentioned breaking change in block hash calculation.


24-24: Dependency update approved for golang.org/x/sync.

The update from v0.7.0 to v0.8.0 is likely to include minor improvements or bug fixes.


42-42: Dependency update approved for github.com/btcsuite/btcd/btcec/v2.

The update from v2.2.1 to v2.3.4 is likely to include minor improvements or bug fixes.


137-137: Dependency update approved for github.com/onflow/crypto.

The update from v0.25.1 to v0.25.2 is likely to include minor improvements or bug fixes.


196-196: Dependency update approved for golang.org/x/crypto.

The update from v0.22.0 to v0.26.0 is likely to include minor improvements or bug fixes.


197-197: Dependency update approved for golang.org/x/net.

The update from v0.24.0 to v0.25.0 is likely to include minor improvements or bug fixes.


199-199: Dependency update approved for golang.org/x/sys.

The update from v0.20.0 to v0.23.0 is likely to include minor improvements or bug fixes.


200-200: Dependency update approved for golang.org/x/text.

The update from v0.14.0 to v0.17.0 is likely to include minor improvements or bug fixes.

Copy link
Contributor

@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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4952c93 and 2f97be1.

Files selected for processing (1)
  • models/block.go (3 hunks)
Additional comments not posted (6)
models/block.go (6)

12-12: Import addition is appropriate.

The gethCrypto import is necessary for hash calculations.


49-58: Enhancement of Block data model is appropriate.

The addition of the hash field and the Hash method improves the block's data model.


81-81: Addition of PrevRandao field is appropriate.

The PrevRandao field aligns with the changes mentioned in the PR summary and objectives.


86-94: Introduction of blockV0 type is necessary for backward compatibility.

The blockV0 type is essential for handling older block versions.


96-121: Functions for handling past block data are well-implemented.

The pastBlockHash and decodeBlockBreakingChanges functions are correctly implemented for handling past block data.

Run the following script to verify the usage of decodeBlockBreakingChanges in the codebase:

Verification successful

Usage of decodeBlockBreakingChanges is appropriate and limited to models/block.go.

The function decodeBlockBreakingChanges is used correctly within the models/block.go file to decode block data and handle errors. There are no other occurrences of this function in the codebase, indicating its specialized use.

  • File: models/block.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `decodeBlockBreakingChanges` in the codebase.

# Test: Search for the function usage. Expect: Occurrences of the function being called.
rg --type go -A 5 $'decodeBlockBreakingChanges'

Length of output: 841


32-41: Backward compatibility logic is well-implemented.

The NewBlockFromBytes function effectively handles decoding of previous block versions and assigns the hash correctly.

Run the following script to verify the usage of NewBlockFromBytes in the codebase:

Verification successful

Backward compatibility logic is well-implemented and verified.

The NewBlockFromBytes function is used in both test and non-test files, confirming its integration and backward compatibility handling within the codebase.

  • Usage Locations:
    • models/block_test.go: Tests the NewBlockFromBytes function.
    • storage/pebble/blocks.go: Utilizes the function for processing data.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `NewBlockFromBytes` in the codebase.

# Test: Search for the function usage. Expect: Occurrences of the function being called.
rg --type go -A 5 $'NewBlockFromBytes'

Length of output: 631

@m-Peter m-Peter merged commit 8e35c75 into main Aug 23, 2024
2 checks passed
@m-Peter m-Peter deleted the update-block-miner-field branch August 23, 2024 16:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

Empty miner field on eth_getBlockByNumber
4 participants