From cb807ad79b318547a5e371c1fc4ce904e3bedf40 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Thu, 5 Oct 2023 08:55:05 +0300 Subject: refactor(tvix/nar-bridge): do root directory dgst check in uploader This check makes more sense there, and gives stronger semantics - Done() only succeeds if the other side successfully received everything, *and* came up with the same hashes as we did. Change-Id: I20b706961053fd00d22cc70e1c8cc859705587e0 Reviewed-on: https://cl.tvl.fyi/c/depot/+/9542 Tested-by: BuildkiteCI Autosubmit: flokli Reviewed-by: Connor Brewster --- tvix/nar-bridge/pkg/pathinfosvc/server.go | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) (limited to 'tvix/nar-bridge/pkg/pathinfosvc/server.go') diff --git a/tvix/nar-bridge/pkg/pathinfosvc/server.go b/tvix/nar-bridge/pkg/pathinfosvc/server.go index 0b573d2131..545966b204 100644 --- a/tvix/nar-bridge/pkg/pathinfosvc/server.go +++ b/tvix/nar-bridge/pkg/pathinfosvc/server.go @@ -200,31 +200,12 @@ func (p *PathInfoServiceServer) Get(ctx context.Context, getPathInfoRequest *sto // Close the directories uploader. This ensures the DirectoryService has // properly persisted all Directory messages sent. - directoriesPutResponse, err := directoriesUploader.Done() - if err != nil { + if _, err := directoriesUploader.Done(); err != nil { log.WithError(err).Error("error during directory upload") return nil, status.Error(codes.Internal, "error during directory upload") } - // If we uploaded directories (so directoriesPutResponse doesn't return null), - // the RootDigest field in directoriesPutResponse should match the digest - // returned in importedPathInfo. - // This check ensures the directory service came up with the same root hash as we did. - if directoriesPutResponse != nil { - rootDigestPathInfo := pathInfo.GetNode().GetDirectory().GetDigest() - rootDigestDirectoriesPutResponse := directoriesPutResponse.GetRootDigest() - - log := log.WithFields(logrus.Fields{ - "root_digest_pathinfo": rootDigestPathInfo, - "root_digest_directories_put_resp": rootDigestDirectoriesPutResponse, - }) - if !bytes.Equal(rootDigestPathInfo, rootDigestDirectoriesPutResponse) { - log.Errorf("returned root digest doesn't match what's calculated") - return nil, status.Error(codes.Internal, "error in root digest calculation") - } - } - // Compare NAR hash in the NARInfo with the one we calculated while reading the NAR // We already checked above that the digest is in sha256. importedNarSha256 := pathInfo.GetNarinfo().GetNarSha256() -- cgit 1.4.1