From f5f560d903138486db7432885cbc6bb3f89f1c5c Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Thu, 6 Oct 2022 23:18:26 +0300 Subject: [PATCH] [#1329] tree: Do not sync trees that are from external containers Signed-off-by: Pavel Karpy --- pkg/services/tree/sync.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pkg/services/tree/sync.go b/pkg/services/tree/sync.go index 7f670795..2d632d0e 100644 --- a/pkg/services/tree/sync.go +++ b/pkg/services/tree/sync.go @@ -14,13 +14,21 @@ import ( "google.golang.org/grpc/credentials/insecure" ) +// ErrNotInContainer is returned when operation could not be performed +// because the node is not included in the container. +var ErrNotInContainer = errors.New("node is not in container") + // Synchronize tries to synchronize log starting from the last stored height. func (s *Service) Synchronize(ctx context.Context, cid cid.ID, treeID string) error { - nodes, _, err := s.getContainerNodes(cid) + nodes, pos, err := s.getContainerNodes(cid) if err != nil { return fmt.Errorf("can't get container nodes: %w", err) } + if pos < 0 { + return ErrNotInContainer + } + lm, err := s.forest.TreeGetOpLog(cid, treeID, 0) if err != nil && !errors.Is(err, pilorama.ErrTreeNotFound) { return err