diff options
author | Jimmy Hu <jimmy.hu@dexon.org> | 2019-02-22 13:14:55 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@byzantine-lab.io> | 2019-06-12 17:27:22 +0800 |
commit | 2354d4aa747616a8fd4fb9482ada8042fd362139 (patch) | |
tree | 46fe0953c0258591c2cd415c3760764ff613a5bb /vendor/github.com/dexon-foundation/dexon-consensus/core/types | |
parent | 81193a683d6328b627ee0e5f0f3689b3473e29ea (diff) | |
download | go-tangerine-2354d4aa747616a8fd4fb9482ada8042fd362139.tar go-tangerine-2354d4aa747616a8fd4fb9482ada8042fd362139.tar.gz go-tangerine-2354d4aa747616a8fd4fb9482ada8042fd362139.tar.bz2 go-tangerine-2354d4aa747616a8fd4fb9482ada8042fd362139.tar.lz go-tangerine-2354d4aa747616a8fd4fb9482ada8042fd362139.tar.xz go-tangerine-2354d4aa747616a8fd4fb9482ada8042fd362139.tar.zst go-tangerine-2354d4aa747616a8fd4fb9482ada8042fd362139.zip |
core: Remove K, Phi and NumChains from Governance (#198)
* change default sync_core.sh
* vendor: sync to latest core
* core: Remove K, Phi and NumChain
Diffstat (limited to 'vendor/github.com/dexon-foundation/dexon-consensus/core/types')
6 files changed, 86 insertions, 45 deletions
diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/types/block-randomness.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/types/block-randomness.go index 65cb635ca..74360c735 100644 --- a/vendor/github.com/dexon-foundation/dexon-consensus/core/types/block-randomness.go +++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/types/block-randomness.go @@ -34,7 +34,7 @@ type AgreementResult struct { func (r *AgreementResult) String() string { return fmt.Sprintf("agreementResult{Hash:%s %s}", - r.BlockHash.String()[:6], &r.Position) + r.BlockHash.String()[:6], r.Position) } // BlockRandomnessResult describes a block randomness result @@ -46,7 +46,7 @@ type BlockRandomnessResult struct { func (r *BlockRandomnessResult) String() string { return fmt.Sprintf("blockRandomness{Block:%s Pos:%s Rand:%s}", - r.BlockHash.String()[:6], &r.Position, + r.BlockHash.String()[:6], r.Position, hex.EncodeToString(r.Randomness)[:6], ) } diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/types/block.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/types/block.go index b2a8f57f8..a2b697ce0 100644 --- a/vendor/github.com/dexon-foundation/dexon-consensus/core/types/block.go +++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/types/block.go @@ -198,7 +198,7 @@ func (b *Block) DecodeRLP(s *rlp.Stream) error { } func (b *Block) String() string { - return fmt.Sprintf("Block{Hash:%v %s}", b.Hash.String()[:6], &b.Position) + return fmt.Sprintf("Block{Hash:%v %s}", b.Hash.String()[:6], b.Position) } // Clone returns a deep copy of a block. @@ -263,62 +263,62 @@ func (b ByHash) Swap(i int, j int) { b[i], b[j] = b[j], b[i] } -// ByPosition is the helper type for sorting slice of blocks by position. -type ByPosition []*Block +// BlocksByPosition is the helper type for sorting slice of blocks by position. +type BlocksByPosition []*Block // Len implements Len method in sort.Sort interface. -func (bs ByPosition) Len() int { +func (bs BlocksByPosition) Len() int { return len(bs) } // Less implements Less method in sort.Sort interface. -func (bs ByPosition) Less(i int, j int) bool { - return bs[j].Position.Newer(&bs[i].Position) +func (bs BlocksByPosition) Less(i int, j int) bool { + return bs[j].Position.Newer(bs[i].Position) } // Swap implements Swap method in sort.Sort interface. -func (bs ByPosition) Swap(i int, j int) { +func (bs BlocksByPosition) Swap(i int, j int) { bs[i], bs[j] = bs[j], bs[i] } // Push implements Push method in heap interface. -func (bs *ByPosition) Push(x interface{}) { +func (bs *BlocksByPosition) Push(x interface{}) { *bs = append(*bs, x.(*Block)) } // Pop implements Pop method in heap interface. -func (bs *ByPosition) Pop() (ret interface{}) { +func (bs *BlocksByPosition) Pop() (ret interface{}) { n := len(*bs) *bs, ret = (*bs)[0:n-1], (*bs)[n-1] return } -// ByFinalizationHeight is the helper type for sorting slice of blocks by +// BlocksByFinalizationHeight is the helper type for sorting slice of blocks by // finalization height. -type ByFinalizationHeight []*Block +type BlocksByFinalizationHeight []*Block // Len implements Len method in sort.Sort interface. -func (bs ByFinalizationHeight) Len() int { +func (bs BlocksByFinalizationHeight) Len() int { return len(bs) } // Less implements Less method in sort.Sort interface. -func (bs ByFinalizationHeight) Less(i int, j int) bool { +func (bs BlocksByFinalizationHeight) Less(i int, j int) bool { return bs[i].Finalization.Height < bs[j].Finalization.Height } // Swap implements Swap method in sort.Sort interface. -func (bs ByFinalizationHeight) Swap(i int, j int) { +func (bs BlocksByFinalizationHeight) Swap(i int, j int) { bs[i], bs[j] = bs[j], bs[i] } // Push implements Push method in heap interface. -func (bs *ByFinalizationHeight) Push(x interface{}) { +func (bs *BlocksByFinalizationHeight) Push(x interface{}) { *bs = append(*bs, x.(*Block)) } // Pop implements Pop method in heap interface. -func (bs *ByFinalizationHeight) Pop() (ret interface{}) { +func (bs *BlocksByFinalizationHeight) Pop() (ret interface{}) { n := len(*bs) *bs, ret = (*bs)[0:n-1], (*bs)[n-1] return 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 efe846755..db58168a2 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 @@ -163,6 +163,64 @@ func (c *Complaint) Equal(other *Complaint) bool { bytes.Compare(c.Signature.Signature, other.Signature.Signature) == 0 } +type rlpComplaint struct { + ProposerID types.NodeID + Round uint64 + IsNack bool + PrivateShare []byte + Signature crypto.Signature +} + +// EncodeRLP implements rlp.Encoder +func (c *Complaint) EncodeRLP(w io.Writer) error { + if c.IsNack() { + return rlp.Encode(w, rlpComplaint{ + ProposerID: c.ProposerID, + Round: c.Round, + IsNack: true, + PrivateShare: c.PrivateShare.ProposerID.Hash[:], + Signature: c.Signature, + }) + } + prvShare, err := rlp.EncodeToBytes(&c.PrivateShare) + if err != nil { + return err + } + return rlp.Encode(w, rlpComplaint{ + ProposerID: c.ProposerID, + Round: c.Round, + IsNack: false, + PrivateShare: prvShare, + Signature: c.Signature, + }) +} + +// DecodeRLP implements rlp.Decoder +func (c *Complaint) DecodeRLP(s *rlp.Stream) error { + var dec rlpComplaint + if err := s.Decode(&dec); err != nil { + return err + } + + var prvShare PrivateShare + if dec.IsNack { + copy(prvShare.ProposerID.Hash[:], dec.PrivateShare) + prvShare.Round = dec.Round + } else { + if err := rlp.DecodeBytes(dec.PrivateShare, &prvShare); err != nil { + return err + } + } + + *c = Complaint{ + ProposerID: dec.ProposerID, + Round: dec.Round, + PrivateShare: prvShare, + Signature: dec.Signature, + } + return nil +} + // PartialSignature describe a partial signature in DKG protocol. type PartialSignature struct { ProposerID types.NodeID `json:"proposer_id"` diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/types/nodeset.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/types/nodeset.go index 21a1e528e..fccfbb6aa 100644 --- a/vendor/github.com/dexon-foundation/dexon-consensus/core/types/nodeset.go +++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/types/nodeset.go @@ -85,11 +85,8 @@ func NewNodeSetFromMap(nodes map[NodeID]struct{}) *NodeSet { } // NewNotarySetTarget is the target for getting Notary Set. -func NewNotarySetTarget(crs common.Hash, chainID uint32) *SubSetTarget { - binaryChainID := make([]byte, 4) - binary.LittleEndian.PutUint32(binaryChainID, chainID) - - return newTarget(targetNotarySet, crs[:], binaryChainID) +func NewNotarySetTarget(crs common.Hash) *SubSetTarget { + return newTarget(targetNotarySet, crs[:]) } // NewDKGSetTarget is the target for getting DKG Set. @@ -98,15 +95,10 @@ func NewDKGSetTarget(crs common.Hash) *SubSetTarget { } // NewNodeLeaderTarget is the target for getting leader of fast BA. -func NewNodeLeaderTarget(crs common.Hash, pos Position) *SubSetTarget { - binaryRoundID := make([]byte, 8) - binary.LittleEndian.PutUint64(binaryRoundID, pos.Round) - binaryChainID := make([]byte, 4) - binary.LittleEndian.PutUint32(binaryChainID, pos.ChainID) +func NewNodeLeaderTarget(crs common.Hash, height uint64) *SubSetTarget { binaryHeight := make([]byte, 8) - binary.LittleEndian.PutUint64(binaryHeight, pos.Height) - return newTarget(targetNodeLeader, crs[:], - binaryRoundID, binaryChainID, binaryHeight) + binary.LittleEndian.PutUint64(binaryHeight, height) + return newTarget(targetNodeLeader, crs[:], binaryHeight) } // Add a NodeID to the set. diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/types/position.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/types/position.go index 8822f6ea9..902a55fec 100644 --- a/vendor/github.com/dexon-foundation/dexon-consensus/core/types/position.go +++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/types/position.go @@ -28,14 +28,14 @@ type Position struct { Height uint64 `json:"height"` } -func (pos *Position) String() string { +func (pos Position) String() string { return fmt.Sprintf("Position{Round:%d Chain:%d Height:%d}", pos.Round, pos.ChainID, pos.Height) } // Equal checks if two positions are equal, it panics when their chainIDs // are different. -func (pos *Position) Equal(other *Position) bool { +func (pos Position) Equal(other Position) bool { if pos.ChainID != other.ChainID { panic(fmt.Errorf("unexpected chainID %d, should be %d", other.ChainID, pos.ChainID)) @@ -45,7 +45,7 @@ func (pos *Position) Equal(other *Position) bool { // Newer checks if one block is newer than another one on the same chain. // If two blocks on different chain compared by this function, it would panic. -func (pos *Position) Newer(other *Position) bool { +func (pos Position) Newer(other Position) bool { if pos.ChainID != other.ChainID { panic(fmt.Errorf("unexpected chainID %d, should be %d", other.ChainID, pos.ChainID)) @@ -56,7 +56,7 @@ func (pos *Position) Newer(other *Position) bool { // Older checks if one block is older than another one on the same chain. // If two blocks on different chain compared by this function, it would panic. -func (pos *Position) Older(other *Position) bool { +func (pos Position) Older(other Position) bool { if pos.ChainID != other.ChainID { panic(fmt.Errorf("unexpected chainID %d, should be %d", other.ChainID, pos.ChainID)) @@ -64,12 +64,3 @@ func (pos *Position) Older(other *Position) bool { return pos.Round < other.Round || (pos.Round == other.Round && pos.Height < other.Height) } - -// Clone a position instance. -func (pos *Position) Clone() *Position { - return &Position{ - ChainID: pos.ChainID, - Round: pos.Round, - Height: pos.Height, - } -} diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/types/vote.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/types/vote.go index 46ea1dfb0..6481eb46d 100644 --- a/vendor/github.com/dexon-foundation/dexon-consensus/core/types/vote.go +++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/types/vote.go @@ -68,7 +68,7 @@ type Vote struct { func (v *Vote) String() string { return fmt.Sprintf("Vote{BP:%s %s Period:%d Type:%d Hash:%s}", v.ProposerID.String()[:6], - &v.Position, v.Period, v.Type, v.BlockHash.String()[:6]) + v.Position, v.Period, v.Type, v.BlockHash.String()[:6]) } // NewVote constructs a Vote instance with header fields. |