@@ -50,6 +50,7 @@ bool protocol_native::handle_get_configuration(const code& ec,
5050 { " witness" , network_settings ().witness_node () },
5151 { " retarget" , system_settings ().forks .retarget },
5252 { " difficult" , system_settings ().forks .difficult },
53+ { " stripped" , get_stripped_height () },
5354 };
5455 BC_POP_WARNING ()
5556
@@ -101,5 +102,40 @@ bool protocol_native::handle_get_event_subscribe(const code& ec,
101102 return true ;
102103}
103104
105+ // utility
106+ // ----------------------------------------------------------------------------
107+
108+ size_t protocol_native::get_stripped_height () NOEXCEPT
109+ {
110+ if (!network_settings ().pruned_node () ||
111+ !network_settings ().witness_node ())
112+ return {};
113+
114+ const auto & system_ = system_settings ();
115+ const auto milestone = get_active_height (system_.milestone .hash ());
116+ const auto checkpoint = get_active_height (system_.top_checkpoint ().hash ());
117+ return std::max (milestone, checkpoint);
118+ }
119+
120+ size_t protocol_native::get_active_height (
121+ const system::hash_digest& hash) NOEXCEPT
122+ {
123+ const auto & query = archive ();
124+ const auto link = query.to_header (hash);
125+ system::chain::context ctx{};
126+
127+ // This uses candidate header vs. confirmed block so that stripping will
128+ // show at heights below top checkpoint and milestone while still syncing.
129+ // This can result in a weak branch milestone block implying a pruned
130+ // height that doesn't confirm (ok), which can't happen for checkpoints.
131+ // This can be mitigated by setting stripped on the object when it's a
132+ // milestone or checked object and pruning is enabled. Pruning can be
133+ // enabled after storage of non-stripped blocks, which does not strip them.
134+ // This will return false is bip141 is not active by the milestone.
135+ return query.get_context (ctx, link) &&
136+ ctx.is_enabled (system::chain::bip141_rule) &&
137+ query.is_candidate_header (link) ? ctx.height : zero;
138+ }
139+
104140} // namespace server
105141} // namespace libbitcoin
0 commit comments