-
Notifications
You must be signed in to change notification settings - Fork 8
Add remaining state changes #313
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
Conversation
Introduces a new EventsProcessor to handle contract event state changes, specifically indexing 'approve' events as allowance state changes. Updates the Indexer to use this processor and adds corresponding tests and utilities for event processing.
Expanded EventsProcessor tests to cover V4 contract event formats, multiple approve events, and various error scenarios including invalid operation types, invalid contract events, insufficient topics, and non-approve events. Added utility functions to generate these test cases in processors_test_utils.go.
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
Introduces support for processing trustline created, updated, and removed effects in the EffectsProcessor. Adds a new StateChangeCategoryTrustline, implements trustline parsing logic, and provides comprehensive tests for trustline state changes.
Introduces a new state change category (SEQUENCE) and reason (BUMP) to track sequence bump operations. Updates the EffectsProcessor to handle EffectSequenceBumped and adds a corresponding test case to ensure correct processing and categorization.
Updated the EventsProcessor to skip invalid contract events and those with insufficient topics instead of returning errors. Adjusted related tests to expect ignored events rather than errors, ensuring only valid 'approve' events are processed.
Introduces a new trustline_limit JSONB column to the state_changes table and updates the StateChange struct, builder, and effect processors to use the new TrustlineLimit field for trustline-related state changes. Updates tests to validate the new structure.
Replaces StateChangeCategoryTrustlineFlags with StateChangeCategoryAuthorization and updates related logic and tests. Also changes StateChangeReasonClear to StateChangeReasonRemove for trustline flag removals. Cleans up unused category constant.
Replaces StateChangeCategoryAuthorization with StateChangeCategoryBalanceAuthorization for trustline flag effects and updates related tests and type definitions. This clarifies the distinction between general authorization and balance-specific authorization changes.
Introduces an EventsProcessor to handle contract events and convert them into state changes, specifically for balance authorization changes. Enhances EffectsProcessor to generate balance authorization state changes for new trustlines based on issuer account flags, requiring an RPC service dependency. Refactors trustline parsing to support multiple state changes and adds utility methods for flag determination and RPC-based issuer flag retrieval.
Introduces a new interfaces.go file defining the LedgerEntryProvider interface to decouple EffectsProcessor from direct RPC service dependency and avoid import cycles. Updates EffectsProcessor and its tests to use the new interface, modifies NewIndexer and ingest service to inject the provider, and adjusts trustline flag logic for clarity and correctness.
Replaces the realRPCLedgerEntryProvider and direct HTTP calls with a mockLedgerEntryProvider using testify's mock package. This simplifies the test setup, removes network dependencies, and improves test isolation and reliability.
Replaces the generic EventsProcessor with a specialized SACEventsProcessor for handling 'set_authorized' contract events. Refactors the Indexer to support multiple operation processors via an interface with a Name() method. Moves contract event utilities to a dedicated contracts package and updates mocks and related processors accordingly.
Introduces unit tests for the SACEventsProcessor's ProcessOperation method, covering V3 and V4 contract event formats, error cases, and event filtering. Adds test utility functions for constructing various contract event transaction scenarios to support comprehensive testing.
Refactored the Indexer struct to use a processors slice for operation processors, simplifying dependency injection and test setup. Updated SAC contract event tests and test utilities to streamline assertions and remove unused parameters. Minor formatting and comment improvements were also made.
Introduces detailed debug logs to provide context when SAC contract events are skipped during processing. This will help with troubleshooting by logging reasons such as invalid contract structure, topic count, function name, extraction failures, invalid contract IDs, and non-boolean authorization values.
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.
This looks like its almost there but I had some questions we should resolve before merging.
Also, I realized through reviewing this PR that SEP-41 doesn't have the set_authorized event -- I thought it did. This means we can't track authorization status for contract tokens, because the implementation is nonstandard and we wouldn't know how to parse it.
I still think its worth having separate state change categories for trustlines and balance authorizations though, because contract accounts can hold stellar assets, and contract accounts don't have trustlines but can be authorized/deauthorized.
@JakeUrban I agree with you. It was a good idea to remove the trustline flags state change and combine it with balance authorization since that also helps us include the contract events for |
Refactored SACEventsProcessor to separate account extraction and SAC contract validation into distinct methods. Improved logging to include processor name for better traceability. Updated utility functions for extracting addresses and assets from ScVal, and removed the now-unused isSAC function from utils.go.
Updated flag names from 'authorized_flag' and 'clawback_enabled_flag' to 'authorized' and 'clawback_enabled' for consistency across processors and tests. Adjusted related code and tests to use the new flag names.
Replaces StateChangeReasonSet with StateChangeReasonAdd when creating trustline state changes. Updates the corresponding test to reflect this change for consistency and correctness.
The SACEventsProcessor now inspects operation changes to determine previous trustline flag states, ensuring that balance authorization state changes are only generated for flags that actually transition. Added extractTrustlineFlagChanges to extract previous flag states, improving accuracy of authorization event processing. Minor constant formatting update in effects.go.
Expanded SACEventsProcessor tests to cover edge cases for trustline authorization and maintain liabilities flag combinations. Added utility functions to create transactions with specific trustline flag states and to simulate missing trustline changes, improving test coverage and robustness.
Eliminated handling of EffectSequenceBumped in EffectsProcessor and removed the related test case. This streamlines effect processing by excluding sequence bump state changes.
Updated state change reason from StateChangeReasonRemove to StateChangeReasonClear in SAC and Effects processors and their tests for better semantic clarity when clearing authorization flags.
Adds logic to distinguish between classic and contract accounts when processing authorization changes in Stellar Asset Contracts (SAC). For contract accounts, authorization is extracted from contract data changes rather than trustline flags. Also introduces helper functions for contract address detection and contract authorization extraction.
Expanded SACEventsProcessor tests to cover contract account authorization scenarios, including state changes and error handling for invalid contract data. Added utility functions to generate contract addresses, construct contract data changes, and handle various balance map structures for testing.
Updates SACEventsProcessor to ensure trustline and contract data changes are only processed if they match the SAC asset and contract referenced by the event. Adds helper methods to verify asset and contract matches, and introduces new tests to confirm unrelated trustline and contract data changes are ignored.
Added test cases to verify that trustline and contract data changes without previous state are correctly processed and not ignored. Introduced utility functions to create transactions simulating newly created trustlines and contract data entries for more robust test coverage.
Replaces individual test transaction creation functions with a fluent TxBuilder interface for building test transactions in sac_test.go and test_utils.go. This improves maintainability and flexibility of test setup for contract and trustline scenarios.
All references to the TxBuilder type and its methods have been updated to testTxBuilder for consistency and clarity in test utility code. Legacy function implementations now use newTestTxBuilder instead of NewTxBuilder.
What
Balance Authorization
We generate a set of balance authorization state changes in different cases:
SetTrustlineFlagsoperation: When trustline flags are updated, we generate state changes with categoryBALANCE_AUTHORIZATIONand reason beingSET/REMOVEbased on the flags that are set and cleared.set_authorizedcalls: We generate 2 state changes in this caseset_authorized = true: Two changes are generated with categoryBALANCE_AUTHORIZATIONand aSETreason forauthorized_flagandREMOVEreason forauthorized_to_maintain_liabilities.set_authorized = false: Two changes are generated with categoryBALANCE_AUTHORIZATIONand aSETreason forauthorized_to_maintain_liabilitiesandREMOVEreason forauthorized_flag.Change Trustline
Changes to trustlines generate state changes for the account involved. We use the effects processor to build these changes. There are 3 types of changes that are generated:
ADDWe record the account and asset and the trustline limit is added to a new colume
trustline_limitwhich is a key-value JSONB string:Additionally we also generate a
BALANCE_AUTHORIZATIONchange by getting the default trustline flags that the issuer has set.REMOVEWe only record the amount and asset since the limit is 0 when the trustlines are removed.
UPDATEWe record the account and asset and the trustline limit with old and new values::
Why
Wallet backend indexer
Known limitations
N/A
Issue that this PR addresses
#310 #314 #315