-
Notifications
You must be signed in to change notification settings - Fork 254
feat: Pause deployments when overdrawn #2013
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
base: main
Are you sure you want to change the base?
Changes from all commits
495dcbd
db753c8
48d48a2
0af2f9e
901f946
aed5aa4
797e3af
1cfb2f9
a84e13b
0239d36
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -311,9 +311,15 @@ func (k Keeper) OnPauseGroup(ctx sdk.Context, group types.Group) error { | |
| store.Delete(key) | ||
|
|
||
| group.State = types.GroupPaused | ||
|
|
||
| key, err := GroupKey(GroupStateToPrefix(group.State), group.ID) | ||
| if err != nil { | ||
| return fmt.Errorf("%s: failed to encode group key", err) | ||
| } | ||
|
|
||
|
Comment on lines
+314
to
+319
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking at It does look like findGroup was checking all possible variants of a key when looking for a group, so it probably could have been found anyways, but this should still be a more accurate state/key for the Group |
||
| store.Set(key, k.cdc.MustMarshal(&group)) | ||
|
|
||
| err := ctx.EventManager().EmitTypedEvent( | ||
| err = ctx.EventManager().EmitTypedEvent( | ||
| &v1.EventGroupPaused{ | ||
| ID: group.ID, | ||
| }, | ||
|
|
@@ -322,7 +328,6 @@ func (k Keeper) OnPauseGroup(ctx sdk.Context, group types.Group) error { | |
| return err | ||
| } | ||
|
|
||
| store.Set(key, k.cdc.MustMarshal(&group)) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was already called a few lines above |
||
| return nil | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ import ( | |
|
|
||
| type Hooks interface { | ||
| OnEscrowAccountClosed(ctx sdk.Context, obj etypes.Account) | ||
| OnEscrowAccountPaused(ctx sdk.Context, obj etypes.Account) | ||
| OnEscrowPaymentClosed(ctx sdk.Context, obj etypes.Payment) | ||
| } | ||
|
|
||
|
|
@@ -56,6 +57,29 @@ func (h *hooks) OnEscrowAccountClosed(ctx sdk.Context, obj etypes.Account) { | |
| } | ||
| } | ||
|
|
||
| func (h *hooks) OnEscrowAccountPaused(ctx sdk.Context, obj etypes.Account) { | ||
| id, err := dv1.DeploymentIDFromEscrowID(obj.ID) | ||
| if err != nil { | ||
| return | ||
| } | ||
|
|
||
| deployment, found := h.dkeeper.GetDeployment(ctx, id) | ||
| if !found { | ||
| return | ||
| } | ||
|
|
||
| if deployment.State != dv1.DeploymentActive { | ||
| return | ||
| } | ||
|
|
||
| for _, group := range h.dkeeper.GetGroups(ctx, deployment.ID) { | ||
| if group.ValidatePausable() == nil { | ||
| _ = h.dkeeper.OnPauseGroup(ctx, group) | ||
| _ = h.mkeeper.OnGroupClosed(ctx, group.ID) | ||
| } | ||
| } | ||
| } | ||
|
Comment on lines
+60
to
+81
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainVerify Line 78 calls If pausing should preserve market state for resumption, consider whether a different market keeper method (e.g., 🏁 Script executed: #!/bin/bash
# Verify OnGroupClosed behavior and check if OnGroupPaused exists
# Check if OnGroupPaused method exists in MarketKeeper interface
ast-grep --pattern $'OnGroupPaused($$$) $$$'
# Check OnGroupClosed implementation to understand what it does
ast-grep --pattern $'func ($$$) OnGroupClosed(ctx $_, id $_) error {
$$$
}'Length of output: 2724 Length of output: 0 🏁 Script executed: #!/bin/bash
# Investigate deployment pause semantics more directly
# Check deployment state enum values
rg "DeploymentPaused|DeploymentClosed|type.*State" -B 2 -A 2 --type go | head -50
# Look at OnEscrowAccountPaused implementation to understand pattern
rg -A 20 "func.*OnEscrowAccountPaused" --type go
# Check if paused deployments have any restrictions or special handling
rg "State.*Paused\|Paused.*State" -C 3 --type goLength of output: 4967 🏁 Script executed: #!/bin/bash
# Find OnPauseGroup implementation and examine the test
# Search for OnPauseGroup method
rg -A 15 "func.*OnPauseGroup" --type go
# Get the full test case to understand intended behavior
rg -A 50 "func Test_OnEscrowAccountPaused_overdrawn" --type goLength of output: 4348 🏁 Script executed: #!/bin/bash
# Check if paused groups/deployments can resume or transition back to active state
# Search for transitions FROM GroupPaused or DeploymentPaused to active states
rg "GroupPaused|DeploymentPaused" -B 3 -A 3 --type go | grep -A 3 -B 3 "GroupOpen\|DeploymentActive\|Active\|resume"
# Check if there's any method that resumes or unpauses a group
rg "GroupOpen" --type go | grep -i "paused\|resume"
# Look for state transition logic
rg "group.State\s*=" -B 2 -A 2 --type go | head -80Length of output: 1930 🏁 Script executed: #!/bin/bash
# Find the method that transitions group.State to GroupOpen
# Search for methods containing the state transition to GroupOpen
rg -B 30 "group.State = types.GroupOpen" --type go | grep -A 30 "^x/deployment"Length of output: 1551 Correct the hook to not close market resources on pause—groups can be resumed. The review comment is valid. OnPauseGroup transitions the group state to GroupPaused, and there exists an However, OnGroupClosed permanently closes orders, bids, and leases. Calling The line 78 call to 🤖 Prompt for AI Agents
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. May be useful to get some feedback here from someone more familiar with desired state. I was initially under the impression that on re-funding and resuming, new orders, etc would have to be created, though maybe this is not actually the case and was a misunderstanding on my side There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: Length of output: 4237 🏁 Script executed: Length of output: 4934 🏁 Script executed: Length of output: 1282 🏁 Script executed: Length of output: 2716 @cmmarslender Your initial understanding was actually correct! Based on the code investigation, here's what happens: Current Design Pattern:
So the current implementation in this PR is consistent with that pattern—calling
My initial review concern was incorrect. The code is working as designed. Calling If this is the intended behavior for handling overdrawn accounts, the current implementation is correct. 👍 🧬 Code Graph Analysis Results
|
||
|
|
||
| func (h *hooks) OnEscrowPaymentClosed(ctx sdk.Context, obj etypes.Payment) { | ||
| id, err := mv1.LeaseIDFromPaymentID(obj.ID) | ||
| if err != nil { | ||
|
|
||
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.
Format the changelog entry per guidelines.
The changelog entry should follow the format specified in lines 15-19:
* (<tag>) \#<issue-number> message. It should also be placed under an appropriate stanza (e.g., "Features" or "Improvements") rather than directly under[Unreleased].Apply this diff to fix the formatting:
🤖 Prompt for AI Agents