Skip to content
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

Do not make Sudo call if parameters are empty #646

Merged
merged 5 commits into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions x/dex/contract/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ func handleFinalizedBlocks(ctx context.Context, sdkCtx sdk.Context, env *environ
if !contractsNeedHook.Contains(contractAddr) {
return true
}
if len(finalizeBlockMsg.FinalizeBlock.Results) == 0 {
return true
}
if _, err := dexkeeperutils.CallContractSudo(sdkCtx, keeper, contractAddr, finalizeBlockMsg, dexutils.ZeroUserProvidedGas); err != nil {
sdkCtx.Logger().Error(fmt.Sprintf("Error calling FinalizeBlock of %s", contractAddr))
env.failedContractAddresses.Add(contractAddr)
Expand Down
2 changes: 1 addition & 1 deletion x/dex/contract/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func HandleExecutionForContract(
tracer *otrace.Tracer,
) (map[string]dextypeswasm.ContractOrderResult, []*types.SettlementEntry, error) {
executionStart := time.Now()
defer telemetry.ModuleSetGauge(types.ModuleName, float32(time.Since(executionStart).Milliseconds()), "handle_execution_for_contract_ms")
defer telemetry.ModuleMeasureSince(types.ModuleName, executionStart, "handle_execution_for_contract_ms")
contractAddr := contract.ContractAddr
typedContractAddr := dextypesutils.ContractAddress(contractAddr)
orderResults := map[string]dextypeswasm.ContractOrderResult{}
Expand Down
3 changes: 3 additions & 0 deletions x/dex/contract/settlement.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ func callSettlementHook(
dexkeeper *keeper.Keeper,
settlementEntries []*types.SettlementEntry,
) error {
if len(settlementEntries) == 0 {
return nil
}
_, currentEpoch := dexkeeper.IsNewEpoch(ctx)
nativeSettlementMsg := dextypeswasm.SudoSettlementMsg{
Settlement: types.Settlements{
Expand Down
3 changes: 3 additions & 0 deletions x/dex/keeper/abci/end_block_cancel_orders.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ func (w KeeperWrapper) HandleEBCancelOrders(ctx context.Context, sdkCtx sdk.Cont

typedContractAddr := typesutils.ContractAddress(contractAddr)
msg := w.getCancelSudoMsg(sdkCtx, typedContractAddr, registeredPairs)
if len(msg.OrderCancellations.IdsToCancel) == 0 {
return nil
}
userProvidedGas := w.GetParams(sdkCtx).DefaultGasPerCancel * uint64(len(msg.OrderCancellations.IdsToCancel))
if _, err := utils.CallContractSudo(sdkCtx, w.Keeper, contractAddr, msg, userProvidedGas); err != nil {
sdkCtx.Logger().Error(fmt.Sprintf("Error during cancellation: %s", err.Error()))
Expand Down
3 changes: 3 additions & 0 deletions x/dex/keeper/abci/end_block_deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ func (w KeeperWrapper) HandleEBDeposit(ctx context.Context, sdkCtx sdk.Context,

typedContractAddr := typesutils.ContractAddress(contractAddr)
msg := w.GetDepositSudoMsg(sdkCtx, typedContractAddr)
if msg.IsEmpty() {
return nil
}
_, err := utils.CallContractSudo(sdkCtx, w.Keeper, contractAddr, msg, dexutils.ZeroUserProvidedGas) // deposit
if err != nil {
sdkCtx.Logger().Error(fmt.Sprintf("Error during deposit: %s", err.Error()))
Expand Down
3 changes: 3 additions & 0 deletions x/dex/keeper/abci/end_block_place_orders.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ func (w KeeperWrapper) HandleEBPlaceOrders(ctx context.Context, sdkCtx sdk.Conte
responses := []wasm.SudoOrderPlacementResponse{}

for _, msg := range msgs {
if msg.IsEmpty() {
continue
}
userProvidedGas := w.GetParams(sdkCtx).DefaultGasPerOrder * uint64(len(msg.OrderPlacements.Orders))
data, err := utils.CallContractSudo(sdkCtx, w.Keeper, contractAddr, msg, userProvidedGas)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions x/dex/types/wasm/order_placement.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ type OrderPlacementMsgDetails struct {
Deposits []types.ContractDepositInfo `json:"deposits"`
}

func (m *SudoOrderPlacementMsg) IsEmpty() bool {
return len(m.OrderPlacements.Deposits) == 0 && len(m.OrderPlacements.Orders) == 0
}

type SudoOrderPlacementResponse struct {
UnsuccessfulOrders []UnsuccessfulOrder `json:"unsuccessful_orders"`
}
Expand Down