Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backport: catch up with the latest commits from v0.11 to v0.12 #631

Merged
merged 5 commits into from
May 4, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/markdown-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Install dependencies
run: sudo apt-get update && sudo apt-get install -y libpcap-dev
- name: Lint Code Base
uses: github/super-linter@v4
uses: github/super-linter@v5
env:
VALIDATE_ALL_CODEBASE: true
DEFAULT_BRANCH: master
Expand Down
43 changes: 29 additions & 14 deletions dash/llmq/llmq.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,29 @@ import (
var (
errThresholdInvalid = errors.New("threshold must be greater than 0")
errKeySharesNotGenerated = errors.New("to initialize shares you must generate the keys")

quorumParams = map[btcjson.LLMQType]struct {
Members int
Threshold int
}{
btcjson.LLMQType_50_60: {50, 30},
btcjson.LLMQType_400_60: {400, 240},
btcjson.LLMQType_400_85: {400, 340},
btcjson.LLMQType_100_67: {100, 67},
btcjson.LLMQType_60_75: {60, 45},
btcjson.LLMQType_25_67: {25, 17},
btcjson.LLMQType_DEVNET: {12, 6},
btcjson.LLMQType_TEST_V17: {3, 2},
btcjson.LLMQType_TEST_DIP0024: {4, 2},
btcjson.LLMQType_TEST_INSTANTSEND: {3, 2},
btcjson.LLMQType_DEVNET_DIP0024: {8, 4},
btcjson.LLMQType_TEST_PLATFORM: {3, 2},
btcjson.LLMQType_DEVNET_PLATFORM: {12, 8},

// temporarily commented out due to the default behavior where if llmq type is not found
// then we take the length of the actual validators as members
//btcjson.LLMQType_TEST: {3, 2},
}
)

type optionFunc func(c *llmqConfig)
Expand All @@ -43,24 +66,16 @@ type blsLLMQData struct {
pkShares []*bls.G1Element
}

// QuorumProps returns corresponding LLMQ parameters
// QuorumParams returns corresponding LLMQ parameters
// the first integer is an expected size of quorum
// the second is an expected threshold
// the third parameter is an error, it returns in a case if quorumType is not supported
func QuorumProps(quorumType btcjson.LLMQType) (int, int, error) {
switch quorumType {
case btcjson.LLMQType_50_60:
return 50, 30, nil
case btcjson.LLMQType_400_60:
return 400, 240, nil
case btcjson.LLMQType_400_85:
return 400, 340, nil
case btcjson.LLMQType_100_67:
return 100, 67, nil
case 101:
return 10, 6, nil
func QuorumParams(quorumType btcjson.LLMQType) (int, int, error) {
params, ok := quorumParams[quorumType]
if !ok {
return 0, 0, fmt.Errorf("quorumType '%d' doesn't match with available", quorumType)
}
return 0, 0, fmt.Errorf("quorumType '%d' doesn't match with available", quorumType)
return params.Members, params.Threshold, nil
}

// MustGenerate generates long-living master node quorum, but panics if a got error
Expand Down
4 changes: 2 additions & 2 deletions types/validator_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ func (vals *ValidatorSet) QuorumVotingThresholdPower() int64 {

// QuorumTypeMemberCount returns a number of validators for a quorum by a type
func (vals *ValidatorSet) QuorumTypeMemberCount() int {
size, _, err := llmq.QuorumProps(vals.QuorumType)
size, _, err := llmq.QuorumParams(vals.QuorumType)
if err != nil {
return len(vals.Validators)
}
Expand All @@ -520,7 +520,7 @@ func (vals *ValidatorSet) QuorumTypeMemberCount() int {

// QuorumTypeThresholdCount returns a threshold number for a quorum by a type
func (vals *ValidatorSet) QuorumTypeThresholdCount() int {
_, threshold, err := llmq.QuorumProps(vals.QuorumType)
_, threshold, err := llmq.QuorumParams(vals.QuorumType)
if err != nil {
return len(vals.Validators)*2/3 + 1
}
Expand Down