Skip to content

Commit

Permalink
Check if tx set is in nominated tx sets
Browse files Browse the repository at this point in the history
In `combineCandidates` it has been seen to cause runtime range error
resulting in SCP fatal crash. It should not happen so log an error when
it does to help find out why.
  • Loading branch information
hewison-chris authored and omerfirmak committed Mar 24, 2022
1 parent dde2824 commit d4f5cb0
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions source/agora/consensus/protocol/Nominator.d
Original file line number Diff line number Diff line change
Expand Up @@ -1520,26 +1520,33 @@ extern(D):
auto candidate = cand.getValue();
auto data = deserializeFull!ConsensusData(candidate[]);
log.trace("Consensus data: {}", data.prettify);

Amount total_rate;
foreach (const ref tx_hash; this.ledger.nominated_tx_sets[data.tx_set])
if (auto tx_set = data.tx_set in this.ledger.nominated_tx_sets)
{
Amount rate;
auto errormsg = this.ledger.getTxFeeRate(tx_hash, rate);
if (errormsg == NodeLedger.InvalidConsensusDataReason.NotInPool)
continue; // most likely a CoinBase Transaction
else if (errormsg)
assert(0);
total_rate += rate;
}
Amount total_rate;
foreach (const ref tx_hash; *tx_set)
{
Amount rate;
auto errormsg = this.ledger.getTxFeeRate(tx_hash, rate);
if (errormsg == NodeLedger.InvalidConsensusDataReason.NotInPool)
continue; // most likely a CoinBase Transaction
else if (errormsg)
assert(0);
total_rate += rate;
}

CandidateHolder candidate_holder =
CandidateHolder candidate_holder =
{
consensus_data: data,
hash: data.hashFull(),
total_rate: total_rate,
};
candidate_holders ~= candidate_holder;
}
else
{
consensus_data: data,
hash: data.hashFull(),
total_rate: total_rate,
};
candidate_holders ~= candidate_holder;
log.error("{}: Missing tx set with hash {} in nominated tx sets {}",
__FUNCTION__, data.tx_set, this.ledger.nominated_tx_sets);
}
}

auto chosen_consensus_data = candidate_holders.sort().front;
Expand Down

0 comments on commit d4f5cb0

Please sign in to comment.