Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asset update issuer operation #599

Merged
merged 15 commits into from
Mar 7, 2018
Merged

Conversation

xeroc
Copy link
Member

@xeroc xeroc commented Jan 25, 2018

WARNING This is a PR without approval from the BTS holders (yet)
A formal BSIP will follow and a worker will be created for this one.
The BSIP
https://github.com/bitshares/bsips/blob/master/bsip-0029.md

I would still like to get feedback on this so that I can present a "final" product to the BTS holders.
For me, this is a playground to learn more about the internal work of BitShares (similar to the other pull request). Doing baby steps here and appreciate all your patients with me!

@@ -0,0 +1,4 @@
// bitshares-core #199 Require owner key for change of asset-issuer (new operation)
#ifndef HARDFORK_CORE_199_TIME
#define HARDFORK_CORE_199_TIME (fc::time_point_sec( 1512747600 ))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use a HF time in the far future in the PR

PUSH_TX( db, tx, ~0 );
};

if( db.head_block_time() <= HARDFORK_CORE_199_TIME )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test is deterministic, so you should know if head_block_time is before or after the hf. No need for the if.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you wish!

generate_blocks( HARDFORK_CORE_199_TIME );
while( db.head_block_time() <= HARDFORK_CORE_199_TIME )
{
generate_block();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use generate_blocks(time_point_sec, skip) to quickly jump to the hf time, skipping over the intermediate blocks. Otherwise these tests take ages.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I always wondered about that pattern and why the test takes so long.
Thanks for the remark, will change it momentarily

BOOST_TEST_MESSAGE( "Updating issuer to bob" );
update_issuer( test, alice, bob );

}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add tests to prove that the active key is not sufficient.

const asset_object& a = o.asset_to_update(d);
auto a_copy = a;
a_copy.validate();

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the two lines with a_copy, they are useless here.

@@ -262,6 +262,8 @@ void_result asset_update_evaluator::do_evaluate(const asset_update_operation& o)

if( o.new_issuer )
{
FC_ASSERT( d.head_block_time() < HARDFORK_CORE_199_TIME,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be consistent with the HF check, elsewhere you use <=

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So true .. I made it < consistently so that I don't need to generate an 'extra block' in the unittests

} else
FC_ASSERT( backing.get_id() == asset_id_type(),
"May not create a blockchain-controlled market asset which is not backed by CORE.");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For bonus points, refactor the parts that are identical with asset_update into a separate method.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure what the best way to do this would be.
Do I simply setup a new function that tests new_issuer, or is some other construct better?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I'd simply move the code block into a static function.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fear, this is too difficult for me and I need some guidance for C++. The major issue is that o is of type asset_update_operation or of type asset_update_issuer_operation. I am not sufficiently into templates and/or visitors to produce code that can do that. Could you give me a hint, please?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

KISS. ;-)
See latest commit.

@abitmore abitmore added this to the Future Consensus-Changing Release milestone Jan 25, 2018
@abitmore
Copy link
Member

Please rebase to targe hardfork branch.

@xeroc
Copy link
Member Author

xeroc commented Jan 30, 2018

@xeroc xeroc force-pushed the asset_update_issuer_operation branch from c44f25d to 05bd614 Compare January 30, 2018 14:43
@xeroc xeroc changed the base branch from develop to hardfork January 30, 2018 14:43
@xeroc
Copy link
Member Author

xeroc commented Jan 30, 2018

  • rebase
  • added cli_wallet command

@@ -251,6 +251,23 @@ void_result asset_fund_fee_pool_evaluator::do_apply(const asset_fund_fee_pool_op
return void_result();
} FC_CAPTURE_AND_RETHROW( (o) ) }

static void validate_new_issuer( const database& d, const asset_object& a, account_id_type new_issuer )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the static for?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That avoids exposing the symbol outside the compilation unit.

@xeroc
Copy link
Member Author

xeroc commented Feb 6, 2018

@oxarbitrage What's your opinion on this PR?
Please let me know if any other modification is needed!

"May not create a blockchain-controlled market asset which is not backed by CORE.");
}
FC_ASSERT( d.head_block_time() < HARDFORK_CORE_199_TIME,
"Since Hardfork #199, updating issuer requires the use of asset_change_issuer_operation.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

asset_change_issuer_operation should be asset_update_issuer_operation

void get_required_owner_authorities( flat_set<account_id_type>& a )const
{ a.insert( issuer ); }

void get_required_active_authorities( flat_set<account_id_type>& a )const
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be removed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can (IMHO) remove the get_required_active_authorities part, but the get_required_owner_authorities is crucial as we only want owner key to be able to sign that transction.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, not a big deal if keep it.

validate_new_issuer( d, a, o.new_issuer );

asset_to_update = &a;
FC_ASSERT( o.issuer == a.issuer, "", ("o.issuer", o.issuer)("a.issuer", a.issuer) );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The message is missing. The parameters followed won't show.

*
* @param symbol the name or id of the asset to update
* @param new_issuer if changing the asset's issuer, the name or id of the new issuer.
* null if you wish to remain the issuer of the asset
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

null here doesn't make sense.

@abitmore abitmore modified the milestones: Future Consensus-Changing Release, 201803 - Consensus Changing Release Feb 8, 2018
return get_account(name);
};

