Skip to content

Commit

Permalink
introduce transfer substitution in form of custom json for cases wher…
Browse files Browse the repository at this point in the history
…e colony worker account has nothing on balances

Also try to look for HIVE in balance before falling back to substitution.
Note that the change only needs to reduce likelyhood of transfer being invalid, not to make sure the balance is nonzero.
We can't do that anyway (since balance can change after transaction was sent but before it was executed), so we also
don't need to care about read-locking access to balances. The whole problem with zero balance should never occur on properly
prepared testnet, however it is very frequent on mirrornet.
  • Loading branch information
ABW committed Oct 7, 2024
1 parent 36c1315 commit f224684
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions libraries/plugins/colony/colony_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ struct transaction_builder
std::array< operation_stats, NUMBER_OF_OPERATIONS > _stats;
uint32_t _reply_substitutions = 0;
uint32_t _vote_substitutions = 0;
uint32_t _transfer_substitutions = 0;
uint32_t _failed_transactions = 0;
uint32_t _failed_rc = 0;
uint32_t _tx_num = 0;
Expand Down Expand Up @@ -189,6 +190,11 @@ void transaction_builder::print_stats() const
ilog( "${r} replies and ${v} votes substituted with articles due to lack of proper target comment",
( "r", _reply_substitutions )( "v", _vote_substitutions ) );
}
if( _transfer_substitutions )
{
ilog( "${r} transfers substituted with custom jsons due to lack of funds",
( "r", _transfer_substitutions ) );
}
if( _failed_transactions )
{
ilog( "${f} transactions failed with exception (including ${r} due to lack of RC)",
Expand Down Expand Up @@ -496,18 +502,33 @@ void transaction_builder::build_vote( const account_object& actor, uint64_t nonc

void transaction_builder::build_transfer( const account_object& actor, uint64_t nonce )
{
bool use_hive = false;
if( actor.get_hbd_balance().amount.value == 0 )
{
if( actor.get_balance().amount.value == 0 )
{
++_transfer_substitutions;
build_custom( actor, nonce );
return;
}
use_hive = true;
}

++_stats[ TRANSFER ].count;

transfer_operation transfer;
transfer.from = actor.get_name();
transfer.to = (*_current_account)->get_name();
transfer.amount = HBD_asset( 1 );
if( use_hive )
transfer.amount = HIVE_asset( 1 );
else
transfer.amount = HBD_asset( 1 );
transfer.memo = std::to_string( nonce );
auto extra_size = _common._params[ TRANSFER ].randomize();
_stats[ TRANSFER ].extra_size += extra_size;
if( extra_size > (int64_t)transfer.memo.size() + 1 )
{
extra_size -= ( int64_t ) transfer.memo.size() + 1;
extra_size -= (int64_t)transfer.memo.size() + 1;
std::string fill;
fill_string( fill, extra_size );
transfer.memo = transfer.memo + ":" + fill;
Expand Down

0 comments on commit f224684

Please sign in to comment.