network: use optimized decoder for transactions

NewTransactionFromBytes() works a bit faster and uses less memory.
This commit is contained in:
Roman Khimov 2021-08-04 23:11:53 +03:00
parent 892c9785ad
commit 1b186e046b

View file

@ -130,7 +130,6 @@ func (m *Message) decodePayload() error {
buf = d
}
r := io.NewBinReaderFromBuf(buf)
var p payload.Payload
switch m.Command {
case CMDVersion:
@ -154,7 +153,12 @@ func (m *Message) decodePayload() error {
case CMDHeaders:
p = &payload.Headers{StateRootInHeader: m.StateRootInHeader}
case CMDTX:
p = &transaction.Transaction{}
p, err := transaction.NewTransactionFromBytes(buf)
if err != nil {
return err
}
m.Payload = p
return nil
case CMDMerkleBlock:
p = &payload.MerkleBlock{}
case CMDPing, CMDPong:
@ -164,6 +168,7 @@ func (m *Message) decodePayload() error {
default:
return fmt.Errorf("can't decode command %s", m.Command.String())
}
r := io.NewBinReaderFromBuf(buf)
p.DecodeBinary(r)
if r.Err == nil || r.Err == payload.ErrTooManyHeaders {
m.Payload = p