auto update_asset_issuer = [&](asset_object current,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change ALL object types in parameters of ALL functions to const references to avoid unnecessary data copy or unintended data modification, like this: const asset_object& current.

generate_blocks( HARDFORK_CORE_199_TIME );

BOOST_TEST_MESSAGE( "Can't change issuer if not my asset" );
GRAPHENE_REQUIRE_THROW( update_issuer( test, bob, alice, bob_active ), fc::exception );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like mentioned in another PR, references may become invalid after generated a block. Please change them to xxx_id(db).

@xeroc
Copy link
Member Author

xeroc commented Feb 13, 2018

With make && ./chain_test --run_test=operation_tests/update_uia_issuer, I don't see any failed unit tests here

Random number generator seeded to 1518526204
GRAPHENE_TESTING_GENESIS_TIMESTAMP is 1431700000
Running 1 test case...
3004478ms th_a       db_management.cpp:151         open                 ] Wiping object_database due to missing or wrong version
3004478ms th_a       object_database.cpp:93        wipe                 ] Wiping object database...
3004478ms th_a       object_database.cpp:95        wipe                 ] Done wiping object databse.
3004479ms th_a       object_database.cpp:106       open                 ] Opening object database from /tmp/graphene-tmp/9d11-0b0a-7b86-e1f2 ...
3004479ms th_a       object_database.cpp:111       open                 ] Done opening object database.
3049627ms th_a       db_management.cpp:191         close                ] Rewinding from 3 to 0
3049627ms th_a       db_management.cpp:201         close                ] Database close unexpected exception: {"code":10,"name":"assert_exception","message":"Assert Exception","stack":[{"context":{"level":"error","file":"fork_database.cpp","line":41,"method":"pop_block","hostname":"","thread_name":"th_a","timestamp":"2018-02-13T12:50:49"},"format":"_head: no blocks to pop","data":{}},{"context":{"level":"warn","file":"db_block.cpp","line":430,"method":"pop_block","hostname":"","thread_name":"th_a","timestamp":"2018-02-13T12:50:49"},"format":"","data":{}}]}

*** No errors detected

account_object new_issuer_account = get_account(*new_issuer);
new_issuer_account_id = new_issuer_account.id;
}
FC_THROW("The use of 'new_issuer' is no longer supported. Please use `update_asset_issuer' instead!");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change need to be done only after the hard fork, otherwise people will be unable to update issuer before the hard fork with this command via this cli_wallet. Perhaps not a big deal though.

Copy link
Member

@abitmore abitmore left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unit test code: dereferencing test after generated blocks is not safe.


BOOST_TEST_MESSAGE( "Updating issuer to bob" );
update_issuer( test, alice_id(db), bob_id(db), alice_owner );

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to test whether the update succeeded. E.G. test(db).issuer == bob_id

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And perhaps test other options didn't change.

const auto& test = create_user_issued_asset("UPDATEISSUER", alice_id(db), 0);

BOOST_TEST_MESSAGE( "can't use this operation before the hardfork" );
GRAPHENE_REQUIRE_THROW( update_issuer( test, alice_id(db), bob_id(db), alice_owner), fc::exception );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need tests for updating with proposals before and after hard fork.

@oxarbitrage
Copy link
Member

i think this pull can have conflicts with #572

i propose to merge 572 and see if we need to change anything here.

@oxarbitrage
Copy link
Member

need to resolve conflicts here now #572 was merged.

@xeroc
Copy link
Member Author

xeroc commented Feb 25, 2018

need to resolve conflicts here now #572 was merged.

Merged hardfork branch into this branch and resolved conflicts.

@@ -442,6 +442,7 @@ namespace graphene { namespace chain {
void validate()const;
};

/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is redundant.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shit, it seems I must be much much more careful when merging to resolve conflicts. On it ..

@@ -82,6 +82,11 @@ void_result proposal_create_evaluator::do_evaluate(const proposal_create_operati
{ // TODO: remove after HARDFORK_CORE_199_TIME has passed
graphene::chain::impl::hf_199_visitor hf_199;
hf_199( o );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this won't compile.. Lack of a }.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for that

@@ -92,6 +92,19 @@ namespace graphene { namespace chain {
}
};

class fee_helper<asset_claim_pool_operation> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe lack of a template<> above this line?

@@ -289,7 +296,7 @@ void_result asset_update_evaluator::do_evaluate(const asset_update_operation& o)
"Flag change is forbidden by issuer permissions");

asset_to_update = &a;
FC_ASSERT( o.issuer == a.issuer, "", ("o.issuer", o.issuer)("a.issuer", a.issuer) );
FC_ASSERT( o.issuer == a.issuer, "Incorrect issuer for asset! (${o.issuer} != ${a.issuer})", ("o.issuer", o.issuer)("a.issuer", a.issuer) );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is too long, better add a line break.

validate_new_issuer( d, a, o.new_issuer );

asset_to_update = &a;
FC_ASSERT( o.issuer == a.issuer, "Incorrect issuer for asset! (${o.issuer} != ${a.issuer})", ("o.issuer", o.issuer)("a.issuer", a.issuer) );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is too long, better add a line break.

@@ -152,16 +163,24 @@ namespace graphene { namespace chain {
void_result do_apply( const asset_claim_fees_operation& o );
};

class asset_claim_pool_evaluator : public evaluator<asset_claim_pool_evaluator>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not remove this class.

void asset_update_issuer_operation::validate()const
{
FC_ASSERT( fee.amount >= 0 );
FC_ASSERT(issuer != new_issuer);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two lines have different code styles, looks strange.

Copy link
Member

@oxarbitrage oxarbitrage left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems all good to me now. it will be great to have test case for the cli wallets commands. we need to merge this for it #675

@abitmore abitmore merged commit 1944754 into hardfork Mar 7, 2018
@abitmore abitmore deleted the asset_update_issuer_operation branch March 17, 2018 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants