diff options
author | Jimmy Hu <jimmy.hu@dexon.org> | 2018-10-04 14:56:00 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-04 14:56:00 +0800 |
commit | 149e918f4fc78632483bf549dd8f5ffe55366e18 (patch) | |
tree | feabcb67103d76cc829ea81a1d57735e71db23d8 /core/lattice.go | |
parent | 519cc8a734a510f44463b8dd175b7505f0308a22 (diff) | |
download | dexon-consensus-149e918f4fc78632483bf549dd8f5ffe55366e18.tar dexon-consensus-149e918f4fc78632483bf549dd8f5ffe55366e18.tar.gz dexon-consensus-149e918f4fc78632483bf549dd8f5ffe55366e18.tar.bz2 dexon-consensus-149e918f4fc78632483bf549dd8f5ffe55366e18.tar.lz dexon-consensus-149e918f4fc78632483bf549dd8f5ffe55366e18.tar.xz dexon-consensus-149e918f4fc78632483bf549dd8f5ffe55366e18.tar.zst dexon-consensus-149e918f4fc78632483bf549dd8f5ffe55366e18.zip |
core: Check Witness height. Add ConsensusTime and ConsensusHeight to block. (#170)
Diffstat (limited to 'core/lattice.go')
-rw-r--r-- | core/lattice.go | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/core/lattice.go b/core/lattice.go index 8906c74..bb3bccd 100644 --- a/core/lattice.go +++ b/core/lattice.go @@ -38,6 +38,8 @@ var ( ErrInvalidChainID = fmt.Errorf("invalid chain id") ErrInvalidProposerID = fmt.Errorf("invalid proposer id") ErrInvalidTimestamp = fmt.Errorf("invalid timestamp") + ErrInvalidWitness = fmt.Errorf("invalid witness data") + ErrInvalidBlock = fmt.Errorf("invalid block") ErrForkBlock = fmt.Errorf("fork block") ErrNotAckParent = fmt.Errorf("not ack parent") ErrDoubleAck = fmt.Errorf("double ack") @@ -146,6 +148,9 @@ func (data *latticeData) sanityCheck(b *types.Block) error { if bParent.Position.Height != b.Position.Height-1 { return ErrInvalidBlockHeight } + if bParent.Witness.Height > b.Witness.Height { + return ErrInvalidWitness + } // Check if its timestamp is valid. if !b.Timestamp.After(bParent.Timestamp) { return ErrInvalidTimestamp @@ -290,6 +295,7 @@ func (data *latticeData) prepareBlock(block *types.Block) { if uint32(chainID) == block.Position.ChainID { block.ParentHash = curBlock.Hash block.Position.Height = curBlock.Position.Height + 1 + block.Witness.Height = curBlock.Witness.Height } } block.Acks = common.NewSortedHashes(acks) @@ -465,7 +471,8 @@ func (s *Lattice) PrepareBlock( // TODO(mission): the proposeTime might be earlier than tip block of // that chain. We should let latticeData suggest the time. b.Timestamp = proposeTime - b.Payload, b.Witness.Data = s.app.PrepareBlock(b.Position) + b.Payload = s.app.PreparePayload(b.Position) + b.Witness = s.app.PrepareWitness(b.Witness.Height) if err = s.authModule.SignBlock(b); err != nil { return } @@ -492,6 +499,10 @@ func (s *Lattice) SanityCheck(b *types.Block) (err error) { err = ErrIncorrectSignature return } + if !s.app.VerifyBlock(b) { + err = ErrInvalidBlock + return err + } s.lock.RLock() defer s.lock.RUnlock() if err = s.data.sanityCheck(b); err != nil { |