Skip to content

Commit

Permalink
explorer: added dh arg to hdrs query
Browse files Browse the repository at this point in the history
  • Loading branch information
valdok committed Jun 9, 2024
1 parent 817294d commit 767d55c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
25 changes: 21 additions & 4 deletions explorer/adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2209,11 +2209,13 @@ class Adapter : public Node::IObserver, public IAdapter {
void OnHdrs_SizeCompressed_Rel(json& j) { j.push_back(MakeTableHdr("D.Size.Compressed")); }
void OnHdrs_SizeCompressed_Rel(json& j, const Totals& t1, const Totals& t0, const Block::SystemState::Full& s) { j.push_back(MakeDecimalDelta(get_ChainSize(s.m_Height, t1, false) - get_ChainSize(s.m_Height - 1, t0, false)).m_sz); }

json get_hdrs(uint64_t hMax, uint64_t nMax, uint32_t fAbs, uint32_t fRel) override
json get_hdrs(uint64_t hMax, uint64_t nMax, uint64_t dh, uint32_t fAbs, uint32_t fRel) override
{
std::setmin(nMax, 2048u);
std::setmin(hMax, _nodeBackend.m_Cursor.m_Full.m_Height);

std::setmax(dh, 1u);

json jRet = json::array();

{
Expand Down Expand Up @@ -2244,6 +2246,7 @@ class Adapter : public Node::IObserver, public IAdapter {
sid.m_Row = db.FindActiveStateStrict(hMax);

Merkle::Hash hv;
bool bValidHv = false;

StateData pTots[2];
uint32_t iIdxTots = 0;
Expand All @@ -2254,7 +2257,7 @@ class Adapter : public Node::IObserver, public IAdapter {
Block::SystemState::Full s;
db.get_State(sid.m_Row, s);

if (hMax == sid.m_Height)
if (!bValidHv)
s.get_Hash(hv);

json jRow = json::array();
Expand All @@ -2267,7 +2270,17 @@ class Adapter : public Node::IObserver, public IAdapter {

iIdxTots = !iIdxTots;

if (!db.get_Prev(sid))
if (sid.m_Height - Rules::HeightGenesis >= dh)
{
if (1u == dh)
db.get_Prev(sid);
else
{
sid.m_Height -= dh;
sid.m_Row = db.FindActiveStateStrict(sid.m_Height);
}
}
else
{
ZeroObject(sid);
bDone = true;
Expand Down Expand Up @@ -2296,7 +2309,11 @@ class Adapter : public Node::IObserver, public IAdapter {
if (bDone)
break;

hv = s.m_Prev;
if (1u == dh)
{
hv = s.m_Prev;
bValidHv = true;
}
}
}

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(uint64_t height) = 0;
virtual json get_block_by_kernel(const Blob& key) = 0;
virtual json get_blocks(uint64_t startHeight, uint64_t n) = 0;
virtual json get_hdrs(uint64_t hMax, uint64_t nMax, uint32_t fAbs, uint32_t fRel) = 0;
virtual json get_hdrs(uint64_t hMax, uint64_t nMax, uint64_t dh, uint32_t fAbs, uint32_t fRel) = 0;
virtual json get_peers() = 0;

#ifdef BEAM_ATOMIC_SWAP_SUPPORT
Expand Down
3 changes: 2 additions & 1 deletion explorer/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,7 @@ OnRequest(hdrs)
{
Height hTop = _currentUrl.get_int_arg("hMax", std::numeric_limits<int64_t>::max());
uint32_t n = (uint32_t) _currentUrl.get_int_arg("nMax", static_cast<uint32_t>(-1));
Height dh = _currentUrl.get_int_arg("dh", static_cast<uint32_t>(1));

// defaults
typedef IAdapter::TotalsFlags F;
Expand All @@ -813,7 +814,7 @@ OnRequest(hdrs)
ReadColFlags(_currentUrl, fAbs, "cabs");
ReadColFlags(_currentUrl, fRel, "crel");

return _backend.get_hdrs(hTop, n, fAbs, fRel);
return _backend.get_hdrs(hTop, n, dh, fAbs, fRel);
}

OnRequest(peers)
Expand Down

0 comments on commit 767d55c

Please sign in to comment.