MCPcopy Create free account
hub / github.com/Niko1221/Strata / chain

Method chain

engine/src/spec/draft_policy.cpp:1009–1033  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1007}
1008
1009int DraftPolicy::chain(int t_mtp, double p_mtp, int k_avail, int match) const {
1010 t_mtp = std::clamp(t_mtp, 1, max_t_);
1011 const int kmax = std::min(k_avail, max_t_ - t_mtp);
1012 if (kmax <= 0) return 0;
1013 const double e0 = mtp_tokens(t_mtp), base = e0 / cost_ms(t_mtp), c = chain_rate(match);
1014 p_mtp = std::clamp(p_mtp, 0.0, 1.0);
1015 double gain = 0.0, ci = 1.0, best = 0.0;
1016 int best_k = 0;
1017 for (int k = 1; k <= kmax; ++k) {
1018 ci *= c;
1019 gain += ci;
1020 if (!allowed(t_mtp + k)) continue;
1021 const double r = (e0 + p_mtp * gain) / cost_ms(t_mtp + k);
1022 if (r > best) { best = r; best_k = k; }
1023 }
1024 const int t_full = fit(t_mtp + kmax), k_full = t_full - t_mtp;
1025 if (best_k > 0 && best > base * (1.0 + margin_)) {
1026 // As choose(): a profitable shorter chain must not keep a stale full size from being measured again.
1027 if (best_k < k_full && p_mtp * c >= 0.6 && stale(t_full)) return k_full;
1028 return best_k;
1029 }
1030 // as choose(): a size whose cost is only guessed is tried a few times when the continuation looks likely
1031 if (!fixed_ && k_full > 0 && (cost_n_[bk_][t_full] < kProbes || stale(t_full)) && p_mtp * c >= 0.6) return k_full;
1032 return 0;
1033}
1034
1035void DraftPolicy::observe_chain(int t_mtp, int k, int accepted, int match, double round_ms) {
1036 const int t = std::clamp(t_mtp + k, 1, kMaxT);

Callers 5

mainFunction · 0.45
mainFunction · 0.45
show_errorFunction · 0.45
argsFunction · 0.45
read_hkcu_strFunction · 0.45

Calls 5

staleFunction · 0.85
clampFunction · 0.50
minFunction · 0.50
allowedFunction · 0.50
fitFunction · 0.50

Tested by

no test coverage detected