-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
chore(core): bring changes from serverv2 #19617
Conversation
WalkthroughWalkthroughThe recent update aims to enhance the core components of the system by refining various functionalities. This includes consolidating struct declarations, restructuring extension interfaces, introducing new interfaces for app modules, events, and transactions, improving gas tracking and error handling, and defining interfaces for non-consensus data operations in stores. These changes are designed to enhance modularity, efficiency, and clarity within the system's key components. Changes
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this 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.yml
Files selected for processing (13)
- core/appmodule/environment.go (1 hunks)
- core/appmodule/module.go (4 hunks)
- core/appmodule/v2/appmodule.go (1 hunks)
- core/appmodule/v2/environment.go (1 hunks)
- core/appmodule/v2/genesis.go (1 hunks)
- core/appmodule/v2/handlers.go (1 hunks)
- core/appmodule/v2/message.go (1 hunks)
- core/appmodule/v2/migrations.go (1 hunks)
- core/event/event.go (1 hunks)
- core/event/service.go (1 hunks)
- core/gas/meter.go (1 hunks)
- core/store/database.go (1 hunks)
- core/transaction/transaction.go (1 hunks)
Files skipped from review due to trivial changes (1)
- core/appmodule/environment.go
Additional comments: 26
core/appmodule/v2/genesis.go (1)
- 7-15: The
HasGenesis
interface is well-defined, focusing on custom genesis handling for app modules. It adheres to best practices by providing a clear contract for modules to implement genesis-related functionalities. The methodsDefaultGenesis
,ValidateGenesis
,InitGenesis
, andExportGenesis
cover the essential aspects of genesis handling, ensuring modules can define their default genesis state, validate genesis data, initialize their state at genesis, and export their current state as genesis data for future chains. This approach promotes modularity and maintainability by allowing each module to encapsulate its genesis logic.core/appmodule/v2/message.go (2)
- 9-10: The type alias
Message
forprotoiface.MessageV1
is correctly defined and simplifies the usage of protobuf messages within the app module context. This aliasing promotes code readability and maintainability by abstracting the underlying protobuf interface, making it easier for developers to work with messages without directly dealing with protobuf specifics.- 12-20: The
messageName
function is a clever utility that provides a way to dynamically retrieve the full name of a protobuf message based on its type. This function supports bothprotov2.Message
andgogoproto.Message
, covering the common use cases in the Cosmos SDK ecosystem. The use of type switches and the panic in the default case is appropriate here, as it enforces the function's contract that only supported message types are passed as arguments. However, it's important to ensure that this function is used in contexts where the message type is known and controlled to avoid runtime panics.core/appmodule/v2/environment.go (1)
- 12-22: The
Environment
struct is well-designed, serving as a central point for app modules to access various services likeBranchService
,EventService
,GasService
, and others. This design promotes modularity and maintainability by decoupling modules from direct dependencies on specific service implementations, allowing for easier testing and future changes to service implementations. The inclusion of aLogger
is also a good practice, enabling modules to perform logging without directly depending on a specific logging library.core/event/event.go (3)
- 3-10: The
Attribute
struct and its constructor functionNewAttribute
are correctly implemented, providing a simple yet effective way to represent key-value pair event attributes. This approach enhances code readability and maintainability by encapsulating the attribute creation logic within a dedicated function, promoting consistency across the codebase where event attributes are needed.- 12-19: The
Events
struct and its constructor functionNewEvents
are well-implemented, offering a straightforward way to aggregate multiple events. This design supports modularity and ease of event management within the system, allowing for the collection and handling of events in a structured manner. The use of variadic arguments inNewEvents
is particularly beneficial, providing flexibility in how events are aggregated.- 21-29: The
Event
struct and its constructor functionNewEvent
are effectively designed, facilitating the creation and handling of events with a specific type and a list of attributes. This structure is crucial for the event system's flexibility and extensibility, enabling modules to define and emit custom events that can be handled appropriately by other parts of the system. The clear separation of event type and attributes promotes better organization and readability of event-related code.core/store/database.go (2)
- 3-7: The
DatabaseService
interface is correctly defined, providing a clear contract for accessing the underlying database for CRUD operations of non-consensus data. The warning comment about the potential unprovability of modules using this API is crucial, ensuring developers are aware of the implications of using non-consensus data in their modules. This approach promotes careful consideration and responsible use of the database service in the context of blockchain applications.- 9-23: The
NonConsensusStore
interface is well-designed, offering a simple yet comprehensive set of methods for CRUD operations on non-consensus data. The emphasis on error handling, especially for nil keys, enhances the robustness of the interface. However, it's important to ensure that implementations of this interface properly document the behavior and expectations for each method, especially regarding error conditions and the handling of non-existent keys, to ensure consistency and predictability across different implementations.core/transaction/transaction.go (2)
- 12-17: The
Codec
interface is well-defined, providing a clear and concise contract for decoding transaction bytes into their concrete representation. This design promotes modularity and flexibility in transaction handling, allowing for different implementations of the codec that can handle various transaction formats. Ensuring that implementations of this interface handle decoding errors appropriately is crucial for the robustness of the transaction processing system.- 19-32: The
Tx
interface encapsulates the essential functionalities required for handling transactions, including hashing, retrieving messages and senders, getting the gas limit, and obtaining the byte representation of the transaction. This comprehensive approach supports a wide range of transaction types and processing requirements. However, the TODO comments regarding the evaluation of the hash size and the reduction of senders to a single identity highlight areas for future consideration and potential optimization, which should be addressed to ensure the interface's effectiveness and efficiency in various use cases.core/event/service.go (1)
- 36-38: > 📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [1-1]
The
Service
andManager
interfaces in theevent
package are well-designed, providing a comprehensive API for event handling within app modules. These interfaces allow for emitting both consensus and non-consensus events, supporting a wide range of use cases. The distinction between consensus and non-consensus events is crucial for blockchain applications, ensuring that developers can correctly categorize events based on their impact on the blockchain state. Implementations of these interfaces should ensure deterministic and consistent event emission to maintain the integrity of the blockchain's state machine.core/appmodule/v2/migrations.go (3)
- 5-11: The
HasConsensusVersion
interface provides a clear and essential method,ConsensusVersion
, for declaring a module's consensus version. This method is crucial for versioning and migration management within the blockchain application, ensuring that consensus-breaking changes are tracked and handled appropriately. The emphasis on incrementing the version number on each consensus-breaking change promotes careful change management and compatibility across versions.- 14-21: The
HasMigrations
interface, along with theRegisterMigrations
method, is effectively designed to support module upgrades and migrations. This interface encourages modular design by allowing each module to define its migration logic, facilitating smooth transitions between consensus versions. It's important for implementations to carefully document the migration process and ensure that migrations are tested thoroughly to prevent issues during upgrades.- 24-34: The
MigrationRegistrar
interface and itsRegister
method provide a structured way for modules to register their in-place store migrations. This approach is beneficial for managing complex migrations across module versions, ensuring that each step of the migration process is clearly defined and executable. The requirement to register a no-op function for consensus version bumps without store changes is a good practice, maintaining the integrity of the migration process even when no changes are necessary.core/gas/meter.go (4)
- 10-13: The introduction of the
ErrOutOfGas
error is a significant improvement in error handling for gas tracking. This explicit error type allows for more precise handling of out-of-gas scenarios, improving the robustness and user experience of the system by clearly signaling when a transaction has consumed all allowed gas. Implementations should ensure that this error is handled appropriately in all contexts where gas consumption is tracked.- 15-17: The
Gas
type alias foruint64
is a good practice, enhancing code readability and maintainability by providing a clear and specific type for gas values. This alias helps to avoid confusion with otheruint64
values that may represent different concepts, promoting clearer and more maintainable code.- 20-21: The
NoGasLimit
constant, set tomath.MaxUint64
, is a clear and effective way to signal that no gas limit should be applied. This constant is useful in scenarios where transactions or operations should not be restricted by gas consumption, providing flexibility in gas management. It's important for developers to use this constant judiciously to avoid unintended consequences, such as allowing transactions that could potentially consume excessive resources.- 22-22: The
Service
andMeter
interfaces are well-designed, providing a comprehensive API for gas tracking and management within app modules. These interfaces support both transaction-level and block-level gas metering, offering flexibility in how gas consumption is tracked and managed across different contexts. Implementations of these interfaces should ensure accurate and efficient gas tracking to maintain the performance and reliability of the blockchain application.core/appmodule/v2/appmodule.go (5)
- 9-19: The
AppModule
interface serves as a foundational tag interface for app module implementations, providing a basis for extension interfaces. This design promotes modularity and interoperability among modules by establishing a common type that all app modules should implement. The inclusion of dummy methods to tag and help resolve modules is a clever approach to leveraging Go's type system for module identification and dependency injection.- 21-29: The
HasBeginBlocker
interface, with itsBeginBlock
method, is correctly designed to allow modules to execute custom logic before transaction processing in a block. This lifecycle hook is essential for modules that need to perform setup or state checks at the beginning of each block, enhancing the flexibility and control modules have over the blockchain's execution flow.- 31-39: The
HasEndBlocker
interface, featuring theEndBlock
method, provides a mechanism for modules to execute custom logic after transaction processing in a block. This capability is crucial for cleanup, state finalization, or triggering actions based on the block's transactions, further enhancing the modularity and extensibility of the blockchain application.- 41-75: The
HasTxValidation
interface introduces a creative and flexible approach to transaction validation, allowing modules to implement custom logic for validating transactions. The detailed ASCII art comment effectively emphasizes the importance of theTxValidator
method in preventing invalid transactions from passing. This interface is a significant improvement over previous patterns, such as the AnteHandler, providing a more modular and expressive way to define transaction validation logic. It's important for implementations to carefully document the expected behavior and conditions under which transactions are considered valid or invalid.- 78-92: The
HasUpdateValidators
interface and theValidatorUpdate
struct provide a structured way for modules to participate in the validator set update process. This interface allows modules to propose changes to the validator set at the end of a block, supporting dynamic and decentralized validator management. The clear definition of theValidatorUpdate
struct, including the validator's public key, type, and updated power, facilitates precise and secure updates to the validator set.core/appmodule/module.go (2)
- 15-21: The use of type aliases to reference entities from the
appmodule/v2
package is a good practice, promoting code readability and maintainability by clearly indicating the source and version of the referenced entities. This approach helps to streamline the interface definitions and their relationships within the module, making it easier for developers to understand and work with the module's API.- 61-65: The redeclaration of
HasBeginBlocker
andHasEndBlocker
as type aliases from theappmodule/v2
package is consistent with the goal of streamlining interface definitions. This change ensures that the module's API remains clear and maintainable, with a direct reference to the latest version of these interfaces. It's important for developers to be aware of these aliases to correctly implement the required functionalities in their modules.
I think this is the moment to add changelogs as well to be sure to miss nothing |
added |
There was a problem hiding this 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.yml
Files selected for processing (2)
- core/CHANGELOG.md (1 hunks)
- core/appmodule/module.go (3 hunks)
Files skipped from review as they are similar to previous changes (1)
- core/appmodule/module.go
Additional comments: 2
core/CHANGELOG.md (2)
- 45-53: The changelog entry for PR chore(core): bring changes from serverv2 #19617 is comprehensive and follows the guiding principles outlined at the beginning of the file. However, it's important to ensure that each sub-point under this entry is directly related to the changes made in PR chore(core): bring changes from serverv2 #19617. If any of these sub-points are not part of the PR, they should be removed or adjusted accordingly. Additionally, consider breaking down complex entries into simpler, more digestible points for better readability.
- 55-55: The "API Breaking Changes" section correctly documents changes that could affect users of the SDK. Ensure that each entry in this section is accurate and provides enough detail for developers to understand the impact of the changes. It's also important to verify that all breaking changes introduced in PR chore(core): bring changes from serverv2 #19617 are documented here. If any are missing, they should be added.
There was a problem hiding this 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.yml
Files selected for processing (1)
- core/appmodule/v2/genesis.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
- core/appmodule/v2/genesis.go
There was a problem hiding this 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.yml
Files selected for processing (2)
- core/go.mod (2 hunks)
- core/go.sum (3 hunks)
Additional comments: 6
core/go.mod (3)
- 7-7: Adding
github.com/cosmos/gogoproto v1.4.11
introduces new or updated protobuf definitions. Ensure compatibility with existing protobuf structures and check for necessary migrations or code generation steps.- 16-16: The inclusion of
github.com/google/go-cmp v0.6.0
as an indirect dependency suggests updates to testing utilities. Verify that this version is compatible with existing tests and consider direct usage if comparison utilities are needed in tests.- 24-24:
golang.org/x/exp v0.0.0-20230811145659-89c5cff77bcb
being added as an indirect dependency indicates experimental features might be in use. Ensure that the stability of these features is acceptable for the project's requirements and review their usage for potential risks.core/go.sum (3)
- 4-5: Checksums for
github.com/cosmos/gogoproto v1.4.11
have been added. Verify that these checksums match the expected values for the version specified to ensure the integrity of the dependency.- 15-15: Checksums for
github.com/google/go-cmp v0.6.0
are included. It's important to confirm these checksums align with the expected values for the specified version, safeguarding against corrupted or tampered dependencies.- 42-43: Added checksums for
golang.org/x/exp v0.0.0-20230811145659-89c5cff77bcb
. As this is an indirect dependency, ensure that its inclusion is necessary and that the checksums are accurate, reflecting the correct version and integrity of the module.
// NonConsensusStore is a simple key-value store that is used to store non-consensus data. | ||
// Note the non-consensus data is not committed to the blockchain and does not allow iteration | ||
type NonConsensusStore interface { | ||
// Get returns nil iff key doesn't exist. Errors on nil key. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor nit
// Get returns nil iff key doesn't exist. Errors on nil key. | |
// Get returns nil if key doesn't exist. Errors on nil key. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if and only if, it should work
Description
Closes: #XXXX
This PR adds appmodule v2 and transaction to core to prep the upstream of server/v2 pieces
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!
in the type prefix if API or client breaking changeCHANGELOG.md
Reviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
I have...
Summary by CodeRabbit
Environment
struct declaration.DatabaseService
for storing non-consensus data.