network: fix MerkleBlock
serialization
1. It contains `block.Base` thus needs network magic. 2. TxCount should match number of hashes.
This commit is contained in:
parent
2d7b823f25
commit
63aebfeae3
2 changed files with 9 additions and 2 deletions
|
@ -159,7 +159,7 @@ func (m *Message) decodePayload() error {
|
|||
case CMDTX:
|
||||
p = &transaction.Transaction{Network: m.Network}
|
||||
case CMDMerkleBlock:
|
||||
p = &payload.MerkleBlock{}
|
||||
p = &payload.MerkleBlock{Network: m.Network}
|
||||
case CMDPing, CMDPong:
|
||||
p = &payload.Ping{}
|
||||
case CMDNotFound:
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
package payload
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
|
@ -9,6 +12,7 @@ import (
|
|||
// MerkleBlock represents a merkle block packet payload.
|
||||
type MerkleBlock struct {
|
||||
*block.Base
|
||||
Network netmode.Magic
|
||||
TxCount int
|
||||
Hashes []util.Uint256
|
||||
Flags []byte
|
||||
|
@ -16,7 +20,7 @@ type MerkleBlock struct {
|
|||
|
||||
// DecodeBinary implements Serializable interface.
|
||||
func (m *MerkleBlock) DecodeBinary(br *io.BinReader) {
|
||||
m.Base = &block.Base{}
|
||||
m.Base = &block.Base{Network: m.Network}
|
||||
m.Base.DecodeBinary(br)
|
||||
|
||||
txCount := int(br.ReadVarUint())
|
||||
|
@ -26,6 +30,9 @@ func (m *MerkleBlock) DecodeBinary(br *io.BinReader) {
|
|||
}
|
||||
m.TxCount = txCount
|
||||
br.ReadArray(&m.Hashes, m.TxCount)
|
||||
if txCount != len(m.Hashes) {
|
||||
br.Err = errors.New("invalid tx count")
|
||||
}
|
||||
m.Flags = br.ReadVarBytes((txCount + 7) / 8)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue