Skip to content

Conversation

@mvandeberg
Copy link
Contributor

PR for #997

const auto& delegation_idx = get_index< vesting_delegation_index, by_id >();
auto itr = delegation_idx.begin();

while( itr != delegation_idx.end() )
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be worth optimizing this using Boost's erase(iterator first,iterator last) if we order by delegated vesting shares, or just erase(const key_type& x) if we keep vesting shares a member in the index.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We do not track that index. This is the safe way to implement the fix. The 0 delegation objects should have no effect on consensus. After the hardfork we can change the 0.17 behavior to match 0.19 and verify that not creating 0 delegation objects has no effect. In which case we can delete this logic entirely.

@theoreticalbts
Copy link
Contributor

You have to be really careful about concurrently modifying collections. Let's use a lower_bound() on the ID to get a completely fresh iterator after that remove().

Let's add a TODO comment noting how this can be simplified after the HF passes.

Whether zero delegations are represented by a zero delegation object, or by the lack of a delegation object, is a non-consensus implementation detail. So I'd personally avoid implementing this as a hardfork. But this implementation is probably a little safer, in case there is some consensus difference I overlooked, it won't split the network.

@mvandeberg
Copy link
Contributor Author

We use the same pattern here.

@mvandeberg mvandeberg force-pushed the 997-0-delegation-objects branch 3 times, most recently from 85b6398 to 04abde7 Compare May 19, 2017 21:24
@theoreticalbts
Copy link
Contributor

The evaluator check is:

if( hf19 && amount > 0 || !hf19 )

You can simplify any expression of the form (a & b) | !a, it distributes to (a|!a) & (b|!a), the first term is tautological so it simplifies further to b|!a. We cannot always apply this simplification with short circuit logical operators (e.g. when evaluation of b is undefined or will cause side effects when a is false), but we can do so here (o.delegation_amount is always defined). So a clearer test is

if( (amount > 0) || !hf19 )

Also, for( auto itr : remove ) should be for( const delegation_object* object_ptr : remove ) for two reasons:

  • Code is clearer if you avoid auto
  • These are pointers to objects, not iterators being dereferenced

@mvandeberg mvandeberg force-pushed the 997-0-delegation-objects branch from 04abde7 to b3421c1 Compare May 19, 2017 21:42
@mvandeberg mvandeberg merged commit deb0dac into master May 19, 2017
@mvandeberg mvandeberg deleted the 997-0-delegation-objects branch May 19, 2017 22:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants