From f3113f78b77662bd566f8382d426fda4213456bc Mon Sep 17 00:00:00 2001 From: lukechampine Date: Wed, 31 Jul 2019 17:32:14 -0400 Subject: [PATCH] merkle: Mark all trimmed sectors as changed --- merkle/proof.go | 11 ++++++----- renter/proto/session.go | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/merkle/proof.go b/merkle/proof.go index 7010ba6..4119ac8 100644 --- a/merkle/proof.go +++ b/merkle/proof.go @@ -225,8 +225,10 @@ func sectorsChanged(actions []renterhost.RPCWriteAction, numSectors int) []int { newNumSectors++ case renterhost.RPCWriteActionTrim: - newNumSectors -= int(action.A) - sectorsChanged[newNumSectors] = struct{}{} + for i := 0; i < int(action.A); i++ { + newNumSectors-- + sectorsChanged[newNumSectors] = struct{}{} + } case renterhost.RPCWriteActionSwap: sectorsChanged[int(action.A)] = struct{}{} @@ -328,9 +330,8 @@ func modifyProofRanges(proofIndices []int, actions []renterhost.RPCWriteAction, numSectors++ case renterhost.RPCWriteActionTrim: - n := int(action.A) - proofIndices = proofIndices[:len(proofIndices)-n] - numSectors -= n + proofIndices = proofIndices[:len(proofIndices)-int(action.A)] + numSectors -= int(action.A) case renterhost.RPCWriteActionSwap: case renterhost.RPCWriteActionUpdate: diff --git a/renter/proto/session.go b/renter/proto/session.go index ce79200..c94ea1d 100644 --- a/renter/proto/session.go +++ b/renter/proto/session.go @@ -343,7 +343,7 @@ func (s *Session) Write(actions []renterhost.RPCWriteAction) (err error) { leafHashes := merkleResp.OldLeafHashes oldRoot, newRoot := rev.NewFileMerkleRoot, merkleResp.NewMerkleRoot if !merkle.VerifyDiffProof(actions, numSectors, proofHashes, leafHashes, oldRoot, newRoot) { - err := errors.New("invalid Merkle proof for old root") + err := errors.New("invalid Merkle proof") s.sess.WriteResponse(nil, err) return err }