-
Notifications
You must be signed in to change notification settings - Fork 646
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
Conversation
@@ -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 )) |
There was a problem hiding this comment.
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
tests/tests/operation_tests.cpp
Outdated
PUSH_TX( db, tx, ~0 ); | ||
}; | ||
|
||
if( db.head_block_time() <= HARDFORK_CORE_199_TIME ) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you wish!
tests/tests/operation_tests.cpp
Outdated
generate_blocks( HARDFORK_CORE_199_TIME ); | ||
while( db.head_block_time() <= HARDFORK_CORE_199_TIME ) | ||
{ | ||
generate_block(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
tests/tests/operation_tests.cpp
Outdated
BOOST_TEST_MESSAGE( "Updating issuer to bob" ); | ||
update_issuer( test, alice, bob ); | ||
|
||
} |
There was a problem hiding this comment.
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.
libraries/chain/asset_evaluator.cpp
Outdated
const asset_object& a = o.asset_to_update(d); | ||
auto a_copy = a; | ||
a_copy.validate(); | ||
|
There was a problem hiding this comment.
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.
libraries/chain/asset_evaluator.cpp
Outdated
@@ -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, |
There was a problem hiding this comment.
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 <=
There was a problem hiding this comment.
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."); | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
KISS. ;-)
See latest commit.
Please rebase to targe |
For reference: Forum discussion: |
c44f25d
to
05bd614
Compare
|
@@ -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 ) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
@oxarbitrage What's your opinion on this PR? |
libraries/chain/asset_evaluator.cpp
Outdated
"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."); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
libraries/chain/asset_evaluator.cpp
Outdated
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) ); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
tests/tests/operation_tests.cpp
Outdated
return get_account(name); | ||
}; | ||
|
||
auto update_asset_issuer = [&](asset_object current, |
There was a problem hiding this comment.
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
.
tests/tests/operation_tests.cpp
Outdated
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 ); |
There was a problem hiding this comment.
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)
.
…and use const references
With
|
libraries/wallet/wallet.cpp
Outdated
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!"); |
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
tests/tests/operation_tests.cpp
Outdated
|
||
BOOST_TEST_MESSAGE( "Updating issuer to bob" ); | ||
update_issuer( test, alice_id(db), bob_id(db), alice_owner ); | ||
|
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
tests/tests/operation_tests.cpp
Outdated
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 ); |
There was a problem hiding this comment.
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.
i think this pull can have conflicts with #572 i propose to merge 572 and see if we need to change anything here. |
need to resolve conflicts here now #572 was merged. |
Merged |
@@ -442,6 +442,7 @@ namespace graphene { namespace chain { | |||
void validate()const; | |||
}; | |||
|
|||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is redundant.
There was a problem hiding this comment.
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 ); |
There was a problem hiding this comment.
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 }
.
There was a problem hiding this comment.
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> { |
There was a problem hiding this comment.
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?
libraries/chain/asset_evaluator.cpp
Outdated
@@ -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) ); |
There was a problem hiding this comment.
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.
libraries/chain/asset_evaluator.cpp
Outdated
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) ); |
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this 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
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!