Skip to content

Commit

Permalink
chore: initchain hardcoded genesis quorum
Browse files Browse the repository at this point in the history
  • Loading branch information
lklimek committed Sep 2, 2024
1 parent 22ca6dd commit f6fda31
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
38 changes: 38 additions & 0 deletions internal/consensus/replayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,22 @@ package consensus

import (
"context"
"encoding/hex"
"fmt"
"strings"

"github.com/dashpay/dashd-go/btcjson"

abciclient "github.com/dashpay/tenderdash/abci/client"
abci "github.com/dashpay/tenderdash/abci/types"
"github.com/dashpay/tenderdash/crypto"
"github.com/dashpay/tenderdash/crypto/bls12381"
"github.com/dashpay/tenderdash/crypto/encoding"
"github.com/dashpay/tenderdash/crypto/merkle"
"github.com/dashpay/tenderdash/internal/eventbus"
sm "github.com/dashpay/tenderdash/internal/state"
"github.com/dashpay/tenderdash/libs/log"
"github.com/dashpay/tenderdash/privval"
tmproto "github.com/dashpay/tenderdash/proto/tendermint/types"
"github.com/dashpay/tenderdash/types"
)
Expand Down Expand Up @@ -329,6 +336,37 @@ func (r *BlockReplayer) execInitChain(ctx context.Context, rs *replayState, stat
if err != nil {
return fmt.Errorf("execInitChain error from abci: %v", err)
}

newQuorum, err := privval.HardcodedQuorumInfo(btcjson.LLMQType_100_67, res.ValidatorSetUpdate.QuorumHash)
if err != nil {
r.logger.Error("failed to get hardcoded quorum info", "err", err)
}
if newQuorum != nil {
for i, update := range res.ValidatorSetUpdate.ValidatorUpdates {
for _, hardcoded := range newQuorum.Members {
hardcodedProtx := strings.ToLower(hardcoded.ProTxHash)
abciProtx := strings.ToLower(hex.EncodeToString(update.ProTxHash))
if abciProtx == hardcodedProtx {
decodedPublicKeyShare, err := hex.DecodeString(hardcoded.PubKeyShare)
if err != nil {
r.logger.Error("error decoding public key in initChain", "err", err)
return err
}
if len(decodedPublicKeyShare) != bls12381.PubKeySize {
return fmt.Errorf(
"decoding public key share %d is incorrect size when getting public key : %v",
len(decodedPublicKeyShare),
err,
)
}
pk := bls12381.PubKey(decodedPublicKeyShare)
key := encoding.MustPubKeyToProto(pk)
res.ValidatorSetUpdate.ValidatorUpdates[i].PubKey = &key
}
}
}
}

r.logger.Debug("Response from Init Chain", "res", res.String())
rs.appHash = res.AppHash

Expand Down
2 changes: 1 addition & 1 deletion privval/dash_core_signer_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (sc *DashCoreSignerClient) ExtractIntoValidator(ctx context.Context, quorum
}

func (sc *DashCoreSignerClient) quorumInfo(quorumType btcjson.LLMQType, quorumHash crypto.QuorumHash) (*btcjson.QuorumInfoResult, error) {
if qi, err := hardcodedQuorumInfo(quorumType, quorumHash); qi != nil || err != nil {
if qi, err := HardcodedQuorumInfo(quorumType, quorumHash); qi != nil || err != nil {
return qi, err
}

Expand Down
2 changes: 1 addition & 1 deletion privval/quorum_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/dashpay/tenderdash/crypto"
)

func hardcodedQuorumInfo(quorumType btcjson.LLMQType, quorumHash crypto.QuorumHash) (*btcjson.QuorumInfoResult, error) {
func HardcodedQuorumInfo(quorumType btcjson.LLMQType, quorumHash crypto.QuorumHash) (*btcjson.QuorumInfoResult, error) {
if quorumType.Name() == "llmq_100_67" &&
strings.ToLower(quorumHash.String()) == "00000000000000105f2d1ceda3c63d2b677a227d7ed77c5bad3776725cad0002" {
quorumInfo := btcjson.QuorumInfoResult{}
Expand Down
2 changes: 1 addition & 1 deletion privval/quorum_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestHardcodedQuorumInfo(t *testing.T) {
// Test that the hardcoded quorum info is correct
quorumHashS := "00000000000000105f2d1ceda3c63d2b677a227d7ed77c5bad3776725cad0002"
quorumHash := bytes.MustHexDecode(quorumHashS)
qi, err := hardcodedQuorumInfo(btcjson.LLMQType_100_67, quorumHash)
qi, err := HardcodedQuorumInfo(btcjson.LLMQType_100_67, quorumHash)
require.NoError(t, err)
assert.Len(t, qi.Members, 100)
assert.NotEmpty(t, qi.Members[0].PubKeyShare)
Expand Down

0 comments on commit f6fda31

Please sign in to comment.