Skip to content

Commit

Permalink
Use the sideband when available in ledger.is_send (#2620)
Browse files Browse the repository at this point in the history
  • Loading branch information
guilhermelawless committed Mar 4, 2020
1 parent 7c6f436 commit 5600dc6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
5 changes: 5 additions & 0 deletions nano/lib/blocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ void nano::block::sideband_set (nano::block_sideband const & sideband_a)
sideband_m = sideband_a;
}

bool nano::block::has_sideband () const
{
return sideband_m.is_initialized ();
}

nano::account const & nano::block::representative () const
{
static nano::account rep{ 0 };
Expand Down
1 change: 1 addition & 0 deletions nano/lib/blocks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class block
nano::block_hash full_hash () const;
nano::block_sideband const & sideband () const;
void sideband_set (nano::block_sideband const &);
bool has_sideband () const;
std::string to_json () const;
virtual void hash (blake2b_state &) const = 0;
virtual uint64_t block_work () const = 0;
Expand Down
15 changes: 11 additions & 4 deletions nano/secure/ledger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -807,12 +807,19 @@ std::string nano::ledger::block_text (nano::block_hash const & hash_a)
bool nano::ledger::is_send (nano::transaction const & transaction_a, nano::state_block const & block_a) const
{
bool result (false);
nano::block_hash previous (block_a.hashables.previous);
if (!previous.is_zero ())
if (block_a.has_sideband ())
{
if (block_a.hashables.balance < balance (transaction_a, previous))
result = block_a.sideband ().details.is_send;
}
else
{
nano::block_hash previous (block_a.hashables.previous);
if (!previous.is_zero ())
{
result = true;
if (block_a.hashables.balance < balance (transaction_a, previous))
{
result = true;
}
}
}
return result;
Expand Down

0 comments on commit 5600dc6

Please sign in to comment.