From 2a3000dd40a1a18f71d1665e381c252a706f5ba8 Mon Sep 17 00:00:00 2001 From: Juhyung Park Date: Tue, 11 Aug 2020 10:18:38 +0900 Subject: [PATCH] Do not count validators who do not proposed in additional reward calculation In the additional reward calculation, we divide a validator's missed precommits by the validator's proposed count. Some validators may not proposed in a term. To avoid "divide by zero" error, ignore the validators who did not proposed any block. --- core/src/consensus/tendermint/engine.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/core/src/consensus/tendermint/engine.rs b/core/src/consensus/tendermint/engine.rs index a1bbc84fd1..6e15d3b5b9 100644 --- a/core/src/consensus/tendermint/engine.rs +++ b/core/src/consensus/tendermint/engine.rs @@ -471,6 +471,7 @@ fn give_additional_rewards Result<(), Error>>( ) -> Result<(), Error> { let sorted_validators = work_info .into_iter() + .filter(|(_, work)| work.proposed > 0) .map(|(address, info)| (address, Ratio::new(info.missed, info.proposed))) // When one sees the Ratio crate's Order trait implementation, he/she can easily realize that the // comparing routine is erroneous. It inversely compares denominators when the numerators are the same.