Handling IBC Acknowledgments in Smart Contracts
When developing contracts that use IBC functionality on Neutron, you need to properly handle acknowledgments:Best Practices
- Keep Sudo Handlers Light: Due to gas limitations, sudo handlers should only store data without complex processing
- Separate Processing Logic: Use separate execute messages to process the stored data
- Handle All Message Types: Implement handlers for all expected sudo message types
- Prepare for Resubmission: Design your contract to handle potential resubmission of messages
Checking for Contract Failures
To check if your contract has experienced any failures, you can use the Contract Manager query functionality:Using CLI
Via CosmWasm Contract
You can query failures from within another contract using bindings:Getting Detailed Failure Information
For more detailed error information (beyond the redacted error in state):Resubmitting Failed Operations
If your contract experiences a failure due to gas limits or other temporary issues, you can resubmit the operation:Using CosmWasm Bindings
- Only the original contract that received the IBC message can resubmit the failure
- Resubmission runs with full gas, not limited by the usual sudo gas constraints
- You should fix any issues in your contract before resubmitting
Implementing Error Handling Patterns
Here’s a pattern for robust IBC acknowledgment handling:Monitoring Contract Failures
For production applications, implement a monitoring system that:- Regularly queries the Contract Manager for failures related to your contracts
- Alerts operators about new failures
- Provides tooling to diagnose and resubmit failures when appropriate
Testing Contract Manager Integration
When testing contracts that interact with IBC:- Test how your contract handles out-of-gas scenarios
- Verify that resubmission logic works correctly
- Ensure error states are properly captured and can be recovered from