Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

fix 7600 double confirm after changing sign key #7601

Merged
merged 4 commits into from
Jul 19, 2019
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 7 additions & 23 deletions plugins/producer_plugin/producer_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,28 +280,9 @@ class producer_plugin_impl : public std::enable_shared_from_this<producer_plugin
}
} ) );

// since the watermark has to be set before a block is created, we are looking into the future to
// determine the new schedule to identify producers that have become active
chain::controller& chain = chain_plug->chain();
const auto hbn = bsp->block_num;
auto new_pbhs = bsp->next(bsp->header.timestamp.next(), 0);

// for newly installed producers we can set their watermarks to the block they became active
if( bsp->active_schedule.version != new_pbhs.active_schedule.version ) {
flat_set<account_name> new_producers;
new_producers.reserve(new_pbhs.active_schedule.producers.size());
for( const auto& p: new_pbhs.active_schedule.producers) {
if (_producers.count(p.producer_name) > 0)
new_producers.insert(p.producer_name);
}

for( const auto& p: bsp->active_schedule.producers) {
new_producers.erase(p.producer_name);
}

for (const auto& new_producer: new_producers) {
_producer_watermarks[new_producer] = hbn;
}
// simplify handling of watermark in on_block
if (bsp->block) {
_producer_watermarks[bsp->block->producer] = bsp->block_num;
arhag marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down Expand Up @@ -1352,9 +1333,12 @@ producer_plugin_impl::start_block_result producer_plugin_impl::start_block() {
if (currrent_watermark_itr != _producer_watermarks.end()) {
auto watermark = currrent_watermark_itr->second;
if (watermark < hbs->block_num) {
blocks_to_confirm = std::min<uint16_t>(std::numeric_limits<uint16_t>::max(), (uint16_t)(hbs->block_num - watermark));
blocks_to_confirm = (uint16_t)(std::min<uint32_t>(std::numeric_limits<uint16_t>::max(), (uint32_t)(hbs->block_num - watermark)));
}
}

// can not confirm irreversible blocks
blocks_to_confirm = (uint16_t)(std::min<uint32_t>(blocks_to_confirm, (uint32_t)(hbs->block_num - hbs->dpos_irreversible_blocknum)));
}

chain.abort_block();
Expand Down