Skip to content

Commit

Permalink
Order TTL (#146)
Browse files Browse the repository at this point in the history
* [ci skip] checkpt

* [ci skip] checkpt

* [ci skip] checkpt

* bump

* fix test wait
  • Loading branch information
aastein committed Mar 26, 2018
1 parent 3f62651 commit 236119c
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 108 deletions.
14 changes: 8 additions & 6 deletions app/market/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ func (e engine) processDeployments(state state.State, w txBuffer) error {
return nil
}

// only create leases for orders which are at or past thier EndAt
func (e engine) processDeployment(state state.State, w txBuffer, deployment types.Deployment) error {

nextSeq := state.Deployment().SequenceFor(deployment.Address).Next()
height := state.Version()

// process cancel deployment
if deployment.State == types.Deployment_CLOSED {
Expand All @@ -70,9 +72,6 @@ func (e engine) processDeployment(state state.State, w txBuffer, deployment type
continue
}

// TODO: put ttl on orders
// TODO: cancel stale orders

// process current orders
orders, err := state.Order().ForGroup(group)
if err != nil {
Expand All @@ -88,9 +87,11 @@ func (e engine) processDeployment(state state.State, w txBuffer, deployment type
if !activeFound && order.State == types.Order_OPEN || order.State == types.Order_MATCHED {
activeFound = true
}
err := e.processOrder(state, w, order)
if err != nil {
return err
if order.EndAt <= height {
err := e.processOrder(state, w, order)
if err != nil {
return err
}
}
}

Expand All @@ -102,6 +103,7 @@ func (e engine) processDeployment(state state.State, w txBuffer, deployment type
Group: group.GetSeq(),
Order: nextSeq,
State: types.Order_OPEN,
EndAt: group.OrderTTL + height,
},
})
nextSeq++
Expand Down
11 changes: 5 additions & 6 deletions app/order/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (a *app) AcceptTx(ctx apptypes.Context, tx interface{}) bool {
func (a *app) CheckTx(ctx apptypes.Context, tx interface{}) tmtypes.ResponseCheckTx {
switch tx := tx.(type) {
case *types.TxPayload_TxCreateOrder:
return a.doCheckTx(ctx, tx.TxCreateOrder)
return a.doCheckCreateTx(ctx, tx.TxCreateOrder)
}
return tmtypes.ResponseCheckTx{
Code: code.UNKNOWN_TRANSACTION,
Expand All @@ -53,7 +53,7 @@ func (a *app) CheckTx(ctx apptypes.Context, tx interface{}) tmtypes.ResponseChec
func (a *app) DeliverTx(ctx apptypes.Context, tx interface{}) tmtypes.ResponseDeliverTx {
switch tx := tx.(type) {
case *types.TxPayload_TxCreateOrder:
return a.doDeliverTx(ctx, tx.TxCreateOrder)
return a.doDeliverCreateTx(ctx, tx.TxCreateOrder)
}
return tmtypes.ResponseDeliverTx{
Code: code.UNKNOWN_TRANSACTION,
Expand Down Expand Up @@ -145,8 +145,7 @@ func (a *app) doRangeQuery(key base.Bytes) tmtypes.ResponseQuery {
}
}

// todo: break each type of check out into a named global exported funtion for all trasaction types to utilize
func (a *app) doCheckTx(ctx apptypes.Context, tx *types.TxCreateOrder) tmtypes.ResponseCheckTx {
func (a *app) doCheckCreateTx(ctx apptypes.Context, tx *types.TxCreateOrder) tmtypes.ResponseCheckTx {

// todo: ensure signed by last block creator / valid market facilitator

Expand Down Expand Up @@ -218,9 +217,9 @@ func (a *app) doCheckTx(ctx apptypes.Context, tx *types.TxCreateOrder) tmtypes.R
return tmtypes.ResponseCheckTx{}
}

func (a *app) doDeliverTx(ctx apptypes.Context, tx *types.TxCreateOrder) tmtypes.ResponseDeliverTx {
func (a *app) doDeliverCreateTx(ctx apptypes.Context, tx *types.TxCreateOrder) tmtypes.ResponseDeliverTx {

cresp := a.doCheckTx(ctx, tx)
cresp := a.doCheckCreateTx(ctx, tx)
if !cresp.IsOK() {
return tmtypes.ResponseDeliverTx{
Code: cresp.Code,
Expand Down
3 changes: 2 additions & 1 deletion testutil/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func Deployment(tenant base.Bytes, nonce uint64) *types.Deployment {
}

func DeploymentGroups(deployment base.Bytes, nonce uint64) *types.DeploymentGroups {

orderTTL := int64(5)
nonce++

runit := types.ResourceUnit{
Expand All @@ -132,6 +132,7 @@ func DeploymentGroups(deployment base.Bytes, nonce uint64) *types.DeploymentGrou
Seq: nonce,
Resources: []types.ResourceGroup{rgroup},
Requirements: []types.ProviderAttribute{pattr},
OrderTTL: orderTTL,
}

groups := []types.DeploymentGroup{*group}
Expand Down
2 changes: 1 addition & 1 deletion testutil/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

const (
defaultDelayThreadStart = time.Millisecond * 2
defaultDelayThreadStart = time.Millisecond * 5
)

func SleepForThreadStart(t *testing.T) {
Expand Down
Loading

0 comments on commit 236119c

Please sign in to comment.