aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/dexon-foundation/dexon-consensus/core/types
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2019-02-27 10:41:01 +0800
committerWei-Ning Huang <w@byzantine-lab.io>2019-06-12 17:27:22 +0800
commit2b2396b6bce0f21b515ac2d38556f6dca08b1770 (patch)
tree60d6c93689b54534ecc88bd1491bd82fa372b541 /vendor/github.com/dexon-foundation/dexon-consensus/core/types
parentedb1273cb08d56df41b30b1f2f2e113f9b4296e4 (diff)
downloadgo-tangerine-2b2396b6bce0f21b515ac2d38556f6dca08b1770.tar
go-tangerine-2b2396b6bce0f21b515ac2d38556f6dca08b1770.tar.gz
go-tangerine-2b2396b6bce0f21b515ac2d38556f6dca08b1770.tar.bz2
go-tangerine-2b2396b6bce0f21b515ac2d38556f6dca08b1770.tar.lz
go-tangerine-2b2396b6bce0f21b515ac2d38556f6dca08b1770.tar.xz
go-tangerine-2b2396b6bce0f21b515ac2d38556f6dca08b1770.tar.zst
go-tangerine-2b2396b6bce0f21b515ac2d38556f6dca08b1770.zip
core: sync to latest core (#214)
* vendor: sync to latest core * fix for single chain
Diffstat (limited to 'vendor/github.com/dexon-foundation/dexon-consensus/core/types')
-rw-r--r--vendor/github.com/dexon-foundation/dexon-consensus/core/types/block.go36
-rw-r--r--vendor/github.com/dexon-foundation/dexon-consensus/core/types/config.go33
-rw-r--r--vendor/github.com/dexon-foundation/dexon-consensus/core/types/position.go23
-rw-r--r--vendor/github.com/dexon-foundation/dexon-consensus/core/types/vote.go2
4 files changed, 20 insertions, 74 deletions
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 a2b697ce0..2b23e96e3 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
@@ -23,7 +23,6 @@ import (
"bytes"
"fmt"
"io"
- "sort"
"time"
"github.com/dexon-foundation/dexon/rlp"
@@ -125,17 +124,16 @@ type Witness struct {
// Block represents a single event broadcasted on the network.
type Block struct {
- ProposerID NodeID `json:"proposer_id"`
- ParentHash common.Hash `json:"parent_hash"`
- Hash common.Hash `json:"hash"`
- Position Position `json:"position"`
- Timestamp time.Time `json:"timestamp"`
- Acks common.SortedHashes `json:"acks"`
- Payload []byte `json:"payload"`
- PayloadHash common.Hash `json:"payload_hash"`
- Witness Witness `json:"witness"`
- Finalization FinalizationResult `json:"finalization"`
- Signature crypto.Signature `json:"signature"`
+ ProposerID NodeID `json:"proposer_id"`
+ ParentHash common.Hash `json:"parent_hash"`
+ Hash common.Hash `json:"hash"`
+ Position Position `json:"position"`
+ Timestamp time.Time `json:"timestamp"`
+ Payload []byte `json:"payload"`
+ PayloadHash common.Hash `json:"payload_hash"`
+ Witness Witness `json:"witness"`
+ Finalization FinalizationResult `json:"finalization"`
+ Signature crypto.Signature `json:"signature"`
CRSSignature crypto.Signature `json:"crs_signature"`
}
@@ -146,7 +144,6 @@ type rlpBlock struct {
Hash common.Hash
Position Position
Timestamp *rlpTimestamp
- Acks common.SortedHashes
Payload []byte
PayloadHash common.Hash
Witness *Witness
@@ -164,7 +161,6 @@ func (b *Block) EncodeRLP(w io.Writer) error {
Hash: b.Hash,
Position: b.Position,
Timestamp: &rlpTimestamp{b.Timestamp},
- Acks: b.Acks,
Payload: b.Payload,
PayloadHash: b.PayloadHash,
Witness: &b.Witness,
@@ -185,7 +181,6 @@ func (b *Block) DecodeRLP(s *rlp.Stream) error {
Hash: dec.Hash,
Position: dec.Position,
Timestamp: dec.Timestamp.Time,
- Acks: dec.Acks,
Payload: dec.Payload,
PayloadHash: dec.PayloadHash,
Witness: *dec.Witness,
@@ -208,7 +203,6 @@ func (b *Block) Clone() (bcopy *Block) {
bcopy.ParentHash = b.ParentHash
bcopy.Hash = b.Hash
bcopy.Position.Round = b.Position.Round
- bcopy.Position.ChainID = b.Position.ChainID
bcopy.Position.Height = b.Position.Height
bcopy.Signature = b.Signature.Clone()
bcopy.CRSSignature = b.CRSSignature.Clone()
@@ -217,8 +211,6 @@ func (b *Block) Clone() (bcopy *Block) {
bcopy.Witness.Data = make([]byte, len(b.Witness.Data))
copy(bcopy.Witness.Data, b.Witness.Data)
bcopy.Timestamp = b.Timestamp
- bcopy.Acks = make(common.SortedHashes, len(b.Acks))
- copy(bcopy.Acks, b.Acks)
bcopy.Payload = make([]byte, len(b.Payload))
copy(bcopy.Payload, b.Payload)
bcopy.PayloadHash = b.PayloadHash
@@ -240,14 +232,6 @@ func (b *Block) IsEmpty() bool {
return b.ProposerID.Hash == common.Hash{}
}
-// IsAcking checks if a block acking another by it's hash.
-func (b *Block) IsAcking(hash common.Hash) bool {
- idx := sort.Search(len(b.Acks), func(i int) bool {
- return bytes.Compare(b.Acks[i][:], hash[:]) >= 0
- })
- return !(idx == len(b.Acks) || b.Acks[idx] != hash)
-}
-
// ByHash is the helper type for sorting slice of blocks by hash.
type ByHash []*Block
diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/types/config.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/types/config.go
index c9d31f8c4..eda09f06e 100644
--- a/vendor/github.com/dexon-foundation/dexon-consensus/core/types/config.go
+++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/types/config.go
@@ -19,52 +19,38 @@ package types
import (
"encoding/binary"
- "math"
"time"
)
// Config stands for Current Configuration Parameters.
type Config struct {
- // Network related.
- NumChains uint32
-
// Lambda related.
LambdaBA time.Duration
LambdaDKG time.Duration
- // Total ordering related.
- K int
- PhiRatio float32
-
// Set related.
NotarySetSize uint32
DKGSetSize uint32
// Time related.
- RoundInterval time.Duration
+ RoundLength uint64
MinBlockInterval time.Duration
}
// Clone return a copied configuration.
func (c *Config) Clone() *Config {
return &Config{
- NumChains: c.NumChains,
LambdaBA: c.LambdaBA,
LambdaDKG: c.LambdaDKG,
- K: c.K,
- PhiRatio: c.PhiRatio,
NotarySetSize: c.NotarySetSize,
DKGSetSize: c.DKGSetSize,
- RoundInterval: c.RoundInterval,
+ RoundLength: c.RoundLength,
MinBlockInterval: c.MinBlockInterval,
}
}
// Bytes returns []byte representation of Config.
func (c *Config) Bytes() []byte {
- binaryNumChains := make([]byte, 4)
- binary.LittleEndian.PutUint32(binaryNumChains, c.NumChains)
-
binaryLambdaBA := make([]byte, 8)
binary.LittleEndian.PutUint64(
binaryLambdaBA, uint64(c.LambdaBA.Nanoseconds()))
@@ -72,32 +58,23 @@ func (c *Config) Bytes() []byte {
binary.LittleEndian.PutUint64(
binaryLambdaDKG, uint64(c.LambdaDKG.Nanoseconds()))
- binaryK := make([]byte, 4)
- binary.LittleEndian.PutUint32(binaryK, uint32(c.K))
- binaryPhiRatio := make([]byte, 4)
- binary.LittleEndian.PutUint32(binaryPhiRatio, math.Float32bits(c.PhiRatio))
-
binaryNotarySetSize := make([]byte, 4)
binary.LittleEndian.PutUint32(binaryNotarySetSize, c.NotarySetSize)
binaryDKGSetSize := make([]byte, 4)
binary.LittleEndian.PutUint32(binaryDKGSetSize, c.DKGSetSize)
- binaryRoundInterval := make([]byte, 8)
- binary.LittleEndian.PutUint64(binaryRoundInterval,
- uint64(c.RoundInterval.Nanoseconds()))
+ binaryRoundLength := make([]byte, 8)
+ binary.LittleEndian.PutUint64(binaryRoundLength, c.RoundLength)
binaryMinBlockInterval := make([]byte, 8)
binary.LittleEndian.PutUint64(binaryMinBlockInterval,
uint64(c.MinBlockInterval.Nanoseconds()))
enc := make([]byte, 0, 40)
- enc = append(enc, binaryNumChains...)
enc = append(enc, binaryLambdaBA...)
enc = append(enc, binaryLambdaDKG...)
- enc = append(enc, binaryK...)
- enc = append(enc, binaryPhiRatio...)
enc = append(enc, binaryNotarySetSize...)
enc = append(enc, binaryDKGSetSize...)
- enc = append(enc, binaryRoundInterval...)
+ enc = append(enc, binaryRoundLength...)
enc = append(enc, binaryMinBlockInterval...)
return enc
}
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 902a55fec..81d23c266 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
@@ -23,33 +23,22 @@ import (
// Position describes the position in the block lattice of an entity.
type Position struct {
- ChainID uint32 `json:"chain_id"`
- Round uint64 `json:"round"`
- Height uint64 `json:"height"`
+ Round uint64 `json:"round"`
+ Height uint64 `json:"height"`
}
func (pos Position) String() string {
- return fmt.Sprintf("Position{Round:%d Chain:%d Height:%d}",
- pos.Round, pos.ChainID, pos.Height)
+ return fmt.Sprintf("Position{Round:%d Height:%d}", pos.Round, pos.Height)
}
-// Equal checks if two positions are equal, it panics when their chainIDs
-// are different.
+// Equal checks if two positions are equal.
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))
- }
return pos.Round == other.Round && pos.Height == other.Height
}
// 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 {
- if pos.ChainID != other.ChainID {
- panic(fmt.Errorf("unexpected chainID %d, should be %d",
- other.ChainID, pos.ChainID))
- }
return pos.Round > other.Round ||
(pos.Round == other.Round && pos.Height > other.Height)
}
@@ -57,10 +46,6 @@ 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 {
- if pos.ChainID != other.ChainID {
- panic(fmt.Errorf("unexpected chainID %d, should be %d",
- other.ChainID, pos.ChainID))
- }
return pos.Round < other.Round ||
(pos.Round == other.Round && pos.Height < other.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 6481eb46d..c4a625edd 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
@@ -66,7 +66,7 @@ type Vote struct {
}
func (v *Vote) String() string {
- return fmt.Sprintf("Vote{BP:%s %s Period:%d Type:%d Hash:%s}",
+ return fmt.Sprintf("Vote{VP:%s %s Period:%d Type:%d Hash:%s}",
v.ProposerID.String()[:6],
v.Position, v.Period, v.Type, v.BlockHash.String()[:6])
}