Skip to content

Commit 5725c16

Browse files
committed
fix: only decode once
1 parent ee6dffd commit 5725c16

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

consensus/propagation/have_wants.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,13 @@ func (blockProp *Reactor) handleWants(peer p2p.ID, wants *proptypes.WantParts) {
190190

191191
for _, partIndex := range canSend.GetTrueIndices() {
192192
part, _ := parts.GetPart(uint32(partIndex))
193+
partBz := make([]byte, len(part.Bytes))
194+
copy(partBz, part.Bytes)
193195
rpart := &propproto.RecoveryPart{
194196
Height: height,
195197
Round: round,
196198
Index: uint32(partIndex),
197-
Data: part.Bytes,
199+
Data: partBz,
198200
}
199201
if wants.Prove {
200202
rpart.Proof = part.Proof.ToProto()
@@ -290,7 +292,13 @@ func (blockProp *Reactor) handleRecoveryPart(peer p2p.ID, part *proptypes.Recove
290292
// during catchup. todo: use the bool found in the state instead of checking
291293
// for nil.
292294
if parts.CanDecode() {
293-
err := parts.Decode(blockProp.codec)
295+
if parts.IsDecoding.Load() {
296+
return
297+
}
298+
parts.IsDecoding.Store(true)
299+
defer parts.IsDecoding.Store(false)
300+
301+
err := parts.Decode()
294302
if err != nil {
295303
blockProp.Logger.Error("failed to decode parts", "peer", peer, "height", part.Height, "round", part.Round, "error", err)
296304
return
@@ -318,11 +326,13 @@ func (blockProp *Reactor) handleRecoveryPart(peer p2p.ID, part *proptypes.Recove
318326
go func(height int64, round int32, parts *proptypes.CombinedPartSet) {
319327
for i := uint32(0); i < parts.Total(); i++ {
320328
p, _ := parts.GetPart(i)
329+
pbz := make([]byte, len(p.Bytes))
330+
copy(pbz, p.Bytes)
321331
msg := &proptypes.RecoveryPart{
322332
Height: height,
323333
Round: round,
324334
Index: p.Index,
325-
Data: p.Bytes,
335+
Data: pbz,
326336
}
327337
blockProp.clearWants(msg)
328338
}

consensus/propagation/types/combined_partset.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"fmt"
66
"sync"
7+
"sync/atomic"
78

89
"github.com/tendermint/tendermint/crypto/merkle"
910
"github.com/tendermint/tendermint/libs/bits"
@@ -18,6 +19,8 @@ type CombinedPartSet struct {
1819
parity *types.PartSet // holds parity parts (logical indexes start at original.Total())
1920
lastLen uint32
2021
catchup bool
22+
23+
IsDecoding atomic.Bool
2124
}
2225

2326
// NewCombinedSetFromCompactBlock creates a new CombinedPartSet from a

0 commit comments

Comments
 (0)