Skip to content

Commit 838338f

Browse files
authored
Merge pull request #716 from evoskuil/master
Must set_code(*block vs. *txs) due to custom allocator.
2 parents 74cacb3 + 18db9d2 commit 838338f

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

src/chasers/chaser_confirm.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ void chaser_confirm::do_bump(height_t) NOEXCEPT
208208
// Set before if not using prevout table.
209209
if (!prevout_ && !query.set_strong(link))
210210
{
211-
fault(error::confirm5);
211+
fault(error::confirm2);
212212
return;
213213
}
214214

@@ -242,14 +242,14 @@ void chaser_confirm::do_bump(height_t) NOEXCEPT
242242

243243
if (!query.set_block_confirmable(link))
244244
{
245-
fault(error::confirm4);
245+
fault(error::confirm3);
246246
return;
247247
}
248248

249249
// Set after if using prevout table.
250250
if (prevout_ && !query.set_strong(link))
251251
{
252-
fault(error::confirm5);
252+
fault(error::confirm4);
253253
return;
254254
}
255255
}
@@ -258,7 +258,7 @@ void chaser_confirm::do_bump(height_t) NOEXCEPT
258258
// Set in either case.
259259
if (!query.set_strong(link))
260260
{
261-
fault(error::confirm6);
261+
fault(error::confirm5);
262262
return;
263263
}
264264
}
@@ -271,21 +271,21 @@ void chaser_confirm::do_bump(height_t) NOEXCEPT
271271
// database::error::block_confirmable [resurrected state]
272272
// database::error::block_unconfirmable [shouldn't be here]
273273
// database::error::unknown_state [shouldn't be here]
274-
fault(error::confirm7);
274+
fault(error::confirm6);
275275
return;
276276
}
277277

278278
if (!query.set_filter_head(link))
279279
{
280-
fault(error::confirm8);
280+
fault(error::confirm7);
281281
return;
282282
}
283283

284-
if (!set_organized(link, height))
285-
{
286-
fault(error::confirm9);
287-
return;
288-
}
284+
////if (!set_organized(link, height))
285+
////{
286+
//// fault(error::confirm8);
287+
//// return;
288+
////}
289289

290290
set_position(height);
291291

src/protocols/protocol_block_in_31800.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -351,14 +351,16 @@ bool protocol_block_in_31800::handle_receive_block(const code& ec,
351351
// Commit block.txs.
352352
// ........................................................................
353353

354-
// This must not be a reference to the shared pointer, as otherwise the
355-
// shared_ptr may be taken out of scope before the tx write completes.
356-
// set_code() uses weak references to many elements of the transaction ref.
357-
const auto txs_ptr = block->transactions_ptr();
358-
const auto size = block->serialized_size(true);
354+
// IMPORTANT: ~block() releases all memory for parts of itself, as a
355+
// consequence of the custom memory allocator. Therefore, while shared_ptr
356+
// to an element of the block would normally be valid after ~block(), the
357+
// object pointed to will have been deallocated by ~block(). Therefore a
358+
// reference to `block` must be passed to set_code (i.e. not a copy of or
359+
// reference to `lock->transactions_ptr()`.
359360

360361
// This invokes set_strong when checked.
361-
if (const auto code = query.set_code(*txs_ptr, link, size, checked))
362+
const auto bytes = block->serialized_size(true);
363+
if (const auto code = query.set_code(*block, link, checked, bytes))
362364
{
363365
LOGF("Failure storing block [" << encode_hash(hash) << ":" << height
364366
<< "] from [" << authority() << "] " << code.message());
@@ -376,7 +378,7 @@ bool protocol_block_in_31800::handle_receive_block(const code& ec,
376378
notify(ec, chase::checked, height);
377379
fire(events::block_archived, height);
378380

379-
count(size);
381+
count(bytes);
380382
map_->erase(it);
381383
if (is_idle())
382384
{

0 commit comments

Comments
 (0)