Skip to content

Commit f224684

Browse files
author
ABW
committed
introduce transfer substitution in form of custom json for cases where 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.
1 parent 36c1315 commit f224684

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

libraries/plugins/colony/colony_plugin.cpp

+23-2
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ struct transaction_builder
8484
std::array< operation_stats, NUMBER_OF_OPERATIONS > _stats;
8585
uint32_t _reply_substitutions = 0;
8686
uint32_t _vote_substitutions = 0;
87+
uint32_t _transfer_substitutions = 0;
8788
uint32_t _failed_transactions = 0;
8889
uint32_t _failed_rc = 0;
8990
uint32_t _tx_num = 0;
@@ -189,6 +190,11 @@ void transaction_builder::print_stats() const
189190
ilog( "${r} replies and ${v} votes substituted with articles due to lack of proper target comment",
190191
( "r", _reply_substitutions )( "v", _vote_substitutions ) );
191192
}
193+
if( _transfer_substitutions )
194+
{
195+
ilog( "${r} transfers substituted with custom jsons due to lack of funds",
196+
( "r", _transfer_substitutions ) );
197+
}
192198
if( _failed_transactions )
193199
{
194200
ilog( "${f} transactions failed with exception (including ${r} due to lack of RC)",
@@ -496,18 +502,33 @@ void transaction_builder::build_vote( const account_object& actor, uint64_t nonc
496502

497503
void transaction_builder::build_transfer( const account_object& actor, uint64_t nonce )
498504
{
505+
bool use_hive = false;
506+
if( actor.get_hbd_balance().amount.value == 0 )
507+
{
508+
if( actor.get_balance().amount.value == 0 )
509+
{
510+
++_transfer_substitutions;
511+
build_custom( actor, nonce );
512+
return;
513+
}
514+
use_hive = true;
515+
}
516+
499517
++_stats[ TRANSFER ].count;
500518

501519
transfer_operation transfer;
502520
transfer.from = actor.get_name();
503521
transfer.to = (*_current_account)->get_name();
504-
transfer.amount = HBD_asset( 1 );
522+
if( use_hive )
523+
transfer.amount = HIVE_asset( 1 );
524+
else
525+
transfer.amount = HBD_asset( 1 );
505526
transfer.memo = std::to_string( nonce );
506527
auto extra_size = _common._params[ TRANSFER ].randomize();
507528
_stats[ TRANSFER ].extra_size += extra_size;
508529
if( extra_size > (int64_t)transfer.memo.size() + 1 )
509530
{
510-
extra_size -= ( int64_t ) transfer.memo.size() + 1;
531+
extra_size -= (int64_t)transfer.memo.size() + 1;
511532
std::string fill;
512533
fill_string( fill, extra_size );
513534
transfer.memo = transfer.memo + ":" + fill;

0 commit comments

Comments
 (0)