Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make ValidPath (nar) hash optional if ca field is present #4059

Draft
wants to merge 18 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge remote-tracking branch 'upstream/master' into unified-contentAd…
…dresses-in-path-info
  • Loading branch information
Ericson2314 committed Sep 24, 2020
commit 014348f42d2d7b54f11b4cd439cb707eb4de6924
55 changes: 24 additions & 31 deletions src/libstore/build.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4010,18 +4010,19 @@ void DerivationGoal::registerOutputs()
outputPathName(drv->name, outputName),
refs.second,
refs.first),
narHashAndSize.first,
This<HashResult> { narHashAndSize },
};
newInfo0.narSize = narHashAndSize.second;
newInfo0.ca = FixedOutputHash {
.method = outputHash.method,
.hash = got,
newInfo0.viewCA() = ContentAddress {
FixedOutputHash {
.method = outputHash.method,
.hash = got,
}
};
newInfo0.references = refs.second;
if (refs.first)
newInfo0.references.insert(newInfo0.path);

assert(newInfo0.ca);
assert(newInfo0.optCA());
return newInfo0;
};

Expand All @@ -4037,8 +4038,7 @@ void DerivationGoal::registerOutputs()
std::string { requiredFinalPath.hashPart() });
rewriteOutput();
auto narHashAndSize = hashPath(htSHA256, actualPath);
ValidPathInfo newInfo0 { requiredFinalPath, narHashAndSize.first };
newInfo0.narSize = narHashAndSize.second;
ValidPathInfo newInfo0 { requiredFinalPath, This<HashResult> { narHashAndSize } };
auto refs = rewriteRefs();
newInfo0.references = refs.second;
if (refs.first)
Expand All @@ -4053,8 +4053,8 @@ void DerivationGoal::registerOutputs()

/* Check wanted hash */
Hash & wanted = dof.hash.hash;
assert(newInfo0.ca);
auto got = getContentAddressHash(*newInfo0.ca);
assert(newInfo0.optCA());
auto got = getContentAddressHash(*newInfo0.optCA());
if (wanted != got) {
/* Throw an error after registering the path as
valid. */
Expand All @@ -4072,6 +4072,9 @@ void DerivationGoal::registerOutputs()
},
}, output.output);

/* Always calculate nar hash for new builds. */
assert(newInfo.optNarHash().has_value());

/* Calculate where we'll move the output files. In the checking case we
will leave leave them where they are, for now, rather than move to
their usual "final destination" */
Expand All @@ -4085,7 +4088,7 @@ void DerivationGoal::registerOutputs()
if (!optFixedPath ||
worker.store.printStorePath(*optFixedPath) != finalDestPath)
{
assert(newInfo.ca);
assert(newInfo.optCA());
dynamicOutputLock.lockPaths({worker.store.toRealPath(finalDestPath)});
}

Expand All @@ -4101,7 +4104,7 @@ void DerivationGoal::registerOutputs()
} else if (worker.store.isValidPath(newInfo.path)) {
/* Path already exists because CA path produced by something
else. No moving needed. */
assert(newInfo.ca);
assert(newInfo.optCA());
} else {
auto destPath = worker.store.toRealPath(finalDestPath);
movePath(actualPath, destPath);
Expand All @@ -4110,10 +4113,9 @@ void DerivationGoal::registerOutputs()
}

