mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-24 09:25:21 +00:00
core: add txes duplication check on block.DecodeBinary
This commit is contained in:
parent
dbda721599
commit
fa467ce628
1 changed files with 12 additions and 9 deletions
|
@ -56,6 +56,17 @@ func (b *Block) RebuildMerkleRoot() error {
|
||||||
|
|
||||||
// Verify verifies the integrity of the block.
|
// Verify verifies the integrity of the block.
|
||||||
func (b *Block) Verify() error {
|
func (b *Block) Verify() error {
|
||||||
|
if b.Transactions != nil {
|
||||||
|
hashes := map[util.Uint256]bool{}
|
||||||
|
for _, tx := range b.Transactions {
|
||||||
|
if !hashes[tx.Hash()] {
|
||||||
|
hashes[tx.Hash()] = true
|
||||||
|
} else {
|
||||||
|
return errors.New("transaction duplication is not allowed")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
merkle, err := b.computeMerkleTree()
|
merkle, err := b.computeMerkleTree()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -142,15 +153,7 @@ func (b *Block) DecodeBinary(br *io.BinReader) {
|
||||||
txes[i] = tx
|
txes[i] = tx
|
||||||
}
|
}
|
||||||
b.Transactions = txes
|
b.Transactions = txes
|
||||||
merkle, err := b.computeMerkleTree()
|
br.Err = b.Verify()
|
||||||
if err != nil {
|
|
||||||
br.Err = err
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if !b.MerkleRoot.Equals(merkle.Root()) {
|
|
||||||
br.Err = errors.New("MerkleRoot mismatch")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// EncodeBinary encodes the block to the given BinWriter, implementing
|
// EncodeBinary encodes the block to the given BinWriter, implementing
|
||||||
|
|
Loading…
Reference in a new issue