change all string utility for bls

pull/1006/head
Rongjian Lan 6 years ago
parent e495a46fed
commit 9a74575bae
  1. 2
      cmd/client/txgen/main.go
  2. 2
      cmd/client/wallet/main.go
  3. 4
      cmd/harmony/main.go
  4. 2
      consensus/consensus.go
  5. 2
      consensus/consensus_service.go
  6. 2
      consensus/consensus_v2.go
  7. 12
      consensus/view_change.go
  8. 4
      core/resharding.go
  9. 4
      crypto/bls/bls_test.go
  10. 2
      drand/drand_test.go
  11. 4
      internal/blsgen/lib.go
  12. 2
      node/node_genesis.go

@ -111,7 +111,7 @@ func setUpTXGen() *node.Node {
endIdx := startIdx + core.GenesisShardSize
for _, acct := range genesis.GenesisAccounts[startIdx:endIdx] {
secretKey := bls2.SecretKey{}
if err := secretKey.SetHexString(acct.BlsPriKey); err != nil {
if err := secretKey.DeserializeHexStr(acct.BlsPriKey); err != nil {
_, _ = fmt.Fprintf(os.Stderr, "cannot parse secret key: %v\n",
err)
os.Exit(1)

@ -357,7 +357,7 @@ func processBlsgenCommand() {
privateKey, fileName := blsgen.GenBlsKeyWithPassPhrase(password)
publickKey := privateKey.GetPublicKey()
fmt.Printf("Bls private key: %s\n", privateKey.GetHexString())
fmt.Printf("Bls private key: %s\n", privateKey.SerializeToHexStr())
fmt.Printf("Bls serialized public key: %s\n", publickKey.SerializeToHexStr())
fmt.Printf("File storing the ENCRYPTED private key with your passphrase: %s\n", fileName)
}

@ -240,14 +240,14 @@ func createGlobalConfig() *nodeconfig.ConfigType {
consensusPriKey := &bls.SecretKey{}
if *isGenesis {
err := consensusPriKey.SetHexString(genesisAccount.BlsPriKey)
err := consensusPriKey.DeserializeHexStr(genesisAccount.BlsPriKey)
if err != nil {
panic(fmt.Errorf("generate key error"))
}
} else {
// NewNode won't work
/*
err := consensusPriKey.SetHexString(genesis.NewNodeAccounts[])
err := consensusPriKey.DeserializeHexStr(genesis.NewNodeAccounts[])
if err != nil {
panic(fmt.Errorf("generate key error"))
}

@ -377,7 +377,7 @@ func NewGenesisStakeInfoFinder() (*GenesisStakeInfoFinder, error) {
for idx, account := range genesis.GenesisAccounts {
blsSecretKeyHex := account.BlsPriKey
blsSecretKey := bls.SecretKey{}
if err := blsSecretKey.SetHexString(blsSecretKeyHex); err != nil {
if err := blsSecretKey.DeserializeHexStr(blsSecretKeyHex); err != nil {
return nil, ctxerror.New("cannot convert BLS secret key",
"accountIndex", idx,
).WithCause(err)

@ -555,7 +555,7 @@ func (consensus *Consensus) checkViewID(msg *PbftMessage) error {
consensus.LeaderPubKey = msg.SenderPubkey
consensus.ignoreViewIDCheck = false
consensus.consensusTimeout[timeoutConsensus].Start()
utils.GetLogger().Debug("viewID and leaderKey override", "viewID", consensus.viewID, "leaderKey", consensus.LeaderPubKey.GetHexString()[:20])
utils.GetLogger().Debug("viewID and leaderKey override", "viewID", consensus.viewID, "leaderKey", consensus.LeaderPubKey.SerializeToHexStr()[:20])
utils.GetLogger().Debug("start consensus timeout", "viewID", consensus.viewID, "block", consensus.blockNum)
return nil
} else if msg.ViewID > consensus.viewID {

@ -117,7 +117,7 @@ func (consensus *Consensus) onAnnounce(msg *msg_pb.Message) {
return
}
if !senderKey.IsEqual(consensus.LeaderPubKey) && consensus.mode.Mode() == Normal && !consensus.ignoreViewIDCheck {
utils.GetLogger().Warn("onAnnounce senderKey not match leader PubKey", "senderKey", senderKey.GetHexString()[:10], "leaderKey", consensus.LeaderPubKey.GetHexString()[:10])
utils.GetLogger().Warn("onAnnounce senderKey not match leader PubKey", "senderKey", senderKey.SerializeToHexStr()[:10], "leaderKey", consensus.LeaderPubKey.SerializeToHexStr()[:10])
return
}
if err = verifyMessageSig(senderKey, msg); err != nil {

@ -121,7 +121,7 @@ func (consensus *Consensus) switchPhase(desirePhase PbftPhase, override bool) {
func (consensus *Consensus) GetNextLeaderKey() *bls.PublicKey {
idx := consensus.getIndexOfPubKey(consensus.LeaderPubKey)
if idx == -1 {
utils.GetLogInstance().Warn("GetNextLeaderKey: currentLeaderKey not found", "key", consensus.LeaderPubKey.GetHexString())
utils.GetLogInstance().Warn("GetNextLeaderKey: currentLeaderKey not found", "key", consensus.LeaderPubKey.SerializeToHexStr())
}
idx = (idx + 1) % len(consensus.PublicKeys)
return consensus.PublicKeys[idx]
@ -173,7 +173,7 @@ func (consensus *Consensus) startViewChange(viewID uint32) {
diff := viewID - consensus.viewID
duration := time.Duration(int64(diff) * int64(viewChangeDuration))
utils.GetLogInstance().Info("startViewChange", "viewID", viewID, "timeoutDuration", duration, "nextLeader", consensus.LeaderPubKey.GetHexString()[:10])
utils.GetLogInstance().Info("startViewChange", "viewID", viewID, "timeoutDuration", duration, "nextLeader", consensus.LeaderPubKey.SerializeToHexStr()[:10])
msgToSend := consensus.constructViewChangeMessage()
consensus.host.SendMessageToGroups([]p2p.GroupID{p2p.NewGroupIDByShardID(p2p.ShardID(consensus.ShardID))}, host.ConstructP2pMessage(byte(17), msgToSend))
@ -371,7 +371,7 @@ func (consensus *Consensus) onViewChange(msg *msg_pb.Message) {
consensus.consensusTimeout[timeoutViewChange].Stop()
consensus.consensusTimeout[timeoutConsensus].Start()
utils.GetLogger().Debug("new leader start consensus timeout and stop view change timeout", "viewID", consensus.viewID, "block", consensus.blockNum, "viewChangingID", consensus.mode.ViewID())
utils.GetLogger().Debug("I am the new leader", "myKey", consensus.PubKey.GetHexString()[:20], "viewID", consensus.viewID, "block", consensus.blockNum)
utils.GetLogger().Debug("I am the new leader", "myKey", consensus.PubKey.SerializeToHexStr()[:20], "viewID", consensus.viewID, "block", consensus.blockNum)
}
utils.GetLogInstance().Debug("onViewChange", "numSigs", len(consensus.viewIDSigs), "needed", consensus.Quorum())
@ -413,7 +413,7 @@ func (consensus *Consensus) onNewView(msg *msg_pb.Message) {
}
if !m3Sig.VerifyHash(m3Mask.AggregatePublic, viewIDHash) {
utils.GetLogInstance().Warn("onNewView unable to verify aggregated signature of m3 payload", "m3Sig", m3Sig.GetHexString()[:10], "m3Mask", m3Mask.Bitmap, "viewID", recvMsg.ViewID)
utils.GetLogInstance().Warn("onNewView unable to verify aggregated signature of m3 payload", "m3Sig", m3Sig.SerializeToHexStr()[:10], "m3Mask", m3Mask.Bitmap, "viewID", recvMsg.ViewID)
return
}
@ -473,7 +473,7 @@ func (consensus *Consensus) onNewView(msg *msg_pb.Message) {
// change view and leaderKey to keep in sync with network
if consensus.blockNum != recvMsg.BlockNum {
utils.GetLogger().Debug("new leader changed", "newLeaderKey", consensus.LeaderPubKey.GetHexString()[:20], "viewID", consensus.viewID, "myBlock", consensus.blockNum, "newViewBlockNum", recvMsg.BlockNum)
utils.GetLogger().Debug("new leader changed", "newLeaderKey", consensus.LeaderPubKey.SerializeToHexStr()[:20], "viewID", consensus.viewID, "myBlock", consensus.blockNum, "newViewBlockNum", recvMsg.BlockNum)
return
}
@ -491,7 +491,7 @@ func (consensus *Consensus) onNewView(msg *msg_pb.Message) {
consensus.ResetState()
utils.GetLogInstance().Info("onNewView === announce")
}
utils.GetLogger().Debug("new leader changed", "newLeaderKey", consensus.LeaderPubKey.GetHexString()[:20], "viewID", consensus.viewID, "block", consensus.blockNum)
utils.GetLogger().Debug("new leader changed", "newLeaderKey", consensus.LeaderPubKey.SerializeToHexStr()[:20], "viewID", consensus.viewID, "block", consensus.blockNum)
utils.GetLogger().Debug("validator start consensus timeout and stop view change timeout", "viewID", consensus.viewID, "block", consensus.blockNum)
consensus.consensusTimeout[timeoutConsensus].Start()
consensus.consensusTimeout[timeoutViewChange].Stop()

@ -227,7 +227,7 @@ func GetInitShardState() types.ShardState {
for j := 0; j < GenesisShardHarmonyNodes; j++ {
index := i + j*GenesisShardNum // The initial account to use for genesis nodes
priKey := bls.SecretKey{}
priKey.SetHexString(genesis.GenesisAccounts[index].BlsPriKey)
priKey.DeserializeHexStr(genesis.GenesisAccounts[index].BlsPriKey)
pubKey := types.BlsPublicKey{}
pubKey.FromLibBLSPublicKey(priKey.GetPublicKey())
// TODO: directly read address for bls too
@ -239,7 +239,7 @@ func GetInitShardState() types.ShardState {
for j := GenesisShardHarmonyNodes; j < GenesisShardSize; j++ {
index := i + (j-GenesisShardHarmonyNodes)*GenesisShardNum
priKey := bls.SecretKey{}
priKey.SetHexString(genesis.GenesisFNAccounts[index].BlsPriKey)
priKey.DeserializeHexStr(genesis.GenesisFNAccounts[index].BlsPriKey)
pubKey := types.BlsPublicKey{}
pubKey.FromLibBLSPublicKey(priKey.GetPublicKey())
// TODO: directly read address for bls too

@ -135,9 +135,9 @@ func TestAggregatedSignature(test *testing.T) {
multiSignature := AggregateSig(signs)
str := multiSignature.GetHexString()
str := multiSignature.SerializeToHexStr()
if strings.Compare(multiSignature.GetHexString(), "0") == 0 {
if strings.Compare(multiSignature.SerializeToHexStr(), "0") == 0 {
test.Error("Error creating multisignature", str)
}
}

@ -157,7 +157,7 @@ func TestUpdatePublicKeys(test *testing.T) {
}
for index, publicKey := range dRand.PublicKeys {
if strings.Compare(publicKey.GetHexString(), publicKeys[index].GetHexString()) != 0 {
if strings.Compare(publicKey.SerializeToHexStr(), publicKeys[index].SerializeToHexStr()) != 0 {
test.Error("Public keys not updated succssfully")
}
}

@ -38,7 +38,7 @@ func GenBlsKeyWithPassPhrase(passphrase string) (*ffi_bls.SecretKey, string) {
privateKey := bls.RandPrivateKey()
publickKey := privateKey.GetPublicKey()
fileName := keyFileName(publickKey)
privateKeyHex := privateKey.GetHexString()
privateKeyHex := privateKey.SerializeToHexStr()
// Encrypt with passphrase
encryptedPrivateKeyBytes := encrypt([]byte(privateKeyHex), passphrase)
// Write to file.
@ -54,7 +54,7 @@ func LoadBlsKeyWithPassPhrase(fileName, passphrase string) *ffi_bls.SecretKey {
decryptedBytes := decrypt(encryptedPrivateKeyBytes, passphrase)
priKey := &ffi_bls.SecretKey{}
priKey.SetHexString(string(decryptedBytes))
priKey.DeserializeHexStr(string(decryptedBytes))
return priKey
}

@ -6,8 +6,6 @@ import (
"math/rand"
"strings"
"github.com/harmony-one/harmony/common/config"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb"

Loading…
Cancel
Save