Skip to content

Commit

Permalink
Merge pull request #516 from binance-chain/ioc_no_fill
Browse files Browse the repository at this point in the history
[R4R] IocNoFill semantic correct
  • Loading branch information
ackratos authored Apr 1, 2019
2 parents e4553bd + e498a86 commit 192ee3c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 18 deletions.
20 changes: 12 additions & 8 deletions app/pub/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,15 @@ func MatchAndAllocateAllForPublish(

tradesToPublish := make([]*Trade, 0)
go collectTradeForPublish(&tradesToPublish, &wg, ctx.BlockHeader().Height, tradeHolderCh)
go updateExpireFeeForPublish(dexKeeper, &wg, iocExpireFeeHolderCh, orderPkg.IocNoFill)
go updateExpireFeeForPublish(dexKeeper, &wg, iocExpireFeeHolderCh)
var feeCollectorForTrades = func(tran orderPkg.Transfer) {
if tran.IsExpire() {
iocExpireFeeHolderCh <- orderPkg.ExpireHolder{tran.Oid}
if tran.IsExpiredWithFee() {
// we only got expire of Ioc here, gte orders expire is handled in breathe block
iocExpireFeeHolderCh <- orderPkg.ExpireHolder{tran.Oid, orderPkg.IocNoFill}
} else {
iocExpireFeeHolderCh <- orderPkg.ExpireHolder{tran.Oid, orderPkg.IocExpire}
}
} else {
tradeHolderCh <- orderPkg.TradeHolder{tran.Oid, tran.Trade, tran.Symbol}
}
Expand All @@ -158,10 +163,10 @@ func ExpireOrdersForPublish(
expireHolderCh := make(chan orderPkg.ExpireHolder, TransferCollectionChannelSize)
wg := sync.WaitGroup{}
wg.Add(1)
go updateExpireFeeForPublish(dexKeeper, &wg, expireHolderCh, orderPkg.Expired)
go updateExpireFeeForPublish(dexKeeper, &wg, expireHolderCh)
var collectorForExpires = func(tran orderPkg.Transfer) {
if tran.IsExpire() {
expireHolderCh <- orderPkg.ExpireHolder{tran.Oid}
expireHolderCh <- orderPkg.ExpireHolder{tran.Oid, orderPkg.Expired}
}
}
dexKeeper.ExpireOrders(ctx, blockTime, collectorForExpires)
Expand Down Expand Up @@ -213,12 +218,11 @@ func CollectProposalsForPublish(passed, failed []int64) Proposals {
func updateExpireFeeForPublish(
dexKeeper *orderPkg.Keeper,
wg *sync.WaitGroup,
tranHolderCh <-chan orderPkg.ExpireHolder,
reason orderPkg.ChangeType) {
tranHolderCh <-chan orderPkg.ExpireHolder) {
defer wg.Done()
for tranHolder := range tranHolderCh {
Logger.Debug("transfer collector for order", "orderId", tranHolder.OrderId)
change := orderPkg.OrderChange{tranHolder.OrderId, reason, nil}
change := orderPkg.OrderChange{tranHolder.OrderId, tranHolder.Reason, nil}
dexKeeper.OrderChanges = append(dexKeeper.OrderChanges, change)
}
}
Expand Down Expand Up @@ -393,7 +397,7 @@ func collectOrdersToPublish(
fee := raw.SerializeForPub(numOfChargedCanceled, numOfExpiredCanceled)
feeToPublish[senderBytesStr] = fee
order.Fee = fee
} else {
} else if numOfChargedCanceled > 0 || numOfExpiredCanceled > 0 {
Logger.Error("cannot find fee for cancel/expire", "sender", order.Owner)
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/pub/keeper_pub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func Test_IOCPartialExpire(t *testing.T) {

orderChange2 := keeper.OrderChanges[2]
assert.Equal("b-1", orderChange2.Id)
assert.Equal(orderPkg.IocNoFill, orderChange2.Tpe)
assert.Equal(orderPkg.IocExpire, orderChange2.Tpe)

assert.Equal("BNB:50000", keeper.RoundOrderFees[string(buyer.Bytes())].String())
assert.Equal("BNB:50000", keeper.RoundOrderFees[string(seller.Bytes())].String())
Expand Down
2 changes: 1 addition & 1 deletion app/pub/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func (msg *Order) effectQtyToOrderBook() int64 {
return msg.Qty
case orderPkg.FullyFill, orderPkg.PartialFill:
return -msg.LastExecutedQty
case orderPkg.Expired, orderPkg.IocNoFill, orderPkg.Canceled, orderPkg.FailedMatching:
case orderPkg.Expired, orderPkg.IocExpire, orderPkg.IocNoFill, orderPkg.Canceled, orderPkg.FailedMatching:
return msg.CumQty - msg.Qty // deliberated be negative value
case orderPkg.FailedBlocking:
return 0
Expand Down
20 changes: 12 additions & 8 deletions plugins/dex/order/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ import (
type ChangeType uint8

const (
Ack ChangeType = iota
Canceled
Expired
IocNoFill
PartialFill
FullyFill
FailedBlocking
FailedMatching
Ack ChangeType = iota // new order tx
Canceled // cancel order tx
Expired // expired for gte order
IocNoFill // ioc order is not filled expire
IocExpire // ioc order is partial filled expire
PartialFill // order is partial filled, derived from trade
FullyFill // order is fully filled, derived from trade
FailedBlocking // order tx is failed blocking, we only publish essential message
FailedMatching // order failed matching
)

// True for should not remove order in these status from OrderInfoForPub
Expand All @@ -41,6 +42,8 @@ func (tpe ChangeType) String() string {
return "Expired"
case IocNoFill:
return "IocNoFill"
case IocExpire:
return "IocExpire"
case PartialFill:
return "PartialFill"
case FullyFill:
Expand Down Expand Up @@ -126,6 +129,7 @@ func (fh TradeHolder) String() string {

type ExpireHolder struct {
OrderId string
Reason ChangeType
}

type FeeHolder map[string]*types.Fee

0 comments on commit 192ee3c

Please sign in to comment.