bitshares / bitshares/bitshares-core
Order fill events notified before order creation events
- Dominant language
- C++
- Stars
- 1.2k
- Forks
- 660
- Avg merge
- 8h 17m
- Merged PRs (30d)
- 26
Description
**Bug Description**
> the market subscription thread seems to be guaranteed to fire before the transaction callback thread, which doesn't make sense for clients because it implies that the market order went through before it actually did.
A client that subscribed to a market always receives order fill events before order creation events if the orders are partially filled in a same block. Note: no notification on order creation if it gets completely filled in same block (not sure if it need to be fixed so far).
There is a `FIXME` in code: https://github.com/bitshares/bitshares-core/blob/d94cc574b2ca460dd636e573f25f0c7737b4a355/libraries/app/database_api.cpp#L2311-L2313
Probably because `on_applied_block()` is called before `on_objects_changed()`: https://github.com/bitshares/bitshares-core/blob/d94cc574b2ca460dd636e573f25f0c7737b4a355/libraries/chain/db_block.cpp#L540-L544
**Expected Behavior**
When a new order is placed, clients receive an order creation event first, then an order fill event.
**Additional Context (optional)**
I'm not sure if it's safe to simply move `on_objects_changed()` to be called before `on_applied_block()`.
**Impacts**
Describe which portion(s) of BitShares Core may be impacted by this bug. Please tick at least one box.
- [x] API (the application programming interface)
- [ ] Build (the build process or something prior to compiled code)
- [ ] CLI (the command line wallet)
- [ ] Deployment (the deployment process after building such as Docker, Travis, etc.)
- [ ] DEX (the Decentralized EXchange, market engine, etc.)
- [ ] P2P (the peer-to-peer network for transaction/block propagation)
- [ ] Performance (system or user efficiency, etc.)
- [ ] Protocol (the blockchain logic, consensus, validation, etc.)
- [ ] Security (the security of system or user data, etc.)
- [ ] UX (the User Experience)
- [ ] Other (please add below)
## CORE TEAM TASK LIST
- [ ] Evaluate / Prioritize Bug Report
- [ ] Refine User Stories / Requirements
- [ ] Define Test Cases
- [ ] Design / Develop Solution
- [ ] Perform QA/Testing
- [ ] Update Documentation
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the FIXME in libraries/app/database_api.cpp around lines 2311-2313, then inspect the on_applied_block() and on_objects_changed() call sites in libraries/chain/db_block.cpp around lines 540-544. Reproduce a partially filled market order in one block and trace notification order. Done means clients receive the order creation event before the order fill event, with same-block complete fills also addressed or explicitly clarified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- api, blockchain
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100