contract

package
v0.0.0-...-bf46863 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 31, 2023 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const LogAfter = 10 * time.Second
View Source
const LogExecSigSendAfter = 2 * time.Second
View Source
const LogRunnerRunAfter = 10 * time.Second

Variables

View Source
var WasmWhitelistedKeys = []string{
	string(wasmtypes.ContractStorePrefix),
}

Functions

func CallPreExecutionHooks

func CallPreExecutionHooks(
	ctx context.Context,
	sdkCtx sdk.Context,
	contractAddr string,
	dexkeeper *keeper.Keeper,
	registeredPairs []types.Pair,
	tracer *otrace.Tracer,
) error

func CancelUnfulfilledMarketOrders

func CancelUnfulfilledMarketOrders(
	ctx context.Context,
	sdkCtx sdk.Context,
	contractAddr string,
	dexkeeper *keeper.Keeper,
	registeredPairs []types.Pair,
	tracer *otrace.Tracer,
) error

func EmitSettlementMetrics

func EmitSettlementMetrics(settlements []*types.SettlementEntry)

Emit metrics for settlements

func EndBlockerAtomic

func EndBlockerAtomic(ctx sdk.Context, keeper *keeper.Keeper, validContractsInfo []types.ContractInfoV2, tracingInfo *tracing.Info) ([]types.ContractInfoV2, []types.ContractInfoV2, map[string]string, sdk.Context, bool)

func ExecutePair

func ExecutePair(
	ctx sdk.Context,
	contractAddr string,
	pair types.Pair,
	dexkeeper *keeper.Keeper,
	orderbook *types.OrderBook,
) []*types.SettlementEntry

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 GetDexMemPerPairWhitelistedPrefixes

func GetDexMemPerPairWhitelistedPrefixes(contractAddr string, pair types.Pair) []string

func GetDexMemWhitelistedPrefixes

func GetDexMemWhitelistedPrefixes(contractAddr string) []string

func GetDexPerPairWhitelistedPrefixes

func GetDexPerPairWhitelistedPrefixes(contractAddr string, pair types.Pair) []string

func GetDexWhitelistedPrefixes

func GetDexWhitelistedPrefixes(contractAddr string) []string

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 GetPerPairWhitelistMap(contractAddr string, pair types.Pair) map[string][]string

func GetWasmWhitelistedPrefixes

func GetWasmWhitelistedPrefixes(contractAddr string) []string

func GetWhitelistMap

func GetWhitelistMap(contractAddr string) map[string][]string

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 HandleSettlements(
	ctx sdk.Context,
	contractAddr string,
	dexkeeper *keeper.Keeper,
	settlements []*types.SettlementEntry,
) error

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

func TransferRentFromDexToCollector

func TransferRentFromDexToCollector(ctx sdk.Context, bankKeeper bankkeeper.Keeper, preRents map[string]uint64, postRents map[string]uint64)

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:

  1. Has not finished running yet, and
  2. 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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL