diff options
author | Jimmy Hu <jimmy.hu@dexon.org> | 2018-08-16 12:02:51 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-16 12:02:51 +0800 |
commit | 9266273b790d4fa8c68e2d0fce290fe58923187b (patch) | |
tree | decf74f593fa84788f8c85f2067747ee702d970d /core | |
parent | 96fcee4688dacd812292376994a3500e2c78edeb (diff) | |
download | tangerine-consensus-9266273b790d4fa8c68e2d0fce290fe58923187b.tar.gz tangerine-consensus-9266273b790d4fa8c68e2d0fce290fe58923187b.tar.zst tangerine-consensus-9266273b790d4fa8c68e2d0fce290fe58923187b.zip |
Verify consensus info and the acking's signature (#63)
Diffstat (limited to 'core')
-rw-r--r-- | core/consensus.go | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/core/consensus.go b/core/consensus.go index 36e54ec..d5ce923 100644 --- a/core/consensus.go +++ b/core/consensus.go @@ -44,9 +44,14 @@ func (e *ErrMissingBlockInfo) Error() string { // Errors for consensus core. var ( - ErrIncorrectHash = fmt.Errorf("hash of block is incorrect") - ErrIncorrectSignature = fmt.Errorf("signature of block is incorrect") - ErrGenesisBlockNotEmpty = fmt.Errorf("genesis block should be empty") + ErrIncorrectHash = fmt.Errorf( + "hash of block is incorrect") + ErrIncorrectSignature = fmt.Errorf( + "signature of block is incorrect") + ErrIncorrectCompactionChainAck = fmt.Errorf( + "compaction chain ack of block is incorrect") + ErrGenesisBlockNotEmpty = fmt.Errorf( + "genesis block should be empty") ) // Consensus implements DEXON Consensus algorithm. @@ -115,11 +120,32 @@ func (con *Consensus) sanityCheck(blockConv types.BlockConverter) (err error) { return ErrIncorrectSignature } + // Check the compaction chain info. + if ackingBlockHash := + b.CompactionChainAck.AckingBlockHash; (ackingBlockHash != common.Hash{}) { + ackingBlock, err := con.db.Get(ackingBlockHash) + if err != nil { + return err + } + hash, err := hashConsensusInfo(&ackingBlock) + if err != nil { + return err + } + pubKey, err := con.sigToPub(hash, + b.CompactionChainAck.ConsensusInfoSignature) + if err != nil { + return err + } + if !b.ProposerID.Equal(crypto.Keccak256Hash(pubKey.Bytes())) { + return ErrIncorrectCompactionChainAck + } + } return nil } // ProcessBlock is the entry point to submit one block to a Consensus instance. func (con *Consensus) ProcessBlock(blockConv types.BlockConverter) (err error) { + // TODO(jimmy-dexon): BlockConverter.Block() is called twice in this method. if err := con.sanityCheck(blockConv); err != nil { return err } |