Skip to content

Commit

Permalink
check duplicated transaction in block (#692)
Browse files Browse the repository at this point in the history
  • Loading branch information
laizy authored Nov 20, 2018
1 parent 5b63859 commit 71daa24
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion core/types/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package types

import (
"bytes"
"errors"
"fmt"
"io"

Expand Down Expand Up @@ -94,6 +95,7 @@ func (self *Block) Deserialization(source *common.ZeroCopySource) error {
}

var hashes []common.Uint256
mask := make(map[common.Uint256]bool)
for i := uint32(0); i < length; i++ {
transaction := new(Transaction)
// note currently all transaction in the block shared the same source
Expand All @@ -102,11 +104,18 @@ func (self *Block) Deserialization(source *common.ZeroCopySource) error {
return err
}
txhash := transaction.Hash()
if mask[txhash] {
return errors.New("duplicated transaction in block")
}
mask[txhash] = true
hashes = append(hashes, txhash)
self.Transactions = append(self.Transactions, transaction)
}

self.Header.TransactionsRoot = common.ComputeMerkleRoot(hashes)
root := common.ComputeMerkleRoot(hashes)
if self.Header.TransactionsRoot != root {
return errors.New("mismatched transaction root")
}

return nil
}
Expand Down

0 comments on commit 71daa24

Please sign in to comment.