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

Bug fix on dkg validator indices in aeon details #67

Merged
merged 1 commit into from
May 22, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
15 changes: 4 additions & 11 deletions beacon/aeon_details.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,13 @@ func newAeonDetails(newPrivValidator types.PrivValidator, valHeight int64,
if startHeight <= 0 || endHeight < startHeight {
panic(fmt.Errorf("aeonDetails invalid start/end height"))
}
qual := make([]*types.Validator, 0)
for index := 0; index < len(validators.Validators); index++ {
if aeonKeys.InQual(uint(index)) {
qual = append(qual, validators.Validators[index])
}
}
newVals := types.NewValidatorSet(qual)
if aeonKeys.CanSign() {
if newPrivValidator == nil {
panic(fmt.Errorf("aeonDetails has DKG keys but no privValidator"))
}
index, _ := newVals.GetByAddress(newPrivValidator.GetPubKey().Address())
if index < 0 {
panic(fmt.Errorf("aeonDetails has DKG keys but not in validators"))
index, _ := validators.GetByAddress(newPrivValidator.GetPubKey().Address())
if index < 0 || !aeonKeys.InQual(uint(index)) {
panic(fmt.Errorf("aeonDetails has DKG keys but not in validators or qual"))
}
if !aeonKeys.CheckIndex(uint(index)) {
i := 0
Expand All @@ -84,7 +77,7 @@ func newAeonDetails(newPrivValidator types.PrivValidator, valHeight int64,
ad := &aeonDetails{
privValidator: newPrivValidator,
validatorHeight: valHeight,
validators: newVals,
validators: types.NewValidatorSet(validators.Validators),
aeonExecUnit: aeonKeys,
threshold: validators.Size()/2 + 1,
Start: startHeight,
Expand Down
6 changes: 1 addition & 5 deletions beacon/aeon_exec_unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,16 @@ AeonExecUnit::AeonExecUnit(std::string generator, DKGKeyInformation keys, std::s
, generator_{std::move(generator)}
, qual_{std::move(qual)}
{
assert(aeon_keys_.public_key_shares.size() == qual_.size());
CheckKeys();
}

AeonExecUnit::AeonExecUnit(std::string const &generator, DKGKeyInformation const &keys, std::vector<CabinetIndex> const &qual)
{
std::set<CabinetIndex> qual_set;
for (auto const &index : qual) {
qual_set.insert(index);
qual_.insert(index);
}
aeon_keys_ = keys;
generator_ = generator;
qual_ = std::move(qual_set);
assert(aeon_keys_.public_key_shares.size() == qual_.size());
CheckKeys();
}

Expand Down
4 changes: 2 additions & 2 deletions beacon/beacon_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,9 +502,9 @@ AeonExecUnit BeaconManager::GetDkgOutput() const
auto output = DKGKeyInformation();
output.group_public_key = public_key_.ToString();
output.private_key = secret_share_.ToString();
for (auto elem : qual_)
for (auto elem : public_key_shares_)
{
output.public_key_shares.push_back(public_key_shares_[elem].ToString());
output.public_key_shares.push_back(elem.ToString());
}
AeonExecUnit aeon{GetGroupG().ToString(), output, qual_};
return aeon;
Expand Down
5 changes: 1 addition & 4 deletions beacon/dkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@ func (dkg *DistributedKeyGeneration) OnBlock(blockHeight int64, trxs []*types.DK
dkg.checkTransition(blockHeight)
return
}
dkg.Logger.Debug("OnBlock: received transactions", "height", blockHeight, "numTrx", len(trxs))
// Process transactions
for _, trx := range trxs {
// Decode transaction
Expand Down Expand Up @@ -406,8 +405,6 @@ func (dkg *DistributedKeyGeneration) checkTransition(blockHeight int64) {
dkg.states[dkg.currentState].onEntry()
// Run check transition again in case we can proceed to the next state already
dkg.checkTransition(blockHeight)
} else {
dkg.Logger.Debug("checkTransition: no state change", "height", blockHeight, "state", dkg.currentState, "iteration", dkg.dkgIteration)
}
}

Expand Down Expand Up @@ -583,7 +580,7 @@ func (dkg *DistributedKeyGeneration) receivedAllDryRuns() bool {

func (dkg *DistributedKeyGeneration) checkDryRuns() bool {
encodedOutput := ""
requiredPassSize := uint(2 * dkg.validators.Size() / 3)
requiredPassSize := uint((2 * dkg.validators.Size()) / 3)
if requiredPassSize < dkg.threshold {
requiredPassSize = dkg.threshold
}
Expand Down
4 changes: 2 additions & 2 deletions beacon/entropy_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func (entropyGenerator *EntropyGenerator) changeKeys() bool {
func (entropyGenerator *EntropyGenerator) applyComputedEntropy(height int64, entropy types.ThresholdSignature) {
// Should not be called in entropy generator is not running
if !entropyGenerator.isSigningEntropy() {
panic(fmt.Errorf("applyEntropyShare while entropy generator stopped"))
panic(fmt.Errorf("applyComputedEntropy while entropy generator stopped"))
}
entropyGenerator.mtx.Lock()
defer entropyGenerator.mtx.Unlock()
Expand Down Expand Up @@ -344,7 +344,7 @@ func (entropyGenerator *EntropyGenerator) getEntropyShares(height int64) map[uin
}

func (entropyGenerator *EntropyGenerator) validInputs(height int64, index int) error {
if index < 0 {
if index < 0 || !entropyGenerator.aeon.aeonExecUnit.InQual(uint(index)) {
return fmt.Errorf("invalid validator index %v", index)
}
if height != entropyGenerator.lastBlockHeight+1 {
Expand Down