network: use optimized decoder for transactions
NewTransactionFromBytes() works a bit faster and uses less memory.
This commit is contained in:
parent
892c9785ad
commit
1b186e046b
1 changed files with 7 additions and 2 deletions
|
@ -130,7 +130,6 @@ func (m *Message) decodePayload() error {
|
||||||
buf = d
|
buf = d
|
||||||
}
|
}
|
||||||
|
|
||||||
r := io.NewBinReaderFromBuf(buf)
|
|
||||||
var p payload.Payload
|
var p payload.Payload
|
||||||
switch m.Command {
|
switch m.Command {
|
||||||
case CMDVersion:
|
case CMDVersion:
|
||||||
|
@ -154,7 +153,12 @@ func (m *Message) decodePayload() error {
|
||||||
case CMDHeaders:
|
case CMDHeaders:
|
||||||
p = &payload.Headers{StateRootInHeader: m.StateRootInHeader}
|
p = &payload.Headers{StateRootInHeader: m.StateRootInHeader}
|
||||||
case CMDTX:
|
case CMDTX:
|
||||||
p = &transaction.Transaction{}
|
p, err := transaction.NewTransactionFromBytes(buf)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
m.Payload = p
|
||||||
|
return nil
|
||||||
case CMDMerkleBlock:
|
case CMDMerkleBlock:
|
||||||
p = &payload.MerkleBlock{}
|
p = &payload.MerkleBlock{}
|
||||||
case CMDPing, CMDPong:
|
case CMDPing, CMDPong:
|
||||||
|
@ -164,6 +168,7 @@ func (m *Message) decodePayload() error {
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("can't decode command %s", m.Command.String())
|
return fmt.Errorf("can't decode command %s", m.Command.String())
|
||||||
}
|
}
|
||||||
|
r := io.NewBinReaderFromBuf(buf)
|
||||||
p.DecodeBinary(r)
|
p.DecodeBinary(r)
|
||||||
if r.Err == nil || r.Err == payload.ErrTooManyHeaders {
|
if r.Err == nil || r.Err == payload.ErrTooManyHeaders {
|
||||||
m.Payload = p
|
m.Payload = p
|
||||||
|
|
Loading…
Reference in a new issue