@@ -289,25 +289,12 @@ transaction::sizes transaction::serialized_size(const input_cptrs& inputs,
289289{
290290 sizes size{ zero, zero };
291291
292- // Keep the condition outside of the loop.
293- if (segregated)
292+ std::for_each (inputs.begin (), inputs.end (), [&](const auto & in) NOEXCEPT
294293 {
295- std::for_each (inputs.begin (), inputs.end (), [&](const auto & in) NOEXCEPT
296- {
297- size.nominal = ceilinged_add (size.nominal , in->nominal_size ());
294+ size.nominal = ceilinged_add (size.nominal , in->nominal_size ());
295+ if (segregated)
298296 size.witnessed = ceilinged_add (size.witnessed , in->witnessed_size ());
299- });
300- }
301- else
302- {
303- // Witness must be zeroed because witnesses have nonzero size when they
304- // are zero-valued, so they can be archived easily. Also it would be
305- // wasteful to to count mutiple zero sizes, so exclude them here.
306- std::for_each (inputs.begin (), inputs.end (), [&](const auto & in) NOEXCEPT
307- {
308- size.nominal = ceilinged_add (size.nominal , in->nominal_size ());
309- });
310- }
297+ });
311298
312299 const auto outs = [](size_t total, const auto & output) NOEXCEPT
313300 {
@@ -316,20 +303,20 @@ transaction::sizes transaction::serialized_size(const input_cptrs& inputs,
316303
317304 constexpr auto base_const_size = ceilinged_add (sizeof (version_),
318305 sizeof (locktime_));
319-
320306 constexpr auto witness_const_size = ceilinged_add (sizeof (witness_marker),
321307 sizeof (witness_enabled));
322308
323309 const auto base_size = ceilinged_add (ceilinged_add (ceilinged_add (
324310 base_const_size, variable_size (inputs.size ())),
325311 variable_size (outputs.size ())),
326312 std::accumulate (outputs.begin (), outputs.end (), zero, outs));
327-
328313 const auto nominal_size = ceilinged_add (base_size, size.nominal );
329- const auto witnessed_size = ceilinged_add (ceilinged_add (base_size,
330- witness_const_size),
331- size.witnessed );
332314
315+ // witnessed_size is nominal_size for non-segregated transactions.
316+ const auto witnessed_size = segregated ? ceilinged_add (ceilinged_add (
317+ base_size, witness_const_size), size.witnessed ) : nominal_size;
318+
319+ // Values are the same for non-segregated transactions.
333320 return { nominal_size, witnessed_size };
334321}
335322
0 commit comments