-
Notifications
You must be signed in to change notification settings - Fork 263
Open
Description
Current Behavior
Currently, when a new proposal is created, its staking pool snapshot is only created during periodic operations that run every 5 minutes. This leads to:
- Data delay: Users must wait up to 5 minutes to see the initial snapshot data
- Data accuracy issues: The first snapshot might not reflect the exact staking state at proposal creation
- Poor user experience: Incomplete proposal information immediately after creation
Expected Behavior
Staking pool snapshots should be:
- Created immediately when a new proposal is created
- Continue to be updated every 5 minutes for ongoing monitoring
Technical Details
Current Implementation
// In modules/gov/handle_msg.go
func (m *Module) handleSubmitProposalEvent(tx *juno.Transaction, proposer string, events sdk.StringEvents) error {
// ... proposal creation logic ...
err = m.db.SaveProposals([]types.Proposal{proposalObj})
if err != nil {
return fmt.Errorf("error while saving proposal: %s", err)
}
// No immediate snapshot creation
return m.handleDepositEvent(tx, proposer, events)
}Proposed Implementation
// New optimized function in modules/gov/utils_proposal.go
func (m *Module) UpdateSingleProposalStakingPoolSnapshot(height int64, proposalID uint64) error {
pool, err := m.stakingModule.GetStakingPoolSnapshot(height)
if err != nil {
return fmt.Errorf("error while getting staking pool: %s", err)
}
return m.db.SaveProposalStakingPoolSnapshot(
types.NewProposalStakingPoolSnapshot(proposalID, pool),
)
}
// Modified handleSubmitProposalEvent
func (m *Module) handleSubmitProposalEvent(tx *juno.Transaction, proposer string, events sdk.StringEvents) error {
// ... proposal creation logic ...
err = m.db.SaveProposals([]types.Proposal{proposalObj})
if err != nil {
return fmt.Errorf("error while saving proposal: %s", err)
}
// Create snapshot immediately
err = m.UpdateSingleProposalStakingPoolSnapshot(int64(tx.Height), proposal.Id)
if err != nil {
log.Error().Err(err).
Uint64("proposal_id", proposal.Id).
Uint64("height", tx.Height).
Msg("failed to update staking pool snapshot for new proposal")
}
return m.handleDepositEvent(tx, proposer, events)
}Benefits
- Immediate Data Availability: Users can see complete proposal information right after creation
- Data Accuracy: Snapshot reflects exact staking state at proposal creation time
- Resource Efficiency: Only updates the necessary proposal instead of all proposals
- Better Error Tracking: Proposal-specific error logging
- Maintains Existing Functionality: Keeps periodic updates as a safety net
Implementation Notes
- The change is minimally invasive and follows existing patterns
- Error handling is non-blocking to prevent proposal creation failure
- Maintains backward compatibility
- No database schema changes required
Test result
Metadata
Metadata
Assignees
Labels
No labels