Skip to content
GitLab
  • Menu
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • hive hive
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 112
    • Issues 112
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 28
    • Merge requests 28
  • Deployments
    • Deployments
    • Releases
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
Collapse sidebar
  • hive
  • hivehive
  • Issues
  • #191
Closed
Open
Created Nov 01, 2021 by Howo@howoDeveloper

RC plugin not handling vesting withdrawal routes correctly

If you set a vesting withdrawal route, you end up with more current_mana than your maximum, I'm still investigating it, will probably include a fix as part of direct rc delegations

#ifdef IS_TEST_NET
#include <boost/test/unit_test.hpp>

#include <hive/chain/account_object.hpp>
#include <hive/chain/comment_object.hpp>
#include <hive/chain/database_exceptions.hpp>
#include <hive/chain/smt_objects.hpp>
#include <hive/protocol/hive_operations.hpp>

#include <hive/plugins/rc/rc_objects.hpp>
#include <hive/plugins/rc/rc_plugin.hpp>

#include "../db_fixture/database_fixture.hpp"

using namespace hive::chain;
using namespace hive::protocol;
using namespace hive::plugins::rc;

BOOST_FIXTURE_TEST_SUITE( rc_direct_delegation, clean_database_fixture )

BOOST_AUTO_TEST_CASE( rc_vesting_withdrawal_routes )
{
  try
  {
    ACTORS( (alice)(bob)(dave) )
    generate_block();

    // We are forced to do this because vests and rc values are bugged when executing tests
    db_plugin->debug_update( [=]( database& db )
    {
      db.modify( db.get_account( "alice" ), [&]( account_object& a )
      {
        a.vesting_shares = asset( 100, VESTS_SYMBOL );
      });

      db.modify( db.get< rc_account_object, by_name >( "alice" ), [&]( rc_account_object& rca )
      {
        rca.max_rc_creation_adjustment.amount.value = 10;
        rca.rc_manabar.current_mana = 110; // vests + max_rc_creation_adjustment
        rca.rc_manabar.last_update_time = db.head_block_time().sec_since_epoch();
        rca.last_max_rc = 110; // vests + max_rc_creation_adjustment
      });


      db.modify( db.get_account( "bob" ), [&]( account_object& a )
      {
        a.vesting_shares = asset( 0, VESTS_SYMBOL );
      });
      db.modify( db.get_account( "dave" ), [&]( account_object& a )
      {
        a.vesting_shares = asset( 0, VESTS_SYMBOL );
      });

      db.modify( db.get< rc_account_object, by_name >( "bob" ), [&]( rc_account_object& rca )
      {
        rca.max_rc_creation_adjustment.amount.value = 10;
        rca.rc_manabar.current_mana = 10;
        rca.rc_manabar.last_update_time = db.head_block_time().sec_since_epoch();
        rca.max_rc_creation_adjustment.amount.value = 10;
        rca.last_max_rc = 10;
      });
      db.modify( db.get< rc_account_object, by_name >( "dave" ), [&]( rc_account_object& rca )
      {
        rca.max_rc_creation_adjustment.amount.value = 10;
        rca.rc_manabar.current_mana = 10;
        rca.rc_manabar.last_update_time = db.head_block_time().sec_since_epoch();
        rca.max_rc_creation_adjustment.amount.value = 10;
        rca.last_max_rc = 10;
      });
    });

    BOOST_TEST_MESSAGE( "Setting up vesting routes" );

    {
      set_withdraw_vesting_route_operation op;
      op.from_account = "alice";
      op.to_account = "bob";
      op.percent = HIVE_1_PERCENT * 25;
      op.auto_vest = true;
      push_transaction( op, alice_private_key );
    }
    {
      set_withdraw_vesting_route_operation op;
      op.from_account = "alice";
      op.to_account = "alice";
      op.percent = HIVE_1_PERCENT * 50;
      op.auto_vest = true;
      push_transaction( op, alice_private_key );
    }
    {
      set_withdraw_vesting_route_operation op;
      op.from_account = "alice";
      op.to_account = "dave";
      op.percent = HIVE_1_PERCENT * 25;
      op.auto_vest = false;
      push_transaction( op, alice_private_key );
    }

    BOOST_TEST_MESSAGE( "Setting up withdrawal" );
    const auto& new_alice = db->get_account( "alice" );

    withdraw_vesting_operation op;
    op.account = "alice";
    op.vesting_shares = asset( new_alice.get_vesting().amount, VESTS_SYMBOL );
    push_transaction(op, alice_private_key);

    auto next_withdrawal = db->head_block_time() + HIVE_VESTING_WITHDRAW_INTERVAL_SECONDS;

    BOOST_TEST_MESSAGE( "Generating block up to first withdrawal" );
    generate_blocks( next_withdrawal - HIVE_BLOCK_INTERVAL );

      const rc_account_object& alice_rc_account1 = db->get< rc_account_object, by_name >( "alice" );
      idump((alice_rc_account1.last_max_rc)(alice_rc_account1.rc_manabar.current_mana));

    BOOST_TEST_MESSAGE( "Generating block to cause withdrawal" );
    generate_block();

    const rc_account_object& alice_rc_account = db->get< rc_account_object, by_name >( "alice" );
    // The RC should be 98: 110 - 8 x 2 + 4.
    // - 8 x 2 because of the vests withdrawal
    // + 4 because of the auto vest from the route
    BOOST_REQUIRE( alice_rc_account.last_max_rc == 98 );
    // This test fails, the current_mana comes out as 106
    // cause TBD, I think it could be tied to update_modified_accounts with a wierd interactions with auto vesting routes
    BOOST_REQUIRE( alice_rc_account.rc_manabar.current_mana == 98 );

  }
  FC_LOG_AND_RETHROW()
}


BOOST_AUTO_TEST_SUITE_END()

#endif
Assignee
Assign to
Time tracking