From bc67f77d86f92734c13d2c198f96d69044d05b81 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Mon, 10 Oct 2022 22:14:05 +0300 Subject: [PATCH] [#1329] tree: Fix sync applying Add the node position in a container and the container size to the CID descriptor that is passed to the `TreeApply`. Previously, `checkValid` does not allow any log operarations. Signed-off-by: Pavel Karpy --- pkg/services/tree/sync.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pkg/services/tree/sync.go b/pkg/services/tree/sync.go index 2d632d0eb9..32052d09e9 100644 --- a/pkg/services/tree/sync.go +++ b/pkg/services/tree/sync.go @@ -29,6 +29,11 @@ func (s *Service) Synchronize(ctx context.Context, cid cid.ID, treeID string) er return ErrNotInContainer } + var d pilorama.CIDDescriptor + d.CID = cid + d.Position = pos + d.Size = len(nodes) + lm, err := s.forest.TreeGetOpLog(cid, treeID, 0) if err != nil && !errors.Is(err, pilorama.ErrTreeNotFound) { return err @@ -50,7 +55,7 @@ func (s *Service) Synchronize(ctx context.Context, cid cid.ID, treeID string) er treeClient := NewTreeServiceClient(cc) for { - h, err := s.synchronizeSingle(ctx, cid, treeID, height, treeClient) + h, err := s.synchronizeSingle(ctx, d, treeID, height, treeClient) if height < h { height = h } @@ -64,9 +69,9 @@ func (s *Service) Synchronize(ctx context.Context, cid cid.ID, treeID string) er return nil } -func (s *Service) synchronizeSingle(ctx context.Context, cid cid.ID, treeID string, height uint64, treeClient TreeServiceClient) (uint64, error) { +func (s *Service) synchronizeSingle(ctx context.Context, d pilorama.CIDDescriptor, treeID string, height uint64, treeClient TreeServiceClient) (uint64, error) { rawCID := make([]byte, sha256.Size) - cid.Encode(rawCID) + d.CID.Encode(rawCID) for { newHeight := height @@ -96,7 +101,6 @@ func (s *Service) synchronizeSingle(ctx context.Context, cid cid.ID, treeID stri if err := m.Meta.FromBytes(lm.Meta); err != nil { return newHeight, err } - d := pilorama.CIDDescriptor{CID: cid} if err := s.forest.TreeApply(d, treeID, m); err != nil { return newHeight, err }