Skip to content

Commit 52f4dde

Browse files
committed
Preserve complete mirror context and earlier standalone ABI controls
1 parent 5a2fc4b commit 52f4dde

8 files changed

Lines changed: 50 additions & 15 deletions

‎docs/pages/fill-model.md‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ admission and scheduling rules, and the ordinary bar scan and callback-driven
1111
scan are separate. The responsibilities below guide their consolidation without
1212
claiming that a single unified scheduler already exists.
1313

14-
The current pending-order representation has six direct boolean members. Two
15-
duplicate placement fields now derive from the original command observation,
16-
and cancellation has an explicit terminal receipt. This declaration count is
14+
The current pending-order representation has five direct boolean members. Two
15+
duplicate placement fields derive from the original command observation;
16+
the opposite-market predecessor fact derives from its accepted command's
17+
original book and removal records. The book records each instruction's raw
18+
buy/sell direction, including manually constructed peers, without storing the
19+
derived predecessor result. Cancellation has an explicit terminal receipt. This declaration count is
1720
an intermediate result: it does not prove that all remaining Pine predicates
1821
are generic, or that the whole engine has fewer than five compatibility choices.
1922

‎include/pineforge/engine.hpp‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242
#include <pineforge/pineforge.h>
4343

4444
// The public C mirror needs the engine's admission journal to derive
45-
// source-bound placement facts. The one-argument form remains for manually
46-
// constructed, unbound native orders only.
45+
// source-bound placement facts. The context-free form refuses a bound priced
46+
// entry whose original history is needed; other orders have no predecessor.
4747
namespace pineforge {
4848
void fill_pending_order_mirror(const PendingOrder&,
4949
const MarketAdmissionJournal*,
@@ -924,8 +924,8 @@ inline bool placement_at_entry_capacity(const PendingOrder& order) {
924924
// PendingOrder object. The producer scanned the physical book immediately
925925
// before accepting this priced entry. The journal's immutable before/removed
926926
// records preserve that exact scan, including a peer that remains physically
927-
// resident after a cancellation. A peer without an original command
928-
// direction is a raw book fact, independent of the peer's source Draft.
927+
// resident after a cancellation. Direction is a raw book fact, independent
928+
// of the peer's source Draft.
929929
inline bool placement_has_opposite_market_predecessor(
930930
const MarketAdmissionJournal& journal, const PendingOrder& current) {
931931
const auto& origin = current.market_admission.observation();

‎scripts/check_aggregate_cpp_versions.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,4 @@ def check(root=ROOT):
103103

104104
if __name__ == "__main__":
105105
check()
106-
print("aggregate v11 and standalone lifecycle/admission/cancellation v1 ownership verified")
106+
print("aggregate v11, standalone admission v2 and lifecycle/cancellation v1 ownership verified")

‎scripts/check_script_cpp_abi.py‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,8 +438,10 @@ def compile_object(name, source, include):
438438
}
439439
'''
440440
current_admission = compile_object("current_admission_methods", admission_caller + admission_assertion, args.include)
441-
draft_admission = compile_object("draft_admission_methods", admission_caller, admission_v1_include)
442-
draft_admission_symbols = compile_object("draft_admission_symbols", admission_symbols, admission_v1_include)
441+
draft_admission = compile_object("draft_admission_methods", admission_caller, standalone_draft_include)
442+
draft_admission_symbols = compile_object("draft_admission_symbols", admission_symbols, standalone_draft_include)
443+
v1_admission = compile_object("v1_admission_methods", admission_caller, admission_v1_include)
444+
v1_admission_symbols = compile_object("v1_admission_symbols", admission_symbols, admission_v1_include)
443445

444446
cancellation_caller = '''#include <pineforge/order_cancellation.hpp>
445447
#include <type_traits>
@@ -593,6 +595,7 @@ def link(name, obj, runtime, missing_namespace=None):
593595
link("draft_lifecycle_to_draft_symbols", draft_lifecycle, draft_lifecycle_symbols)
594596
link("current_admission_to_current", current_admission, args.library)
595597
link("draft_admission_to_draft_symbols", draft_admission, draft_admission_symbols)
598+
link("v1_admission_to_v1_symbols", v1_admission, v1_admission_symbols)
596599
for name, obj, runtime, expected in [
597600
("draft_lifecycle_to_current_symbols", draft_lifecycle, current_lifecycle_symbols,
598601
["pairing_lifecycle(pineforge::exit_legs::Lifecycle const&"]),
@@ -605,6 +608,14 @@ def link(name, obj, runtime, missing_namespace=None):
605608
["pineforge::admission::market_admission_v2::Draft::bind(",
606609
"pineforge::admission::market_admission_v2::Journal::next_sequence(",
607610
"pineforge::admission::market_admission_v2::Allocation::~Allocation("]),
611+
("v1_admission_to_current", v1_admission, args.library,
612+
["pineforge::admission::market_admission_v1::Draft::bind(",
613+
"pineforge::admission::market_admission_v1::Journal::next_sequence(",
614+
"pineforge::admission::market_admission_v1::Allocation::~Allocation("]),
615+
("current_admission_to_v1_symbols", current_admission, v1_admission_symbols,
616+
["pineforge::admission::market_admission_v2::Draft::bind(",
617+
"pineforge::admission::market_admission_v2::Journal::next_sequence(",
618+
"pineforge::admission::market_admission_v2::Allocation::~Allocation("]),
608619
]:
609620
result = subprocess.run([*common, str(obj), str(runtime), "-pthread", "-o", str(root / name)],
610621
capture_output=True, text=True, timeout=60)

‎scripts/gen_pending_order_mirror.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,15 +491,19 @@ def generate() -> tuple[str, str]:
491491
"} // namespace",
492492
"",
493493
"void fill_pending_order_mirror(const PendingOrder& src, const MarketAdmissionJournal* journal, pf_pending_order_v1_t* out) {",
494+
" const auto& origin = src.market_admission.observation();",
495+
" if (!journal && src.type == OrderType::ENTRY && origin",
496+
" && origin->kind == admission::CommandKind::Entry",
497+
" && origin->placement_side == static_cast<int>(PositionSide::FLAT)",
498+
" && (!std::isnan(origin->prices.limit) || !std::isnan(origin->prices.stop)))",
499+
' throw std::logic_error("bound priced order mirror requires its admission journal");',
494500
" std::memset(out, 0, sizeof(*out));",
495501
f" out->struct_version = {STRUCT_VERSION};",
496502
" out->size = (uint32_t)sizeof(*out);",
497503
*copies,
498504
"}",
499505
"",
500506
"void fill_pending_order_mirror(const PendingOrder& src, pf_pending_order_v1_t* out) {",
501-
" if (src.market_admission.observation())",
502-
' throw std::logic_error("bound pending order mirror requires its admission journal");',
503507
" fill_pending_order_mirror(src, nullptr, out);",
504508
"}",
505509
"",

‎src/pending_order_mirror.cpp‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ void copy_str(std::string_view s, char* dst, uint8_t* truncated, uint64_t* hash)
3131
} // namespace
3232

3333
void fill_pending_order_mirror(const PendingOrder& src, const MarketAdmissionJournal* journal, pf_pending_order_v1_t* out) {
34+
const auto& origin = src.market_admission.observation();
35+
if (!journal && src.type == OrderType::ENTRY && origin
36+
&& origin->kind == admission::CommandKind::Entry
37+
&& origin->placement_side == static_cast<int>(PositionSide::FLAT)
38+
&& (!std::isnan(origin->prices.limit) || !std::isnan(origin->prices.stop)))
39+
throw std::logic_error("bound priced order mirror requires its admission journal");
3440
std::memset(out, 0, sizeof(*out));
3541
out->struct_version = 1;
3642
out->size = (uint32_t)sizeof(*out);
@@ -427,8 +433,6 @@ void fill_pending_order_mirror(const PendingOrder& src, const MarketAdmissionJou
427433
}
428434

429435
void fill_pending_order_mirror(const PendingOrder& src, pf_pending_order_v1_t* out) {
430-
if (src.market_admission.observation())
431-
throw std::logic_error("bound pending order mirror requires its admission journal");
432436
fill_pending_order_mirror(src, nullptr, out);
433437
}
434438

‎tests/admission_literal_book.hpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Book:public BacktestEngine{
3434
PendingOrder& get(const std::string& id){for(auto& o:pending_orders_)if(o.id==id)return o;throw std::logic_error("missing "+id);}
3535
bool has(const std::string& id)const{for(auto& o:pending_orders_)if(o.id==id)return true;return false;}
3636
std::size_t size()const{return pending_orders_.size();}
37-
pf_pending_order_v1_t mirror(const char* id){pf_pending_order_v1_t m{};fill_pending_order_mirror(get(id),&m);return m;}
37+
pf_pending_order_v1_t mirror(const char* id){pf_pending_order_v1_t m{};fill_pending_order_mirror(get(id),&market_admission_journal(),&m);return m;}
3838
void default_mode(double pct=100){default_qty_type_=QtyType::PERCENT_OF_EQUITY;default_qty_value_=pct;pyramiding_=1;}
3939
void terminal_mode(){process_orders_on_close_=true;calc_on_order_fills_=true;pyramiding_=0;}
4040
void pct(double v){default_qty_value_=v;}

‎tests/test_opposite_intent_facts.cpp‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,19 @@ void accepted_peer_is_reconstructed() {
7171
try { fill_pending_order_mirror(order, &mirror); }
7272
catch (const std::logic_error&) { refused_without_context = true; }
7373
CHECK(refused_without_context);
74+
refused_without_context = false;
75+
mirror.reverses_same_bar_market_from_flat = 37;
76+
try { fill_pending_order_mirror(order, nullptr, &mirror); }
77+
catch (const std::logic_error&) { refused_without_context = true; }
78+
CHECK(refused_without_context);
79+
CHECK(mirror.reverses_same_bar_market_from_flat == 37);
80+
81+
// An ordinary MARKET cannot have this priced-entry predecessor fact, so
82+
// its complete mirror requires no historical context.
83+
auto market = order;
84+
market.type = OrderType::MARKET;
85+
fill_pending_order_mirror(market, &mirror);
86+
CHECK(mirror.reverses_same_bar_market_from_flat == 0);
7487
}
7588

7689
void removed_peer_and_unknown_peer_fail_closed() {

0 commit comments

Comments
 (0)