Skip to content

Commit d6d759f

Browse files
author
ABW
committed
change interface of on_cashout to take comment_object and comment_cashout_object since caller needs to have access to them
Previous interface suggested you could take passed values from places other than existing chain objects.
1 parent d55fdd8 commit d6d759f

File tree

4 files changed

+21
-23
lines changed

4 files changed

+21
-23
lines changed

libraries/chain/database.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -663,8 +663,9 @@ void database::remove_old_cashouts()
663663
while( itr != idx.end() )
664664
{
665665
const auto& current = *itr;
666+
const auto& comment = get_comment( current );
666667
++itr;
667-
get_comments_handler()->on_cashout( current.get_comment_id(), current.get_author_id(), current.get_permlink() );
668+
get_comments_handler()->on_cashout( comment, current );
668669
remove( current );
669670
}
670671
}
@@ -2657,6 +2658,12 @@ void database::process_comment_cashout()
26572658
funds[ fund_id ].hive_awarded += cashout_comment_helper( ctx, _comment, *_current,
26582659
find_comment_cashout_ex( _comment ), forward_curation_remainder );
26592660
++count;
2661+
2662+
if( has_hardfork( HIVE_HARDFORK_0_19 ) )
2663+
{
2664+
get_comments_handler()->on_cashout( _comment, *_current );
2665+
remove( *_current );
2666+
}
26602667
}
26612668
else
26622669
{
@@ -2685,11 +2692,6 @@ void database::process_comment_cashout()
26852692
}
26862693
}
26872694

2688-
if( has_hardfork( HIVE_HARDFORK_0_19 ) )
2689-
{
2690-
get_comments_handler()->on_cashout( _current->get_comment_id(), _current->get_author_id(), _current->get_permlink() );
2691-
remove( *_current );
2692-
}
26932695
_current = cidx.begin();
26942696
}
26952697
if( _benchmark_dumper.is_enabled() && count )

libraries/chain/external_storage/rocksdb_storage_processor.cpp

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,31 +27,27 @@ rocksdb_storage_processor::~rocksdb_storage_processor()
2727
{
2828
}
2929

30-
void rocksdb_storage_processor::on_cashout( const comment_id_type& comment_id, const account_id_type& account_id, const std::string& permlink )
30+
void rocksdb_storage_processor::on_cashout( const comment_object& _comment, const comment_cashout_object& _comment_cashout )
3131
{
32-
auto& _account = db.get_account( account_id );
33-
auto _found = db.find_comment( comment_id );
34-
35-
FC_ASSERT( _found, "Comment ${author}/${permlink} has to exist", ("permlink", permlink)("author", _account.get_name()) );
3632

3733
const auto& _volatile_idx = db.get_index< volatile_comment_index, by_permlink >();
38-
auto _vfound = _volatile_idx.find( _found->get_author_and_permlink_hash() );
39-
40-
if( _vfound != _volatile_idx.end() )
41-
return;
34+
FC_ASSERT( _volatile_idx.find( _comment.get_author_and_permlink_hash() ) == _volatile_idx.end(),
35+
"Incorrect duplicate archiving of the same comment" ); //ABW: because volatile_comment_index is under undo, this should never happen
4236

4337
#ifdef DBG_INFO
38+
auto& _account = db.get_account( _comment_cashout.get_author_id() );
4439
ilog( "head: ${head} lib: ${lib} Store a comment with hash: ${hash}, with author/permlink: ${author}/${permlink}",
45-
("hash", comment_object::compute_author_and_permlink_hash( _account.get_id(), permlink ))
46-
("permlink", permlink)("author", _account.get_name())("head", db.head_block_num())("lib", db.get_last_irreversible_block_num()) );
40+
( "head", db.head_block_num() )( "lib", db.get_last_irreversible_block_num() )
41+
( "hash", _comment.get_author_and_permlink_hash() )
42+
( "author", _account.get_name() )( "permlink", _comment_cashout.get_permlink() ) );
4743
#endif
4844

4945
db.create< volatile_comment_object >( [&]( volatile_comment_object& o )
5046
{
51-
o.comment_id = _found->get_id();
52-
o.parent_comment = _found->get_parent_id();
53-
o.depth = _found->get_depth();
54-
o.set_author_and_permlink_hash( _found->get_author_and_permlink_hash() );
47+
o.comment_id = _comment.get_id();
48+
o.parent_comment = _comment.get_parent_id();
49+
o.depth = _comment.get_depth();
50+
o.set_author_and_permlink_hash( _comment.get_author_and_permlink_hash() );
5551

5652
o.block_number = db.head_block_num();
5753
});

libraries/chain/include/hive/chain/external_storage/comments_handler.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class comments_handler
1414

1515
using ptr = std::shared_ptr<comments_handler>;
1616

17-
virtual void on_cashout( const comment_id_type& comment_id, const account_id_type& account_id, const std::string& permlink ) = 0;
17+
virtual void on_cashout( const comment_object& _comment, const comment_cashout_object& _comment_cashout ) = 0;
1818
virtual void on_irreversible_block( uint32_t block_num ) = 0;
1919

2020
virtual comment get_comment( const account_id_type& author, const std::string& permlink, bool comment_is_required ) const = 0;

libraries/chain/include/hive/chain/external_storage/rocksdb_storage_processor.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class rocksdb_storage_processor: public external_storage_processor
3232
rocksdb_storage_processor( const abstract_plugin& plugin, database& db, const bfs::path& blockchain_storage_path, const bfs::path& storage_path, appbase::application& app, bool destroy_on_startup );
3333
virtual ~rocksdb_storage_processor();
3434

35-
void on_cashout( const comment_id_type& comment_id, const account_id_type& account_id, const std::string& permlink ) override;
35+
void on_cashout( const comment_object& _comment, const comment_cashout_object& _comment_cashout ) override;
3636
void on_irreversible_block( uint32_t block_num ) override;
3737

3838
comment get_comment( const account_id_type& author, const std::string& permlink, bool comment_is_required ) const override;

0 commit comments

Comments
 (0)