diff --git a/README.md b/README.md index 8953138bd..4b315fcd3 100644 --- a/README.md +++ b/README.md @@ -4,16 +4,35 @@ ![Discord](https://img.shields.io/discord/532383335348043777.svg) [![Coverage Status](https://coveralls.io/repos/github/harmony-one/harmony/badge.svg?branch=master)](https://coveralls.io/github/harmony-one/harmony?branch=master) +## Installation Requirements +GMP and OpenSSL +```bash +brew install gmp +brew install openssl +``` ## Dev Environment Setup ```bash export GOPATH=$HOME/ +export CGO_CFLAGS="-I$GOPATH/src/github.com/harmony-one/bls/include -I$GOPATH/src/github.com/harmony-one/mcl/include -I/usr/local/opt/openssl/include" +export CGO_LDFLAGS="-L$GOPATH/src/github.com/harmony-one/bls/lib -L/usr/local/opt/openssl/lib" +export LD_LIBRARY_PATH=$GOPATH/src/github.com/harmony-one/bls/lib:$GOPATH/src/github.com/harmony-one/mcl/lib:/usr/local/opt/openssl/lib +export LIBRARY_PATH=$LD_LIBRARY_PATH +export DYLD_LIBRARY_PATH=$LD_LIBRARY_PATH mkdir -p $HOME//src/github.com/harmony-one cd $HOME//src/github.com/harmony-one +git clone git@github.com:harmony-one/mcl.git + +cd mcl && make -j4 && cd .. + +git clone git@github.com:harmony-one/bls.git + +cd bls && make -j4 && cd .. + git clone git@github.com:harmony-one/harmony.git cd harmony diff --git a/cmd/client/txgen/main.go b/cmd/client/txgen/main.go index 7efe4cd31..db5ed0c4d 100644 --- a/cmd/client/txgen/main.go +++ b/cmd/client/txgen/main.go @@ -22,7 +22,6 @@ import ( "github.com/harmony-one/harmony/p2p/p2pimpl" peerstore "github.com/libp2p/go-libp2p-peerstore" - multiaddr "github.com/multiformats/go-multiaddr" ) var ( diff --git a/cmd/harmony.go b/cmd/harmony.go index df52b0d70..4906b6e54 100644 --- a/cmd/harmony.go +++ b/cmd/harmony.go @@ -20,7 +20,6 @@ import ( "github.com/harmony-one/harmony/p2p" "github.com/harmony-one/harmony/p2p/p2pimpl" peerstore "github.com/libp2p/go-libp2p-peerstore" - multiaddr "github.com/multiformats/go-multiaddr" ) var ( diff --git a/consensus/consensus_leader.go b/consensus/consensus_leader.go index 70e6775eb..50181f6c2 100644 --- a/consensus/consensus_leader.go +++ b/consensus/consensus_leader.go @@ -183,7 +183,7 @@ func (consensus *Consensus) processPrepareMessage(message consensus_proto.Messag // Broadcast prepared message host.BroadcastMessageFromLeader(consensus.host, consensus.GetValidatorPeers(), msgToSend, consensus.OfflinePeers) - // Set state to targetState (ChallengeDone or FinalChallengeDone) + // Set state to targetState consensus.state = targetState } } @@ -264,9 +264,8 @@ func (consensus *Consensus) processCommitMessage(message consensus_proto.Message return } - threshold := 2 - targetState := CommitDone - if len(*commitSigs) >= ((len(consensus.PublicKeys)*threshold)/3+1) && consensus.state != targetState { + targetState := CommittedDone + if len(*commitSigs) >= ((len(consensus.PublicKeys)*2)/3+1) && consensus.state != targetState { utils.GetLogInstance().Info("Enough commits received!", "num", len(*commitSigs), "state", consensus.state) // Construct committed message @@ -276,9 +275,6 @@ func (consensus *Consensus) processCommitMessage(message consensus_proto.Message // Broadcast committed message host.BroadcastMessageFromLeader(consensus.host, consensus.GetValidatorPeers(), msgToSend, consensus.OfflinePeers) - // Set state to CollectiveSigDone or Finished - consensus.state = targetState - var blockObj types.Block err = rlp.DecodeBytes(consensus.block, &blockObj) if err != nil { @@ -312,7 +308,6 @@ func (consensus *Consensus) processCommitMessage(message consensus_proto.Message time.Sleep(500 * time.Millisecond) // Send signal to Node so the new block can be added and new round of consensus can be triggered consensus.ReadySignal <- struct{}{} - consensus.state = Finished } } diff --git a/consensus/consensus_validator.go b/consensus/consensus_validator.go index e190ad96e..a5043cfa3 100644 --- a/consensus/consensus_validator.go +++ b/consensus/consensus_validator.go @@ -105,7 +105,7 @@ func (consensus *Consensus) processAnnounceMessage(message consensus_proto.Messa consensus.SendMessage(consensus.leader, msgToSend) // utils.GetLogInstance().Warn("Sending Commit to leader", "state", targetState) - // Set state to CommitDone + // Set state to PrepareDone consensus.state = PrepareDone } @@ -255,7 +255,7 @@ func (consensus *Consensus) processCommittedMessage(message consensus_proto.Mess consensus.SendMessage(consensus.leader, msgToSend) - consensus.state = PrepareDone + consensus.state = CommittedDone // TODO: the block catch up logic is a temporary workaround for full failure node catchup. Implement the full node catchup logic // The logic is to roll up to the latest blocks one by one to try catching up with the leader. @@ -283,6 +283,7 @@ func (consensus *Consensus) processCommittedMessage(message consensus_proto.Mess } utils.GetLogInstance().Info("Finished Response. Adding block to chain", "numTx", len(blockObj.Transactions())) consensus.OnConsensusDone(&blockObj) + consensus.state = Finished select { case consensus.VerifiedNewBlock <- &blockObj: @@ -290,7 +291,6 @@ func (consensus *Consensus) processCommittedMessage(message consensus_proto.Mess utils.GetLogInstance().Info("[SYNC] consensus verified block send to chan failed", "blockHash", blockObj.Hash()) continue } - } else { break } diff --git a/crypto/bls/bls.go b/crypto/bls/bls.go index a437e2892..273a2b1cd 100644 --- a/crypto/bls/bls.go +++ b/crypto/bls/bls.go @@ -7,6 +7,10 @@ import ( "github.com/harmony-one/bls/ffi/go/bls" ) +func init() { + bls.Init(bls.BLS12_381) +} + // AggregateSig aggregates all the BLS signature into a single multi-signature. func AggregateSig(sigs []*bls.Sign) *bls.Sign { var aggregatedSig bls.Sign diff --git a/crypto/pki/utils.go b/crypto/pki/utils.go index 3a587c835..c7edba76b 100644 --- a/crypto/pki/utils.go +++ b/crypto/pki/utils.go @@ -4,13 +4,15 @@ import ( "crypto/sha256" "encoding/binary" - "github.com/harmony-one/bls/ffi/go/bls" - "github.com/dedis/kyber" "github.com/harmony-one/bls/ffi/go/bls" "github.com/harmony-one/harmony/crypto" ) +func init() { + bls.Init(bls.BLS12_381) +} + // GetAddressFromPublicKey returns address given a public key. func GetAddressFromPublicKey(pubKey *bls.PublicKey) [20]byte { bytes := pubKey.Serialize() diff --git a/internal/utils/utils.go b/internal/utils/utils.go index 64e15f867..19735fdbf 100644 --- a/internal/utils/utils.go +++ b/internal/utils/utils.go @@ -24,6 +24,10 @@ import ( var lock sync.Mutex +func init() { + bls.Init(bls.BLS12_381) +} + // Unmarshal is a function that unmarshals the data from the // reader into the specified value. func Unmarshal(r io.Reader, v interface{}) error { diff --git a/test/crypto/bls/main b/test/crypto/bls/main new file mode 100755 index 000000000..b4dd7a065 Binary files /dev/null and b/test/crypto/bls/main differ diff --git a/test/crypto/bls/main.go b/test/crypto/bls/main.go index e7e639fda..62e5e7c43 100644 --- a/test/crypto/bls/main.go +++ b/test/crypto/bls/main.go @@ -13,6 +13,10 @@ import ( "github.com/harmony-one/bls/ffi/go/bls" ) +func init() { + bls.Init(bls.BLS12_381) +} + func main() { m := "message to sign" var aggSig *bls.Sign