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/crypto.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/crypto.go')
-rw-r--r-- | core/crypto.go | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/core/crypto.go b/core/crypto.go index a0bacac..6fc0d1b 100644 --- a/core/crypto.go +++ b/core/crypto.go @@ -25,6 +25,19 @@ import ( "github.com/dexon-foundation/dexon-consensus-core/core/types" ) +func hashWitness(witness *types.Witness) (common.Hash, error) { + binaryTimestamp, err := witness.Timestamp.MarshalBinary() + if err != nil { + return common.Hash{}, err + } + binaryHeight := make([]byte, 8) + binary.LittleEndian.PutUint64(binaryHeight, witness.Height) + return crypto.Keccak256Hash( + binaryHeight, + binaryTimestamp, + witness.Data), nil +} + func hashBlock(block *types.Block) (common.Hash, error) { hashPosition := hashPosition(block.Position) // Handling Block.Acks. @@ -37,6 +50,10 @@ func hashBlock(block *types.Block) (common.Hash, error) { if err != nil { return common.Hash{}, err } + binaryWitness, err := hashWitness(&block.Witness) + if err != nil { + return common.Hash{}, err + } payloadHash := crypto.Keccak256Hash(block.Payload) hash := crypto.Keccak256Hash( @@ -45,7 +62,8 @@ func hashBlock(block *types.Block) (common.Hash, error) { hashPosition[:], hashAcks[:], binaryTimestamp[:], - payloadHash[:]) + payloadHash[:], + binaryWitness[:]) return hash, nil } |