Skip to content

Commit

Permalink
Merge pull request graft-project#71 from graft-project/fix-tx-not-pos…
Browse files Browse the repository at this point in the history
…sible

fix for  tx_not_possible aka "tx always splitted"
  • Loading branch information
laid37 authored Jan 19, 2018
2 parents 42c6013 + ce7ac2c commit 920f8bf
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 13 deletions.
6 changes: 4 additions & 2 deletions src/supernode/graft_wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5451,8 +5451,10 @@ bool GraftWallet::use_fork_rules(uint8_t version, int64_t early_blocks)
throw_on_rpc_response_error(result, "get_info");
result = m_node_rpc_proxy.get_earliest_height(version, earliest_height);
throw_on_rpc_response_error(result, "get_hard_fork_info");

bool close_enough = height >= earliest_height - early_blocks; // start using the rules that many blocks beforehand
// graft: check if we have integer overflow in 'earliest_height - early_blocks' because we started from v7
bool close_enough = earliest_height >= std::abs(early_blocks) ?
(height >= earliest_height - early_blocks) : true; // start using the rules that many blocks beforehand
LOG_PRINT_L2("height: " << height << ", earliest_height: " << earliest_height);
if (close_enough)
LOG_PRINT_L2("Using v" << (unsigned)version << " rules");
else
Expand Down
2 changes: 1 addition & 1 deletion src/version.h.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#define GRAFT_VERSION_TAG "@VERSIONTAG@"
#define GRAFT_VERSION "1.0.0"
#define GRAFT_VERSION "1.0.1"
#define GRAFT_RELEASE_NAME "Vega"
#define GRAFT_VERSION_FULL GRAFT_VERSION "-" GRAFT_VERSION_TAG
9 changes: 3 additions & 6 deletions src/wallet/wallet2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4507,11 +4507,6 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions_2(std::vector<cryp
// if we need to spend money and don't have any left, we fail
if (unused_dust_indices.empty() && unused_transfers_indices.empty()) {
LOG_PRINT_L2("No more outputs to choose from");

uint64_t available_outputs = select_available_outputs([](const transfer_details &td) {
return true;
}).size();
LOG_ERROR("can't create transaction(s): available outputs count: " << available_outputs << ", destinations count: " << dsts.size());
THROW_WALLET_EXCEPTION_IF(1, error::tx_not_possible, unlocked_balance(), needed_money, accumulated_fee + needed_fee);
}

Expand Down Expand Up @@ -4900,7 +4895,9 @@ bool wallet2::use_fork_rules(uint8_t version, int64_t early_blocks)
throw_on_rpc_response_error(result, "get_info");
result = m_node_rpc_proxy.get_earliest_height(version, earliest_height);
throw_on_rpc_response_error(result, "get_hard_fork_info");
bool close_enough = height >= earliest_height - early_blocks; // start using the rules that many blocks beforehand
// graft: check if we have integer overflow in 'earliest_height - early_blocks' because we started from v7
bool close_enough = earliest_height >= static_cast<uint64_t>(std::abs(early_blocks)) ?
(height >= earliest_height - early_blocks) : true; // start using the rules that many blocks beforehand
LOG_PRINT_L2("height: " << height << ", earliest_height: " << earliest_height);
if (close_enough)
LOG_PRINT_L2("Using v" << (unsigned)version << " rules");
Expand Down
27 changes: 23 additions & 4 deletions tests/supernode_tests/graft_wallet_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,9 @@ struct GraftWalletTest : public testing::Test
const std::string DAEMON_ADDR = "localhost:28281";



GraftWalletTest()
{
GraftWallet *wallet1 = new GraftWallet(true, false);
GraftWallet * wallet1 = new GraftWallet(true, false);
GraftWallet *wallet2 = new GraftWallet(true, false);
wallet_root_path = epee::string_tools::get_current_module_folder() + "/../data/supernode/test_wallets";
string wallet_path1 = wallet_root_path + "/miner_wallet";
Expand All @@ -87,7 +86,6 @@ struct GraftWalletTest : public testing::Test

~GraftWalletTest()
{

}

};
Expand Down Expand Up @@ -142,7 +140,28 @@ TEST_F(GraftWalletTest, LoadWrongCache)
ASSERT_ANY_THROW(wallet->load_graft(wallet_account2, "", cache_filename));
boost::filesystem::remove(temp);
delete wallet;
}


// implemented here; normally we need the same for wallet/wallet2.cpp
TEST_F(GraftWalletTest, UseForkRule)
{
GraftWallet *wallet = new GraftWallet(true, false);
ASSERT_NO_THROW(wallet->load_graft(wallet_account1, "", ""));
// connect to daemon and get the blocks
wallet->init(DAEMON_ADDR);
ASSERT_TRUE(wallet->use_fork_rules(2, 0));
ASSERT_TRUE(wallet->use_fork_rules(4, 0));
ASSERT_TRUE(wallet->use_fork_rules(5, 0));
ASSERT_TRUE(wallet->use_fork_rules(6, 0));
// this will fail on rta testnet as we need to update block version there
ASSERT_TRUE(wallet->use_fork_rules(7, 0));
ASSERT_FALSE(wallet->use_fork_rules(8, 0));
ASSERT_TRUE(wallet->use_fork_rules(2, 10));
ASSERT_TRUE(wallet->use_fork_rules(4, 10));
ASSERT_TRUE(wallet->use_fork_rules(5, 10));
ASSERT_TRUE(wallet->use_fork_rules(6, 10));
// this will fail on rta testnet as we need to update block version there
ASSERT_TRUE(wallet->use_fork_rules(7, 10));
ASSERT_FALSE(wallet->use_fork_rules(8, 10));
}

0 comments on commit 920f8bf

Please sign in to comment.