diff options
author | Jimmy Hu <jimmy.hu@dexon.org> | 2018-09-11 13:28:44 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-11 13:28:44 +0800 |
commit | 582a491aa0bcb784ac7b65ebbfb42139945ea703 (patch) | |
tree | 8589bad986f512455717728012c3d9edf3b68c4f /core/reliable-broadcast.go | |
parent | 2439f49063d8498eadf26d4fa1220c5eac8412a8 (diff) | |
download | dexon-consensus-582a491aa0bcb784ac7b65ebbfb42139945ea703.tar dexon-consensus-582a491aa0bcb784ac7b65ebbfb42139945ea703.tar.gz dexon-consensus-582a491aa0bcb784ac7b65ebbfb42139945ea703.tar.bz2 dexon-consensus-582a491aa0bcb784ac7b65ebbfb42139945ea703.tar.lz dexon-consensus-582a491aa0bcb784ac7b65ebbfb42139945ea703.tar.xz dexon-consensus-582a491aa0bcb784ac7b65ebbfb42139945ea703.tar.zst dexon-consensus-582a491aa0bcb784ac7b65ebbfb42139945ea703.zip |
core: timestamp (#98)
Diffstat (limited to 'core/reliable-broadcast.go')
-rw-r--r-- | core/reliable-broadcast.go | 53 |
1 files changed, 7 insertions, 46 deletions
diff --git a/core/reliable-broadcast.go b/core/reliable-broadcast.go index 7cca4f1..7d3ba2d 100644 --- a/core/reliable-broadcast.go +++ b/core/reliable-broadcast.go @@ -140,22 +140,11 @@ func (rb *reliableBroadcast) sanityCheck(b *types.Block) error { } } - // TODO(jimmy-dexon): verify the timestamps. - /* - // Check if its timestamp is valid. - for h := range rb.lattice { - if _, exist := b.Timestamps[h]; !exist { - return ErrInvalidTimestamp - } - } - */ - + // Check if its timestamp is valid. if bParent, exist := rb.lattice[b.Position.ChainID].blocks[b.Position.Height-1]; exist { - for hash := range b.Timestamps { - if b.Timestamps[hash].Before(bParent.Timestamps[hash]) { - return ErrInvalidTimestamp - } + if !b.Timestamp.After(bParent.Timestamp) { + return ErrInvalidTimestamp } } @@ -370,36 +359,6 @@ func (rb *reliableBroadcast) prepareBlock(block *types.Block) { // Reset fields to make sure we got these information from parent block. block.Position.Height = 0 block.ParentHash = common.Hash{} - // The helper function to accumulate timestamps. - accumulateTimestamps := func( - times map[types.ValidatorID]time.Time, b *types.Block) { - - // Update timestamps with the block's proposer time. - // TODO (mission): make epslon configurable. - times[b.ProposerID] = b.Timestamps[b.ProposerID].Add( - 1 * time.Millisecond) - - // Update timestamps from the block if it's later than - // current cached ones. - for vID, t := range b.Timestamps { - cachedTime, exists := times[vID] - if !exists { - // This means the block contains timestamps from - // removed validators. - continue - } - if cachedTime.After(t) { - continue - } - times[vID] = t - } - return - } - // Initial timestamps with current validator set. - times := make(map[types.ValidatorID]time.Time) - for vID := range rb.validators { - times[vID] = time.Time{} - } acks := make(map[common.Hash]struct{}) for chainID := range rb.lattice { // find height of the latest block for that validator. @@ -420,15 +379,17 @@ func (rb *reliableBroadcast) prepareBlock(block *types.Block) { continue } acks[curBlock.Hash] = struct{}{} - accumulateTimestamps(times, curBlock) if uint32(chainID) == block.Position.ChainID { block.ParentHash = curBlock.Hash + if block.Timestamp.Before(curBlock.Timestamp) { + // TODO (mission): make epslon configurable. + block.Timestamp = curBlock.Timestamp.Add(1 * time.Millisecond) + } if block.Position.Height == 0 { block.Position.Height = curBlock.Position.Height + 1 } } } - block.Timestamps = times block.Acks = acks return } |