Skip to content

Commit d135834

Browse files
authored
Merge pull request #750 from evoskuil/master
Adapt to chain and database block population changes.
2 parents 5d0991d + 5e929d3 commit d135834

File tree

6 files changed

+31
-30
lines changed

6 files changed

+31
-30
lines changed

include/bitcoin/node/chasers/chaser_block.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ class BCN_API chaser_block
6868

6969
private:
7070
void set_prevout(const system::chain::input& input) const NOEXCEPT;
71-
bool populate(const system::chain::block& block,
72-
const system::chain::context& ctx) const NOEXCEPT;
71+
bool populate(const system::chain::block& block) const NOEXCEPT;
7372
};
7473

7574
} // namespace node

include/bitcoin/node/error.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ enum error_t : uint8_t
8484
validate5,
8585
validate6,
8686
validate7,
87-
validate8,
88-
validate9,
87+
////validate8,
88+
////validate9,
8989
confirm1,
9090
confirm2,
9191
confirm3,

src/chasers/chaser_block.cpp

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,11 @@ code chaser_block::validate(const block& block,
117117
return ec;
118118
}
119119

120-
// Populate prevouts from self/tree (metadata not required).
121-
if (!populate(block, ctx))
122-
return system::error::relative_time_locked;
120+
// Populate prevouts from self/tree (no metadata for accept/connect).
121+
populate(block);
123122

124-
// Populate prevouts from store (metadata not required).
125-
if (!archive().populate(block))
123+
// Populate prevouts from store (no metadata for accept/connect).
124+
if (!archive().populate_without_metadata(block))
126125
return network::error::protocol_violation;
127126

128127
if ((ec = block.accept(ctx,
@@ -156,6 +155,8 @@ void chaser_block::update_milestone(const header&, size_t, size_t) NOEXCEPT
156155
void chaser_block::set_prevout(const input& input) const NOEXCEPT
157156
{
158157
const auto& point = input.point();
158+
if (input.prevout || point.is_null())
159+
return;
159160

160161
// Scan all tree blocks for matching tx (linear :/ but legacy scenario)
161162
std::for_each(tree().begin(), tree().end(), [&](const auto& item) NOEXCEPT
@@ -173,25 +174,22 @@ void chaser_block::set_prevout(const input& input) const NOEXCEPT
173174
const outputs_cptr outs{ tx->outputs_ptr() };
174175
if (point.index() < outs->size())
175176
{
177+
// prevout is mutable so can be set on a const object.
176178
input.prevout = outs->at(point.index());
177179
return;
178180
}
179181
}
180182
});
181183
}
182184

183-
// metadata is mutable so can be set on a const object.
184-
bool chaser_block::populate(const block& block,
185-
const system::chain::context& ctx) const NOEXCEPT
185+
bool chaser_block::populate(const block& block) const NOEXCEPT
186186
{
187-
if (!block.populate(ctx))
188-
return false;
187+
block.populate();
189188

190-
const inputs_cptr ins{ block.inputs_ptr() };
191-
std::for_each(ins->begin(), ins->end(), [&](const auto& in) NOEXCEPT
189+
const auto& ins = *block.inputs_ptr();
190+
std::for_each(ins.begin(), ins.end(), [&](const auto& in) NOEXCEPT
192191
{
193-
if (!in->prevout && !in->point().is_null())
194-
set_prevout(*in);
192+
set_prevout(*in);
195193
});
196194

197195
return true;

src/chasers/chaser_confirm.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ void chaser_confirm::do_validated(height_t height) NOEXCEPT
164164

165165
// TODO: This is simplified single thread variant of full implementation below.
166166
// This variant doesn't implement the relative work check and instead confirms
167-
// one block at a time, just like validation.
167+
// one block at a time, just like validation though sequentially.
168168
void chaser_confirm::do_bump(height_t) NOEXCEPT
169169
{
170170
BC_ASSERT(stranded());
@@ -229,7 +229,7 @@ void chaser_confirm::do_bump(height_t) NOEXCEPT
229229
return;
230230
}
231231

232-
// Set after if using prevout table.
232+
// Set after block_confirmable when using the prevout table.
233233
if (!query.set_strong(link))
234234
{
235235
fault(error::confirm6);

src/chasers/chaser_validate.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -238,18 +238,21 @@ code chaser_validate::populate(bool bypass, const chain::block& block,
238238
{
239239
const auto& query = archive();
240240

241-
// Relative locktime check is unnecessary under bypass, but cheap.
242-
if (!block.populate(ctx))
243-
return system::error::relative_time_locked;
244-
245241
if (bypass)
246242
{
243+
block.populate();
247244
if (!query.populate_without_metadata(block))
248245
return system::error::missing_previous_output;
249246
}
250247
else
251248
{
252-
if (!query.populate(block))
249+
// Internal maturity and time locks are verified here because they are
250+
// the only necessary confirmation checks for internal spends.
251+
if (const auto ec = block.populate_with_metadata(ctx))
252+
return ec;
253+
254+
// Metadata identifies internal spends alowing confirmation bypass.
255+
if (!query.populate_with_metadata(block))
253256
return system::error::missing_previous_output;
254257
}
255258

@@ -271,11 +274,11 @@ code chaser_validate::validate(bool bypass, const chain::block& block,
271274
if ((ec = block.connect(ctx)))
272275
return ec;
273276

274-
if ((ec = query.set_prevouts(link, block)))
275-
return ec;
277+
if (!query.set_prevouts(link, block))
278+
return error::validate6;
276279

277280
if (!query.set_block_valid(link, block.fees()))
278-
return error::validate6;
281+
return error::validate7;
279282

280283
return ec;
281284
}
@@ -286,6 +289,7 @@ void chaser_validate::complete_block(const code& ec, const header_link& link,
286289
{
287290
if (ec)
288291
{
292+
// Node errors are fatal.
289293
if (node::error::error_category::contains(ec))
290294
{
291295
LOGR("Validate fault [" << height << "] " << ec.message());

src/error.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ DEFINE_ERROR_T_MESSAGE_MAP(error)
7474
{ validate5, "validate5" },
7575
{ validate6, "validate6" },
7676
{ validate7, "validate7" },
77-
{ validate8, "validate8" },
78-
{ validate9, "validate9" },
77+
////{ validate8, "validate8" },
78+
////{ validate9, "validate9" },
7979
{ confirm1, "confirm1" },
8080
{ confirm2, "confirm2" },
8181
{ confirm3, "confirm3" },

0 commit comments

Comments
 (0)