diff options
Diffstat (limited to 'core/types')
-rw-r--r-- | core/types/block.go | 1 | ||||
-rw-r--r-- | core/types/block_test.go | 5 | ||||
-rw-r--r-- | core/types/config.go | 27 | ||||
-rw-r--r-- | core/types/config_test.go | 4 | ||||
-rw-r--r-- | core/types/position.go | 23 | ||||
-rw-r--r-- | core/types/position_test.go | 59 |
6 files changed, 29 insertions, 90 deletions
diff --git a/core/types/block.go b/core/types/block.go index a2b697c..8c3e510 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -208,7 +208,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() diff --git a/core/types/block_test.go b/core/types/block_test.go index d47096f..1dd83a9 100644 --- a/core/types/block_test.go +++ b/core/types/block_test.go @@ -67,9 +67,8 @@ func (s *BlockTestSuite) createRandomBlock() *Block { ParentHash: common.NewRandomHash(), Hash: common.NewRandomHash(), Position: Position{ - Round: rand.Uint64(), - ChainID: rand.Uint32(), - Height: rand.Uint64(), + Round: rand.Uint64(), + Height: rand.Uint64(), }, Acks: common.NewSortedHashes(common.Hashes{ common.NewRandomHash(), diff --git a/core/types/config.go b/core/types/config.go index c9d31f8..56f0175 100644 --- a/core/types/config.go +++ b/core/types/config.go @@ -19,40 +19,29 @@ 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 + RoundInterval 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, @@ -62,9 +51,6 @@ func (c *Config) Clone() *Config { // 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,29 +58,20 @@ 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())) + binary.LittleEndian.PutUint64(binaryRoundInterval, c.RoundInterval) 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...) diff --git a/core/types/config_test.go b/core/types/config_test.go index bf6e422..6029479 100644 --- a/core/types/config_test.go +++ b/core/types/config_test.go @@ -30,13 +30,11 @@ type ConfigTestSuite struct { func (s *ConfigTestSuite) TestClone() { c := &Config{ - NumChains: 2, LambdaBA: 1 * time.Millisecond, LambdaDKG: 2 * time.Hour, - K: 4, NotarySetSize: 5, DKGSetSize: 6, - RoundInterval: 3 * time.Second, + RoundInterval: 1000, MinBlockInterval: 7 * time.Nanosecond, } s.Require().Equal(c, c.Clone()) diff --git a/core/types/position.go b/core/types/position.go index 902a55f..81d23c2 100644 --- a/core/types/position.go +++ b/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/core/types/position_test.go b/core/types/position_test.go index 213c15f..d2f4165 100644 --- a/core/types/position_test.go +++ b/core/types/position_test.go @@ -30,63 +30,47 @@ type PositionTestSuite struct { func (s *PositionTestSuite) TestNewer() { pos := Position{ - Round: 1, - ChainID: 1, - Height: 1, + Round: 1, + Height: 1, } - s.Panics(func() { - pos.Newer(Position{ChainID: 2}) - }) s.False(pos.Newer(Position{ - Round: 2, - ChainID: 1, - Height: 0, + Round: 2, + Height: 0, })) s.False(pos.Newer(Position{ - Round: 1, - ChainID: 1, - Height: 2, + Round: 1, + Height: 2, })) s.True(pos.Newer(Position{ - Round: 0, - ChainID: 1, - Height: 100, + Round: 0, + Height: 100, })) s.True(pos.Newer(Position{ - Round: 1, - ChainID: 1, - Height: 0, + Round: 1, + Height: 0, })) } func (s *PositionTestSuite) TestOlder() { pos := Position{ - Round: 1, - ChainID: 1, - Height: 1, + Round: 1, + Height: 1, } - s.Panics(func() { - pos.Older(Position{ChainID: 2}) - }) s.False(pos.Older(Position{ - Round: 0, - ChainID: 1, - Height: 0, + Round: 0, + Height: 0, })) s.False(pos.Older(Position{ - Round: 1, - ChainID: 1, - Height: 0, + Round: 1, + Height: 0, })) s.True(pos.Older(Position{ - Round: 2, - ChainID: 1, - Height: 0, + Round: 2, + Height: 0, })) s.True(pos.Older(Position{ - Round: 1, - ChainID: 1, - Height: 100, + Round: 1, + Height: 100, })) } @@ -116,9 +100,6 @@ func (s *PositionTestSuite) TestSearchInAsendingOrder() { func (s *PositionTestSuite) TestEqual() { pos := Position{} - s.Panics(func() { - pos.Equal(Position{ChainID: 1}) - }) s.True(pos.Equal(Position{})) s.False(pos.Equal(Position{Round: 1})) s.False(pos.Equal(Position{Height: 1})) |