aboutsummaryrefslogtreecommitdiffstats
path: root/vendor
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2019-04-15 18:19:46 +0800
committerWei-Ning Huang <w@byzantine-lab.io>2019-06-15 22:09:55 +0800
commit073064170c874bb19741108d0833b1bf019b439b (patch)
tree74de9ac95ea36614fe1740a07c4466556582346f /vendor
parent2f4bfc149062715b712ce6729f2ba100284d9af5 (diff)
downloadgo-tangerine-073064170c874bb19741108d0833b1bf019b439b.tar
go-tangerine-073064170c874bb19741108d0833b1bf019b439b.tar.gz
go-tangerine-073064170c874bb19741108d0833b1bf019b439b.tar.bz2
go-tangerine-073064170c874bb19741108d0833b1bf019b439b.tar.lz
go-tangerine-073064170c874bb19741108d0833b1bf019b439b.tar.xz
go-tangerine-073064170c874bb19741108d0833b1bf019b439b.tar.zst
go-tangerine-073064170c874bb19741108d0833b1bf019b439b.zip
core: implement DKG success (#362)
* vendor: sync to latest core * core: implmenet dkg success * cmd: govtool: add DKGSuccess
Diffstat (limited to 'vendor')
-rw-r--r--vendor/github.com/dexon-foundation/dexon-consensus/core/agreement-mgr.go12
-rw-r--r--vendor/github.com/dexon-foundation/dexon-consensus/core/blockchain.go7
-rw-r--r--vendor/github.com/dexon-foundation/dexon-consensus/core/configuration-chain.go1
-rw-r--r--vendor/github.com/dexon-foundation/dexon-consensus/core/consensus.go20
-rw-r--r--vendor/github.com/dexon-foundation/dexon-consensus/core/dkg-tsig-protocol.go18
-rw-r--r--vendor/github.com/dexon-foundation/dexon-consensus/core/interfaces.go6
-rw-r--r--vendor/github.com/dexon-foundation/dexon-consensus/core/types/dkg/dkg.go34
-rw-r--r--vendor/github.com/dexon-foundation/dexon-consensus/core/utils/crypto.go27
-rw-r--r--vendor/github.com/dexon-foundation/dexon-consensus/core/utils/round-event.go2
-rw-r--r--vendor/github.com/dexon-foundation/dexon-consensus/core/utils/signer.go7
-rw-r--r--vendor/vendor.json46
11 files changed, 144 insertions, 36 deletions
diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/agreement-mgr.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/agreement-mgr.go
index 4597fe92b..f65903d25 100644
--- a/vendor/github.com/dexon-foundation/dexon-consensus/core/agreement-mgr.go
+++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/agreement-mgr.go
@@ -564,11 +564,13 @@ func (mgr *agreementMgr) baRoutineForOneRound(
default:
}
nextHeight, nextTime = mgr.bcModule.nextBlock()
- if isStop(restartPos) {
- break
- }
- if nextHeight > restartPos.Height {
- break
+ if nextHeight != notReadyHeight {
+ if isStop(restartPos) {
+ break
+ }
+ if nextHeight > restartPos.Height {
+ break
+ }
}
mgr.logger.Debug("BlockChain not ready!!!",
"old", oldPos, "restart", restartPos, "next", nextHeight)
diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/blockchain.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/blockchain.go
index 1efd867e7..4fae221c7 100644
--- a/vendor/github.com/dexon-foundation/dexon-consensus/core/blockchain.go
+++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/blockchain.go
@@ -21,6 +21,7 @@ import (
"bytes"
"errors"
"fmt"
+ "math"
"sort"
"sync"
"time"
@@ -49,6 +50,8 @@ var (
ErrMissingRandomness = errors.New("missing block randomness")
)
+const notReadyHeight uint64 = math.MaxUint64
+
type pendingBlockRecord struct {
position types.Position
block *types.Block
@@ -384,6 +387,10 @@ func (bc *blockChain) nextBlock() (uint64, time.Time) {
if tip == nil {
return types.GenesisHeight, bc.dMoment
}
+ if tip != bc.lastDelivered {
+ // If tip is not delivered, we should not proceed to next block.
+ return notReadyHeight, time.Time{}
+ }
return tip.Position.Height + 1, tip.Timestamp.Add(config.minBlockInterval)
}
diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/configuration-chain.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/configuration-chain.go
index e9e04a28c..4e70ff087 100644
--- a/vendor/github.com/dexon-foundation/dexon-consensus/core/configuration-chain.go
+++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/configuration-chain.go
@@ -400,6 +400,7 @@ func (cc *configurationChain) runDKGPhaseNine(round uint64, reset uint64) error
cc.db.PutDKGPrivateKey(round, reset, *signer.privateKey); err != nil {
return err
}
+ cc.dkg.proposeSuccess()
cc.dkgResult.Lock()
defer cc.dkgResult.Unlock()
cc.dkgSigner[round] = signer
diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/consensus.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/consensus.go
index 968b90e99..ba7d8fd60 100644
--- a/vendor/github.com/dexon-foundation/dexon-consensus/core/consensus.go
+++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/consensus.go
@@ -496,6 +496,16 @@ func (recv *consensusDKGReceiver) ProposeDKGFinalize(final *typesDKG.Finalize) {
recv.gov.AddDKGFinalize(final)
}
+// ProposeDKGSuccess propose a DKGSuccess message.
+func (recv *consensusDKGReceiver) ProposeDKGSuccess(success *typesDKG.Success) {
+ if err := recv.signer.SignDKGSuccess(success); err != nil {
+ recv.logger.Error("Failed to sign DKG successize", "error", err)
+ return
+ }
+ recv.logger.Debug("Calling Governance.AddDKGSuccess", "success", success)
+ recv.gov.AddDKGSuccess(success)
+}
+
// Consensus implements DEXON Consensus algorithm.
type Consensus struct {
// Node Info.
@@ -818,6 +828,12 @@ func (con *Consensus) prepare(initBlock *types.Block) (err error) {
"reset", e.Reset)
return false
}
+ if !con.gov.IsDKGSuccess(nextRound) {
+ con.logger.Error("Next DKG is not success, reset it",
+ "round", e.Round,
+ "reset", e.Reset)
+ return false
+ }
gpk, err := typesDKG.NewGroupPublicKey(
nextRound,
con.gov.DKGMasterPublicKeys(nextRound),
@@ -1132,6 +1148,10 @@ func (con *Consensus) generateBlockRandomness(blocks []*types.Block) {
"block", block,
"result", result)
con.network.BroadcastAgreementResult(result)
+ if err := con.deliverFinalizedBlocks(); err != nil {
+ con.logger.Error("Failed to deliver finalized block",
+ "error", err)
+ }
}
}(block)
}
diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/dkg-tsig-protocol.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/dkg-tsig-protocol.go
index 0612bda4b..8383ad118 100644
--- a/vendor/github.com/dexon-foundation/dexon-consensus/core/dkg-tsig-protocol.go
+++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/dkg-tsig-protocol.go
@@ -102,6 +102,9 @@ type dkgReceiver interface {
// ProposeDKGFinalize propose a DKGFinalize message.
ProposeDKGFinalize(final *typesDKG.Finalize)
+
+ // ProposeDKGSuccess propose a DKGSuccess message.
+ ProposeDKGSuccess(final *typesDKG.Success)
}
type dkgProtocol struct {
@@ -487,10 +490,13 @@ func (d *dkgProtocol) processPrivateShare(
if _, exist := d.antiComplaintReceived[prvShare.ReceiverID]; !exist {
d.antiComplaintReceived[prvShare.ReceiverID] =
make(map[types.NodeID]struct{})
+ }
+ if _, exist :=
+ d.antiComplaintReceived[prvShare.ReceiverID][prvShare.ProposerID]; !exist {
d.recv.ProposeDKGAntiNackComplaint(prvShare)
+ d.antiComplaintReceived[prvShare.ReceiverID][prvShare.ProposerID] =
+ struct{}{}
}
- d.antiComplaintReceived[prvShare.ReceiverID][prvShare.ProposerID] =
- struct{}{}
}
return nil
}
@@ -511,6 +517,14 @@ func (d *dkgProtocol) proposeFinalize() {
})
}
+func (d *dkgProtocol) proposeSuccess() {
+ d.recv.ProposeDKGSuccess(&typesDKG.Success{
+ ProposerID: d.ID,
+ Round: d.round,
+ Reset: d.reset,
+ })
+}
+
func (d *dkgProtocol) recoverShareSecret(qualifyIDs dkg.IDs) (
*dkgShareSecret, error) {
if len(qualifyIDs) < d.threshold {
diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/interfaces.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/interfaces.go
index c16c624e3..c88b3dcb4 100644
--- a/vendor/github.com/dexon-foundation/dexon-consensus/core/interfaces.go
+++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/interfaces.go
@@ -141,6 +141,12 @@ type Governance interface {
// IsDKGFinal checks if DKG is final.
IsDKGFinal(round uint64) bool
+ // AddDKGSuccess adds a DKG success message.
+ AddDKGSuccess(success *typesDKG.Success)
+
+ // IsDKGSuccess checks if DKG is success.
+ IsDKGSuccess(round uint64) bool
+
// ReportForkVote reports a node for forking votes.
ReportForkVote(vote1, vote2 *types.Vote)
diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/types/dkg/dkg.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/types/dkg/dkg.go
index 868f0da17..cb921e586 100644
--- a/vendor/github.com/dexon-foundation/dexon-consensus/core/types/dkg/dkg.go
+++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/types/dkg/dkg.go
@@ -242,6 +242,11 @@ func (c *Complaint) DecodeRLP(s *rlp.Stream) error {
return nil
}
+// IsNack returns true if it's a nack complaint in DKG protocol.
+func (c *Complaint) IsNack() bool {
+ return len(c.PrivateShare.Signature.Signature) == 0
+}
+
// PartialSignature describe a partial signature in DKG protocol.
type PartialSignature struct {
ProposerID types.NodeID `json:"proposer_id"`
@@ -251,7 +256,7 @@ type PartialSignature struct {
Signature crypto.Signature `json:"signature"`
}
-// MPKReady describe a dig ready message in DKG protocol.
+// MPKReady describe a dkg ready message in DKG protocol.
type MPKReady struct {
ProposerID types.NodeID `json:"proposer_id"`
Round uint64 `json:"round"`
@@ -275,7 +280,7 @@ func (ready *MPKReady) Equal(other *MPKReady) bool {
bytes.Compare(ready.Signature.Signature, other.Signature.Signature) == 0
}
-// Finalize describe a dig finalize message in DKG protocol.
+// Finalize describe a dkg finalize message in DKG protocol.
type Finalize struct {
ProposerID types.NodeID `json:"proposer_id"`
Round uint64 `json:"round"`
@@ -299,9 +304,28 @@ func (final *Finalize) Equal(other *Finalize) bool {
bytes.Compare(final.Signature.Signature, other.Signature.Signature) == 0
}
-// IsNack returns true if it's a nack complaint in DKG protocol.
-func (c *Complaint) IsNack() bool {
- return len(c.PrivateShare.Signature.Signature) == 0
+// Success describe a dkg success message in DKG protocol.
+type Success struct {
+ ProposerID types.NodeID `json:"proposer_id"`
+ Round uint64 `json:"round"`
+ Reset uint64 `json:"reset"`
+ Signature crypto.Signature `json:"signature"`
+}
+
+func (s *Success) String() string {
+ return fmt.Sprintf("DKGSuccess{SP:%s Round:%d Reset:%d}",
+ s.ProposerID.String()[:6],
+ s.Round,
+ s.Reset)
+}
+
+// Equal check equality of two Success instances.
+func (s *Success) Equal(other *Success) bool {
+ return s.ProposerID.Equal(other.ProposerID) &&
+ s.Round == other.Round &&
+ s.Reset == other.Reset &&
+ s.Signature.Type == other.Signature.Type &&
+ bytes.Compare(s.Signature.Signature, other.Signature.Signature) == 0
}
// GroupPublicKey is the result of DKG protocol.
diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/utils/crypto.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/utils/crypto.go
index 496944dab..42ee6122e 100644
--- a/vendor/github.com/dexon-foundation/dexon-consensus/core/utils/crypto.go
+++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/utils/crypto.go
@@ -325,6 +325,19 @@ func hashDKGFinalize(final *typesDKG.Finalize) common.Hash {
)
}
+func hashDKGSuccess(success *typesDKG.Success) common.Hash {
+ binaryRound := make([]byte, 8)
+ binary.LittleEndian.PutUint64(binaryRound, success.Round)
+ binaryReset := make([]byte, 8)
+ binary.LittleEndian.PutUint64(binaryReset, success.Reset)
+
+ return crypto.Keccak256Hash(
+ success.ProposerID.Hash[:],
+ binaryRound,
+ binaryReset,
+ )
+}
+
// VerifyDKGFinalizeSignature verifies DKGFinalize signature.
func VerifyDKGFinalizeSignature(
final *typesDKG.Finalize) (bool, error) {
@@ -339,6 +352,20 @@ func VerifyDKGFinalizeSignature(
return true, nil
}
+// VerifyDKGSuccessSignature verifies DKGSuccess signature.
+func VerifyDKGSuccessSignature(
+ success *typesDKG.Success) (bool, error) {
+ hash := hashDKGSuccess(success)
+ pubKey, err := crypto.SigToPub(hash, success.Signature)
+ if err != nil {
+ return false, err
+ }
+ if success.ProposerID != types.NewNodeID(pubKey) {
+ return false, nil
+ }
+ return true, nil
+}
+
// Rehash hashes the hash again and again and again...
func Rehash(hash common.Hash, count uint) common.Hash {
result := hash
diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/utils/round-event.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/utils/round-event.go
index 602d2da16..b1d4d230e 100644
--- a/vendor/github.com/dexon-foundation/dexon-consensus/core/utils/round-event.go
+++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/utils/round-event.go
@@ -84,7 +84,7 @@ func (e RoundEventParam) NextTouchNodeSetCacheHeight() uint64 {
// NextDKGResetHeight returns the height to reset DKG for next period.
func (e RoundEventParam) NextDKGResetHeight() uint64 {
- return e.BeginHeight + e.Config.RoundLength*8/10
+ return e.BeginHeight + e.Config.RoundLength*85/100
}
// NextDKGRegisterHeight returns the height to register DKG.
diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/utils/signer.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/utils/signer.go
index 9904410c4..ff767437f 100644
--- a/vendor/github.com/dexon-foundation/dexon-consensus/core/utils/signer.go
+++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/utils/signer.go
@@ -145,3 +145,10 @@ func (s *Signer) SignDKGFinalize(final *typesDKG.Finalize) (err error) {
final.Signature, err = s.prvKey.Sign(hashDKGFinalize(final))
return
}
+
+// SignDKGSuccess signs a DKG success message.
+func (s *Signer) SignDKGSuccess(success *typesDKG.Success) (err error) {
+ success.ProposerID = s.proposerID
+ success.Signature, err = s.prvKey.Sign(hashDKGSuccess(success))
+ return
+}
diff --git a/vendor/vendor.json b/vendor/vendor.json
index eac81e0b8..3480eec30 100644
--- a/vendor/vendor.json
+++ b/vendor/vendor.json
@@ -141,16 +141,16 @@
{
"checksumSHA1": "In6vBHYUsX7DUIGiFN2hQggBgvI=",
"path": "github.com/dexon-foundation/dexon-consensus/common",
- "revision": "2d26246247e2f7e616cc3d13b9d61308580e7d67",
- "revisionTime": "2019-04-13T15:07:46Z",
+ "revision": "e9a1d3bca8353ee206d262ab1fad2d7e3e0b24a5",
+ "revisionTime": "2019-04-15T04:12:22Z",
"version": "master",
"versionExact": "master"
},
{
- "checksumSHA1": "6anh4sqNQZY5ZD+cZoTIB+N4PRc=",
+ "checksumSHA1": "1RGs5z/8Kq82E69C8aRUAZT3U24=",
"path": "github.com/dexon-foundation/dexon-consensus/core",
- "revision": "2d26246247e2f7e616cc3d13b9d61308580e7d67",
- "revisionTime": "2019-04-13T15:07:46Z",
+ "revision": "e9a1d3bca8353ee206d262ab1fad2d7e3e0b24a5",
+ "revisionTime": "2019-04-15T04:12:22Z",
"version": "master",
"versionExact": "master"
},
@@ -165,64 +165,64 @@
{
"checksumSHA1": "tQSbYCu5P00lUhKsx3IbBZCuSLY=",
"path": "github.com/dexon-foundation/dexon-consensus/core/crypto",
- "revision": "2d26246247e2f7e616cc3d13b9d61308580e7d67",
- "revisionTime": "2019-04-13T15:07:46Z",
+ "revision": "e9a1d3bca8353ee206d262ab1fad2d7e3e0b24a5",
+ "revisionTime": "2019-04-15T04:12:22Z",
"version": "master",
"versionExact": "master"
},
{
"checksumSHA1": "4besQaa0rm8jRUAJjpEaLZ/ZOYs=",
"path": "github.com/dexon-foundation/dexon-consensus/core/crypto/dkg",
- "revision": "2d26246247e2f7e616cc3d13b9d61308580e7d67",
- "revisionTime": "2019-04-13T15:07:46Z",
+ "revision": "e9a1d3bca8353ee206d262ab1fad2d7e3e0b24a5",
+ "revisionTime": "2019-04-15T04:12:22Z",
"version": "master",
"versionExact": "master"
},
{
"checksumSHA1": "BhLKK8RveoLaeXc9UyUKMwQqchU=",
"path": "github.com/dexon-foundation/dexon-consensus/core/crypto/ecdsa",
- "revision": "2d26246247e2f7e616cc3d13b9d61308580e7d67",
- "revisionTime": "2019-04-13T15:07:46Z",
+ "revision": "e9a1d3bca8353ee206d262ab1fad2d7e3e0b24a5",
+ "revisionTime": "2019-04-15T04:12:22Z",
"version": "master",
"versionExact": "master"
},
{
"checksumSHA1": "3Ludp/1V4dMBZH/c1oIVjHj0CqY=",
"path": "github.com/dexon-foundation/dexon-consensus/core/db",
- "revision": "2d26246247e2f7e616cc3d13b9d61308580e7d67",
- "revisionTime": "2019-04-13T15:07:46Z",
+ "revision": "e9a1d3bca8353ee206d262ab1fad2d7e3e0b24a5",
+ "revisionTime": "2019-04-15T04:12:22Z",
"version": "master",
"versionExact": "master"
},
{
"checksumSHA1": "sO5twEFTdLvkMuQo+I3vyzm9T3o=",
"path": "github.com/dexon-foundation/dexon-consensus/core/syncer",
- "revision": "2d26246247e2f7e616cc3d13b9d61308580e7d67",
- "revisionTime": "2019-04-13T15:07:46Z",
+ "revision": "e9a1d3bca8353ee206d262ab1fad2d7e3e0b24a5",
+ "revisionTime": "2019-04-15T04:12:22Z",
"version": "master",
"versionExact": "master"
},
{
"checksumSHA1": "0BY+E0E2cM7IHIMqunXwoolDS5Y=",
"path": "github.com/dexon-foundation/dexon-consensus/core/types",
- "revision": "2d26246247e2f7e616cc3d13b9d61308580e7d67",
- "revisionTime": "2019-04-13T15:07:46Z",
+ "revision": "e9a1d3bca8353ee206d262ab1fad2d7e3e0b24a5",
+ "revisionTime": "2019-04-15T04:12:22Z",
"version": "master",
"versionExact": "master"
},
{
- "checksumSHA1": "lbG7yqVgzo2CV/CQPYjG78xp5jg=",
+ "checksumSHA1": "yEPSfn48GaJmDbd2OFY+QRhjJ0w=",
"path": "github.com/dexon-foundation/dexon-consensus/core/types/dkg",
- "revision": "2d26246247e2f7e616cc3d13b9d61308580e7d67",
- "revisionTime": "2019-04-13T15:07:46Z",
+ "revision": "e9a1d3bca8353ee206d262ab1fad2d7e3e0b24a5",
+ "revisionTime": "2019-04-15T04:12:22Z",
"version": "master",
"versionExact": "master"
},
{
- "checksumSHA1": "C2r/uE8K53WIIA0FYYHIfR2xhng=",
+ "checksumSHA1": "7Ib134BAyLF1M/kREou4Zm7UUS4=",
"path": "github.com/dexon-foundation/dexon-consensus/core/utils",
- "revision": "2d26246247e2f7e616cc3d13b9d61308580e7d67",
- "revisionTime": "2019-04-13T15:07:46Z",
+ "revision": "e9a1d3bca8353ee206d262ab1fad2d7e3e0b24a5",
+ "revisionTime": "2019-04-15T04:12:22Z",
"version": "master",
"versionExact": "master"
},