Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions core/block_crypt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2704,8 +2704,12 @@ namespace beam

oracle
<< "fork6"
<< pForks[6].m_Height
<< (uint32_t) 1 // fees in coinbase
<< pForks[6].m_Height;

if (Rules::Consensus::Pbft != m_Consensus)
oracle << (uint32_t) 1; // fees in coinbase, n/a for pbft

oracle
<< Evm.Groth2Wei
<< Evm.BaseGasPrice
<< Evm.MinTxGasUnits
Expand Down
118 changes: 75 additions & 43 deletions explorer/adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2838,47 +2838,59 @@ class Adapter : public Node::IObserver, public IAdapter {
return json{ { "found", false}, {"height", h } };
}

json get_block(Height height, int adj) override
// Resolves the block for the given height and adj direction. false if there's none (vacant height, no adj)
// h is the resolved height, 0 means treasury
bool ResolveBlock(NodeDB::StateID& sid, Block::SystemState::Full& s, Height& h, Height height, int adj)
{
NodeDB::StateID sid;
Block::SystemState::Full s;
Height h = height;
assert(height);

if (height)
if (FindBlockByHeight(sid, s, height))
{
if (FindBlockByHeight(sid, s, height))
{
h = s.get_Height();
assert(h >= height);
}
else
{
assert(height > _nodeBackend.m_Cursor.m_hh.m_Height); // requested above current tip
h = s.get_Height();
assert(h >= height);
}
else
{
assert(height > _nodeBackend.m_Cursor.m_hh.m_Height); // requested above current tip

sid = _nodeBackend.m_Cursor.get_Sid();
s = _nodeBackend.m_Cursor.m_Full;
h = _nodeBackend.m_Cursor.m_hh.m_Height;
}
sid = _nodeBackend.m_Cursor.get_Sid();
s = _nodeBackend.m_Cursor.m_Full;
h = _nodeBackend.m_Cursor.m_hh.m_Height;
}

if (h != height)
{
if (!adj)
return get_block_not_found(height);
if (h != height)
{
if (!adj)
return false;

if ((h > height) && (adj < 0))
if ((h > height) && (adj < 0))
{
if (_nodeBackend.get_DB().get_Prev(sid))
{
if (_nodeBackend.get_DB().get_Prev(sid))
{
_nodeBackend.get_DB().get_State(sid.m_Row, s);
h = s.get_Height();
assert(h < height);
}
else
h = 0; // fall back to treasury
_nodeBackend.get_DB().get_State(sid.m_Row, s);
h = s.get_Height();
assert(h < height);
}

// ignore other cases
else
h = 0; // fall back to treasury
}

// ignore other cases
}

return true;
}

json get_block(Height height, int adj) override
{
NodeDB::StateID sid;
Block::SystemState::Full s;
Height h = height;

if (height)
{
if (!ResolveBlock(sid, s, h, height, adj))
return get_block_not_found(height);
}
else
{
Expand Down Expand Up @@ -2919,7 +2931,7 @@ class Adapter : public Node::IObserver, public IAdapter {
return get_block_not_found(h);
}

json get_blocks(Height startHeight, uint64_t n) override {
json get_blocks(Height startHeight, uint64_t n, int adj) override {

json result = json::array();

Expand All @@ -2929,25 +2941,45 @@ class Adapter : public Node::IObserver, public IAdapter {

NodeDB::StateID sid;
Block::SystemState::Full s;
Height h = startHeight;

Height endHeight = startHeight + n - 1; // correct only for PoW
_exchangeRateProvider->preloadRates(startHeight, endHeight);

if (FindBlockByHeight(sid, s, startHeight))
// adj applies to the 1st block only, the rest follow upwards
if (!ResolveBlock(sid, s, h, startHeight, adj))
{
while (true)
{
result.push_back(extract_block_from_row(sid, s, s.get_Height()));
if (!--n)
break;
result.push_back(get_block_not_found(startHeight));
return result;
}

if (sid.m_Number.v >= _nodeBackend.m_Cursor.m_Full.m_Number.v)
break;
if (!h)
{
// treasury, nothing to continue from
result.push_back(get_treasury());
return result;
}

while (true)
{
result.push_back(extract_block_from_row(sid, s, h));
if (!--n)
break;

sid.m_Number.v++;
sid.m_Row = _nodeBackend.FindActiveAtStrict(sid.m_Number);
if (sid.m_Number.v >= _nodeBackend.m_Cursor.m_Full.m_Number.v)
{
// past the tip, report the rest as missing
while (n--)
result.push_back(get_block_not_found(++h)); // correct only for PoW
break;
}

sid.m_Number.v++;
sid.m_Row = _nodeBackend.FindActiveAtStrict(sid.m_Number);

_nodeBackend.get_DB().get_State(sid.m_Row, s);

h = s.get_Height();
}

return result;
Expand Down
2 changes: 1 addition & 1 deletion explorer/adapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ struct IAdapter {
virtual json get_block(Height height, int adj) = 0;
virtual json get_treasury() = 0;
virtual json get_block_by_kernel(const Blob& key) = 0;
virtual json get_blocks(Height startHeight, uint64_t n) = 0;
virtual json get_blocks(Height startHeight, uint64_t n, int adj) = 0;
virtual json get_hdrs(Height hMax, uint64_t nMax, uint64_t dn, const TotalsCol* pCols, uint32_t nCols) = 0;
virtual json get_peers() = 0;

Expand Down
3 changes: 2 additions & 1 deletion explorer/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,8 @@ OnRequest(blocks)
if (start <= 0 || n < 0)
Exc::Fail("#3.1");

return _backend.get_blocks(start, n);
auto adj = _currentUrl.get_int_arg("adj", 0);
return _backend.get_blocks(start, n, static_cast<int>(adj));
}

OnRequest(hdrs)
Expand Down
Loading