if (buildMode == bmCheck) {
if (!worker.store.isValidPath(worker.store.parseStorePath(path))) continue;
ValidPathInfo info(*worker.store.queryPathInfo(worker.store.parseStorePath(path)));
assert(info.optNarHash()); // Always calculate nar hash for new builds.
if (hash.first != *info.optNarHash()) {
if (!worker.store.isValidPath(newInfo.path)) continue;
ValidPathInfo oldInfo(*worker.store.queryPathInfo(newInfo.path));
if (newInfo.optNarHash() != oldInfo.optNarHash()) {
worker.checkMismatch = true;
if (settings.runDiffHook || settings.keepFailed) {
auto dst = worker.store.toRealPath(finalDestPath + checkSuffix);
Expand Down Expand Up @@ -4156,25 +4158,16 @@ void DerivationGoal::registerOutputs()
worker.markContentsGood(newInfo.path);
}

ValidPathInfo info {
worker.store.parseStorePath(path),
This<HashResult> { hash },
};
info.references = std::move(references);
info.deriver = drvPath;
info.ultimate = true;
info.viewCA().add(ca);
worker.store.signPathInfo(info);

if (!info.references.empty()) {
// FIXME don't we have an experimental feature for fixed output with references?
info.viewCA() = std::nullopt;
}
newInfo.deriver = drvPath;
newInfo.ultimate = true;
worker.store.signPathInfo(newInfo);

finish(newInfo.path);

/* If it's a CA path, register it right away. This is necessary if it
isn't statically known so that we can safely unlock the path before
the next iteration */
if (newInfo.ca)
if (newInfo.optCA().has_value())
worker.store.registerValidPaths({newInfo});

infos.emplace(outputName, std::move(newInfo));
Expand Down
24 changes: 8 additions & 16 deletions src/libstore/daemon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,18 @@ static void writeValidPathInfo(
Sink & to,
std::shared_ptr<const ValidPathInfo> info)
{
auto narHashResult = *info->viewHashResultConst();
assert(narHashResult);
auto narHash = narHashResult->first;
auto narSize = narHashResult->second;
to << (info->deriver ? store->printStorePath(*info->deriver) : "")
<< info->narHash.to_string(Base16, false);
<< narHash.to_string(Base16, false);
writeStorePaths(*store, to, info->references);
to << info->registrationTime << info->narSize;
to << info->registrationTime << narSize;
if (GET_PROTOCOL_MINOR(clientVersion) >= 16) {
to << info->ultimate
<< info->sigs
<< renderContentAddress(info->ca);
<< renderContentAddress(*info->viewCAConst());
}
}

Expand Down Expand Up @@ -729,19 +733,7 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
if (info) {
if (GET_PROTOCOL_MINOR(clientVersion) >= 17)
to << 1;
auto narHashResult = *info->viewHashResultConst();
assert(narHashResult);
auto narHash = narHashResult->first;
auto narSize = narHashResult->second;
to << (info->deriver ? store->printStorePath(*info->deriver) : "")
<< narHash.to_string(Base16, false);
writeStorePaths(*store, to, info->references);
to << info->registrationTime << narSize;
if (GET_PROTOCOL_MINOR(clientVersion) >= 16) {
to << info->ultimate
<< info->sigs
<< renderContentAddress(*info->viewCAConst());
}
writeValidPathInfo(store, clientVersion, to, info);
} else {
assert(GET_PROTOCOL_MINOR(clientVersion) >= 17);
to << 0;
Expand Down
29 changes: 9 additions & 20 deletions src/libstore/remote-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -426,16 +426,20 @@ ref<const ValidPathInfo> RemoteStore::readValidPathInfo(ConnectionHandle & conn,
{
auto deriver = readString(conn->from);
auto narHash = Hash::parseAny(readString(conn->from), htSHA256);
auto info = make_ref<ValidPathInfo>(path, narHash);
auto info = make_ref<ValidPathInfo>(path, This<HashResult> { { narHash, 0 } });
if (deriver != "") info->deriver = parseStorePath(deriver);
info->references = readStorePaths<StorePathSet>(*this, conn->from);
conn->from >> info->registrationTime >> info->narSize;
conn->from >> info->registrationTime;
{
auto tempNarSize = readInt(conn->from);
auto tempHashResult = **info->viewHashResult();
info->viewHashResult() = { tempHashResult.first, tempNarSize };
}
if (GET_PROTOCOL_MINOR(conn->daemonVersion) >= 16) {
conn->from >> info->ultimate;
info->sigs = readStrings<StringSet>(conn->from);
info->ca = parseContentAddressOpt(readString(conn->from));
info->viewCA() = parseContentAddressOpt(readString(conn->from));
}
return info;
}


Expand All @@ -459,22 +463,7 @@ void RemoteStore::queryPathInfoUncached(const StorePath & path,
bool valid; conn->from >> valid;
if (!valid) throw InvalidPath("path '%s' is not valid", printStorePath(path));
}
auto deriver = readString(conn->from);
auto narHash = Hash::parseAny(readString(conn->from), htSHA256);
info = std::make_shared<ValidPathInfo>(path, This<HashResult> { { narHash, 0 } });
if (deriver != "") info->deriver = parseStorePath(deriver);
info->references = readStorePaths<StorePathSet>(*this, conn->from);
conn->from >> info->registrationTime;
{
auto tempNarSize = readInt(conn->from);
auto tempHashResult = **info->viewHashResult();
info->viewHashResult() = { tempHashResult.first, tempNarSize };
}
if (GET_PROTOCOL_MINOR(conn->daemonVersion) >= 16) {
conn->from >> info->ultimate;
info->sigs = readStrings<StringSet>(conn->from);
info->viewCA() = parseContentAddressOpt(readString(conn->from));
}
info = readValidPathInfo(conn, path);
}
callback(std::move(info));
} catch (...) { callback.rethrow(); }
Expand Down
39 changes: 38 additions & 1 deletion src/libutil/args.cc
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,44 @@ bool Args::processArgs(const Strings & args, bool finish)
return res;
}

static void hashTypeCompleter(size_t index, std::string_view prefix)
nlohmann::json Args::toJSON()
{
auto flags = nlohmann::json::object();

for (auto & [name, flag] : longFlags) {
auto j = nlohmann::json::object();
if (flag->shortName)
j["shortName"] = std::string(1, flag->shortName);
if (flag->description != "")
j["description"] = flag->description;
if (flag->category != "")
j["category"] = flag->category;
if (flag->handler.arity != ArityAny)
j["arity"] = flag->handler.arity;
if (!flag->labels.empty())
j["labels"] = flag->labels;
flags[name] = std::move(j);
}

auto args = nlohmann::json::array();

for (auto & arg : expectedArgs) {
auto j = nlohmann::json::object();
j["label"] = arg.label;
j["optional"] = arg.optional;
if (arg.handler.arity != ArityAny)
j["arity"] = arg.handler.arity;
args.push_back(std::move(j));
}

auto res = nlohmann::json::object();
res["description"] = description();
res["flags"] = std::move(flags);
res["args"] = std::move(args);
return res;
}

static void hashTypeCompleter(size_t index, std::string_view prefix)
{
for (auto & type : hashTypes)
if (hasPrefix(type, prefix))
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.