Documentation ¶
Index ¶
- Constants
- Variables
- func CallPreExecutionHooks(ctx context.Context, sdkCtx sdk.Context, contractAddr string, ...) error
- func CancelUnfulfilledMarketOrders(ctx context.Context, sdkCtx sdk.Context, contractAddr string, ...) error
- func EmitSettlementMetrics(settlements []*types.SettlementEntry)
- func EndBlockerAtomic(ctx sdk.Context, keeper *keeper.Keeper, ...) ([]types.ContractInfoV2, []types.ContractInfoV2, map[string]string, sdk.Context, ...)
- func ExecutePair(ctx sdk.Context, contractAddr string, pair types.Pair, ...) []*types.SettlementEntry
- func ExecutePairsInParallel(ctx sdk.Context, contractAddr string, dexkeeper *keeper.Keeper, ...) []*types.SettlementEntry
- func GetDexMemPerPairWhitelistedPrefixes(contractAddr string, pair types.Pair) []string
- func GetDexMemWhitelistedPrefixes(contractAddr string) []string
- func GetDexPerPairWhitelistedPrefixes(contractAddr string, pair types.Pair) []string
- func GetDexWhitelistedPrefixes(contractAddr string) []string
- func GetMatchResults(ctx sdk.Context, typedContractAddr types.ContractAddress, ...) ([]*types.Order, []*types.Cancellation)
- func GetOrderIDToSettledQuantities(settlements []*types.SettlementEntry) map[uint64]sdk.Dec
- func GetPerPairWhitelistMap(contractAddr string, pair types.Pair) map[string][]string
- func GetWasmWhitelistedPrefixes(contractAddr string) []string
- func GetWhitelistMap(contractAddr string) map[string][]string
- func HandleExecutionForContract(ctx context.Context, sdkCtx sdk.Context, contract types.ContractInfoV2, ...) ([]*types.SettlementEntry, error)
- func HandleSettlements(ctx sdk.Context, contractAddr string, dexkeeper *keeper.Keeper, ...) error
- func PrepareCancelUnfulfilledMarketOrders(ctx sdk.Context, typedContractAddr types.ContractAddress, ...)
- func TopologicalSortContractInfo(contracts []types.ContractInfoV2) ([]types.ContractInfoV2, error)
- func TransferRentFromDexToCollector(ctx sdk.Context, bankKeeper bankkeeper.Keeper, preRents map[string]uint64, ...)
- type ParallelRunner
Constants ¶
const LogAfter = 10 * time.Second
const LogExecSigSendAfter = 2 * time.Second
const LogRunnerRunAfter = 10 * time.Second
Variables ¶
var DexMemWhitelistedKeys = []string{ types.MemOrderKey, types.MemDepositKey, types.MemCancelKey, }
var DexWhitelistedKeys = []string{ types.LongBookKey, types.ShortBookKey, types.OrderKey, types.AccountActiveOrdersKey, types.CancelKey, types.TwapKey, types.PriceKey, types.SettlementEntryKey, types.NextOrderIDKey, types.MatchResultKey, types.LongOrderCountKey, types.ShortOrderCountKey, keeper.ContractPrefixKey, }
var WasmWhitelistedKeys = []string{ string(wasmtypes.ContractStorePrefix), }
Functions ¶
func CallPreExecutionHooks ¶
func EmitSettlementMetrics ¶
func EmitSettlementMetrics(settlements []*types.SettlementEntry)
Emit metrics for settlements
func EndBlockerAtomic ¶
func ExecutePair ¶
func ExecutePairsInParallel ¶
func ExecutePairsInParallel(ctx sdk.Context, contractAddr string, dexkeeper *keeper.Keeper, registeredPairs []types.Pair, orderBooks *datastructures.TypedSyncMap[types.PairString, *types.OrderBook]) []*types.SettlementEntry
func GetMatchResults ¶
func GetMatchResults( ctx sdk.Context, typedContractAddr types.ContractAddress, typedPairStr types.PairString, ) ([]*types.Order, []*types.Cancellation)
func GetOrderIDToSettledQuantities ¶
func GetOrderIDToSettledQuantities(settlements []*types.SettlementEntry) map[uint64]sdk.Dec
func GetPerPairWhitelistMap ¶
func GetWhitelistMap ¶
func HandleExecutionForContract ¶
func HandleExecutionForContract( ctx context.Context, sdkCtx sdk.Context, contract types.ContractInfoV2, dexkeeper *keeper.Keeper, registeredPairs []types.Pair, orderBooks *datastructures.TypedSyncMap[types.PairString, *types.OrderBook], tracer *otrace.Tracer, ) ([]*types.SettlementEntry, error)
func HandleSettlements ¶
func PrepareCancelUnfulfilledMarketOrders ¶
func PrepareCancelUnfulfilledMarketOrders( ctx sdk.Context, typedContractAddr types.ContractAddress, typedPairStr types.PairString, orderIDToSettledQuantities map[uint64]sdk.Dec, )
func TopologicalSortContractInfo ¶
func TopologicalSortContractInfo(contracts []types.ContractInfoV2) ([]types.ContractInfoV2, error)
Kahn's algorithm
Types ¶
type ParallelRunner ¶
type ParallelRunner struct {
// contains filtered or unexported fields
}
func NewParallelRunner ¶
func NewParallelRunner(runnable func(contract types.ContractInfoV2), contracts []types.ContractInfoV2, ctx sdk.Context) ParallelRunner
func (*ParallelRunner) Run ¶
func (r *ParallelRunner) Run()
We define "frontier contract" as a contract which:
- Has not finished running yet, and
- either: a. has no other contracts depending on it, or b. for which all contracts that depend on it have already finished.
Consequently, the set of frontier contracts will mutate throughout the `Run` method, until all contracts finish their runs. The key principle here is that at any moment, we can have all frontier contracts running concurrently, since there must be no ancestral relationships among them due to the definition above. The simplest implementation would be: ``` while there is any contract left:
run all frontier contracts concurrently wait for all runs to finish update the frontier set
``` We can illustrate why this implementation is not optimal with the following example:
Suppose we have four contracts, where A depends on B, and C depends on D. The run for A, B, C, D takes 5s, 5s, 8s, 2s, respectively. With the implementation above, the first iteration would take 8s since it runs A and C, and the second iteration would take 5s since it runs B and D. However C doesn't actually need to wait for B to finish, and if C runs immediately after A finishes, the whole process would take max(5 + 5, 8 + 2) = 10s, which is 3s faster than the implementation above.
So we can optimize the implementation to be: ``` while there is any contract left:
run all frontier contracts concurrently wait for any existing run (could be from previous iteration) to finish update the frontier set
``` With the example above, the whole process would take 3 iterations: Iter 1 (A, C run): 5s since it finishes when A finishes Iter 2 (B run): 3s since it finishes when C finishes Iter 3 (D run): 2s since it finishes when B, D finish
The following `Run` method implements the pseudocode above.