-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Duplicate validation checking for ProcessProposerMatchesEvents (#708)
* minor fix * dont need liquidation check * basic validation ppme * fixes to tests * Fix tests again * pr comments * lint
- Loading branch information
1 parent
1089ad2
commit da31d6e
Showing
5 changed files
with
90 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package types | ||
|
||
import ( | ||
"fmt" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/dydxprotocol/v4-chain/protocol/lib" | ||
) | ||
|
||
// ValidateProcessProposerMatchesEvents performs basic stateless validation on ProcessProposerMatchesEvents. | ||
// It returns an error if: | ||
// - Block height does not equal current block height. | ||
// - Any of the fields have duplicate OrderIds. Note that this is currently invalid since | ||
// stateful order replacements are not enabled. | ||
func (ppme *ProcessProposerMatchesEvents) ValidateProcessProposerMatchesEvents( | ||
ctx sdk.Context, | ||
) error { | ||
if ctx.BlockHeight() != int64(ppme.BlockHeight) { | ||
return fmt.Errorf( | ||
"block height %d for ProcessProposerMatchesEvents does not equal current block height %d", | ||
ppme.BlockHeight, | ||
ctx.BlockHeight(), | ||
) | ||
} | ||
|
||
if lib.ContainsDuplicates(ppme.PlacedLongTermOrderIds) { | ||
return fmt.Errorf( | ||
"ProcessProposerMatchesEvents contains duplicate PlacedLongTermOrderIds: %+v", | ||
ppme.PlacedLongTermOrderIds, | ||
) | ||
} | ||
if lib.ContainsDuplicates(ppme.ExpiredStatefulOrderIds) { | ||
return fmt.Errorf( | ||
"ProcessProposerMatchesEvents contains duplicate ExpiredStatefulOrderIds: %+v", | ||
ppme.ExpiredStatefulOrderIds, | ||
) | ||
} | ||
if lib.ContainsDuplicates(ppme.OrderIdsFilledInLastBlock) { | ||
return fmt.Errorf( | ||
"ProcessProposerMatchesEvents contains duplicate OrderIdsFilledInLastBlock: %+v", | ||
ppme.OrderIdsFilledInLastBlock, | ||
) | ||
} | ||
if lib.ContainsDuplicates(ppme.PlacedStatefulCancellationOrderIds) { | ||
return fmt.Errorf( | ||
"ProcessProposerMatchesEvents contains duplicate PlacedStatefulCancellationOrderIds: %+v", | ||
ppme.PlacedStatefulCancellationOrderIds, | ||
) | ||
} | ||
if lib.ContainsDuplicates(ppme.RemovedStatefulOrderIds) { | ||
return fmt.Errorf( | ||
"ProcessProposerMatchesEvents contains duplicate RemovedStatefulOrderIds: %+v", | ||
ppme.RemovedStatefulOrderIds, | ||
) | ||
} | ||
if lib.ContainsDuplicates(ppme.ConditionalOrderIdsTriggeredInLastBlock) { | ||
return fmt.Errorf( | ||
"ProcessProposerMatchesEvents contains duplicate ConditionalOrderIdsTriggeredInLastBlock: %+v", | ||
ppme.ConditionalOrderIdsTriggeredInLastBlock, | ||
) | ||
} | ||
if lib.ContainsDuplicates(ppme.PlacedConditionalOrderIds) { | ||
return fmt.Errorf( | ||
"ProcessProposerMatchesEvents contains duplicate PlacedConditionalOrderIds: %+v", | ||
ppme.PlacedConditionalOrderIds, | ||
) | ||
} | ||
return nil | ||
} |