diff options
Diffstat (limited to 'core/types')
-rw-r--r-- | core/types/block.go | 35 | ||||
-rw-r--r-- | core/types/block_test.go | 18 | ||||
-rw-r--r-- | core/types/vote.go | 2 |
3 files changed, 11 insertions, 44 deletions
diff --git a/core/types/block.go b/core/types/block.go index 8c3e510..2b23e96 100644 --- a/core/types/block.go +++ b/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, @@ -216,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 @@ -239,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/core/types/block_test.go b/core/types/block_test.go index 1dd83a9..03eef35 100644 --- a/core/types/block_test.go +++ b/core/types/block_test.go @@ -70,10 +70,6 @@ func (s *BlockTestSuite) createRandomBlock() *Block { Round: rand.Uint64(), Height: rand.Uint64(), }, - Acks: common.NewSortedHashes(common.Hashes{ - common.NewRandomHash(), - common.NewRandomHash(), - }), Timestamp: time.Now().UTC(), Witness: Witness{ Height: rand.Uint64(), @@ -180,20 +176,6 @@ func (s *BlockTestSuite) TestGenesisBlock() { s.False(b2.IsGenesis()) } -func (s *BlockTestSuite) TestIsAcking() { - // This test case would check if types.Block.IsAcking works - ack0 := common.NewRandomHash() - acks0 := common.Hashes{ - ack0, - common.NewRandomHash(), - common.NewRandomHash(), - } - b0 := &Block{Acks: common.NewSortedHashes(acks0)} - s.True(b0.IsAcking(ack0)) - s.False(b0.IsAcking(common.Hash{})) - s.False(b0.IsAcking(common.NewRandomHash())) -} - func (s *BlockTestSuite) TestClone() { b1 := *s.createRandomBlock() b2 := *b1.Clone() diff --git a/core/types/vote.go b/core/types/vote.go index 6481eb4..c4a625e 100644 --- a/core/types/vote.go +++ b/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]) } |