Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
112 changes: 56 additions & 56 deletions Cargo.lock

Large diffs are not rendered by default.

18 changes: 10 additions & 8 deletions fabric/go/fabric.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ func (f *Fabric) ResolveAll(handles []string) (ResolvedBatch, error) {
if slicesEqual(batch, prevBatch) {
break
}
verified, err := f.resolveFlat(batch)
verified, err := f.resolveFlat(batch, true)
if err != nil {
return ResolvedBatch{}, err
}
Expand Down Expand Up @@ -629,7 +629,7 @@ func (f *Fabric) Export(handle string) ([]byte, error) {
if slicesEqual(batch, prevBatch) {
break
}
verified, err := f.resolveFlat(batch)
verified, err := f.resolveFlat(batch, false)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -699,7 +699,7 @@ func (f *Fabric) Publish(cert []byte, records []byte, secretKey []byte, primary
return f.Broadcast(msg)
}

func (f *Fabric) resolveFlat(handles []string) (*libveritas.VerifiedMessage, error) {
func (f *Fabric) resolveFlat(handles []string, hints bool) (*libveritas.VerifiedMessage, error) {
bySpace := make(map[string][]string)
for _, h := range handles {
space, label := parseHandle(h)
Expand All @@ -709,13 +709,15 @@ func (f *Fabric) resolveFlat(handles []string) (*libveritas.VerifiedMessage, err
var queries []Query
for space, labels := range bySpace {
q := Query{Space: space, Handles: labels}
f.mu.Lock()
if cached, ok := f.zoneCache[space]; ok {
if hint := epochHintFromZone(cached); hint != nil {
q.EpochHint = hint
if hints {
f.mu.Lock()
if cached, ok := f.zoneCache[space]; ok {
if hint := epochHintFromZone(cached); hint != nil {
q.EpochHint = hint
}
}
f.mu.Unlock()
}
f.mu.Unlock()
queries = append(queries, q)
}

Expand Down
2 changes: 1 addition & 1 deletion fabric/go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.22

require (
github.com/btcsuite/btcd/btcec/v2 v2.3.6
github.com/spacesprotocol/libveritas-go v0.1.2
github.com/spacesprotocol/libveritas-go v0.1.4
)

require (
Expand Down
4 changes: 2 additions & 2 deletions fabric/go/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ github.com/decred/dcrd/crypto/blake256 v1.0.0 h1:/8DMNYp9SGi5f0w7uCm6d6M4OU2rGFK
github.com/decred/dcrd/crypto/blake256 v1.0.0/go.mod h1:sQl2p6Y26YV+ZOcSTP6thNdn47hh8kt6rqSlvmrXFAc=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 h1:YLtO71vCjJRCBcrPMtQ9nqBsqpA1m5sE92cU+pd5Mcc=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1/go.mod h1:hyedUtir6IdtD/7lIxGeCxkaw7y45JueMRL4DIyJDKs=
github.com/spacesprotocol/libveritas-go v0.1.2 h1:uMhRnQaPWgDIJtYGXo9wO10aav36G8lmgWXK3gw73gc=
github.com/spacesprotocol/libveritas-go v0.1.2/go.mod h1:HXnX2FNL43ueJuedsQwX9GF5jRHYZLqXYfFLWz900H8=
github.com/spacesprotocol/libveritas-go v0.1.4 h1:FuTQO25UgTocr3HMZm/qQnR4SihDVqWZ33On7+AtFD8=
github.com/spacesprotocol/libveritas-go v0.1.4/go.mod h1:HXnX2FNL43ueJuedsQwX9GF5jRHYZLqXYfFLWz900H8=
22 changes: 12 additions & 10 deletions fabric/js/fabric-core/src/fabric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ export class Fabric {
let batch = lookup.start();
while (batch.length > 0) {
if (arraysEqual(batch, prevBatch)) break;
const verified = await this.resolveFlat(batch);
const verified = await this.resolveFlat(batch, false);
allCertBytes.push(...verified.certificates());
const zones = verified.zones();
prevBatch = batch;
Expand All @@ -568,7 +568,7 @@ export class Fabric {
}

/** Resolve a flat list of non-dotted handles in a single relay query. */
private async resolveFlat(handles: string[]): Promise<VerifiedMessageHandle> {
private async resolveFlat(handles: string[], hints = true): Promise<VerifiedMessageHandle> {
const bySpace = new Map<string, string[]>();
for (const h of handles) {
const { space, label } = parseHandle(h);
Expand All @@ -580,14 +580,16 @@ export class Fabric {
const queries: Query[] = [];
for (const [space, labels] of bySpace) {
const q: Query = { space, handles: labels };
const cached = this.zoneCache.get(space);
if (cached) {
const json = cached.zone.toJson();
if (json?.commitment?.onchain) {
q.epoch_hint = {
root: json.commitment.onchain.state_root,
height: json.commitment.onchain.block_height,
};
if (hints) {
const cached = this.zoneCache.get(space);
if (cached) {
const json = cached.zone.toJson();
if (json?.commitment?.onchain) {
q.epoch_hint = {
root: json.commitment.onchain.state_root,
height: json.commitment.onchain.block_height,
};
}
}
}
queries.push(q);
Expand Down
2 changes: 1 addition & 1 deletion fabric/js/fabric-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"dependencies": {
"@noble/curves": "^1.8.0",
"@spacesprotocol/fabric-core": "*",
"@spacesprotocol/libveritas": "^0.1.2"
"@spacesprotocol/libveritas": "^0.1.4"
},
"devDependencies": {
"@types/node": "^25.5.0",
Expand Down
8 changes: 4 additions & 4 deletions fabric/js/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions fabric/kotlin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ dependencies {
// compileOnly — consumers provide the right variant at runtime:
// Android: org.spacesprotocol:libveritas (AAR)
// JVM: org.spacesprotocol:libveritas-jvm (JAR)
compileOnly("org.spacesprotocol:libveritas-jvm:0.1.2")
compileOnly("org.spacesprotocol:libveritas-jvm:0.1.4")
// CLI needs it at runtime
runtimeOnly("org.spacesprotocol:libveritas-jvm:0.1.2")
runtimeOnly("org.spacesprotocol:libveritas-jvm:0.1.4")

implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.3")
compileOnly("fr.acinq.secp256k1:secp256k1-kmp:0.17.3")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ class Fabric(
var batch = lookup.start()
while (batch.isNotEmpty()) {
if (batch == prevBatch) break
val verified = resolveFlat(batch)
val verified = resolveFlat(batch, true)
val zones = verified.zones()
prevBatch = batch
batch = lookup.advance(zones)
Expand All @@ -319,7 +319,7 @@ class Fabric(
var batch = lookup.start()
while (batch.isNotEmpty()) {
if (batch == prevBatch) break
val verified = resolveFlat(batch)
val verified = resolveFlat(batch, false)
allCertBytes.addAll(verified.certificates())
val zones = verified.zones()
prevBatch = batch
Expand All @@ -329,7 +329,7 @@ class Fabric(
return createCertificateChain(handle, allCertBytes)
}

private fun resolveFlat(handles: List<String>): VerifiedMessage {
private fun resolveFlat(handles: List<String>, hints: Boolean): VerifiedMessage {
val bySpace = mutableMapOf<String, MutableList<String>>()
for (h in handles) {
val (space, label) = parseHandle(h)
Expand All @@ -339,9 +339,11 @@ class Fabric(
val queries = mutableListOf<Query>()
for ((space, labels) in bySpace) {
var epochHint: EpochHint? = null
synchronized(lock) {
zoneCache[space]?.let { cached ->
epochHintFromZone(cached)?.let { epochHint = it }
if (hints) {
synchronized(lock) {
zoneCache[space]?.let { cached ->
epochHintFromZone(cached)?.let { epochHint = it }
}
}
}
queries.add(Query(space = space, handles = labels, epochHint = epochHint))
Expand Down
19 changes: 10 additions & 9 deletions fabric/python/fabric/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ def resolve_all(self, handles: list[str]) -> ResolvedBatch:
while batch:
if batch == prev_batch:
break
verified = self._resolve_flat(batch)
verified = self._resolve_flat(batch, hints=True)
zones = verified.zones()
prev_batch = batch
batch = lookup.advance(zones)
Expand All @@ -344,7 +344,7 @@ def export(self, handle: str) -> bytes:
while batch:
if batch == prev_batch:
break
verified = self._resolve_flat(batch)
verified = self._resolve_flat(batch, hints=False)
all_cert_bytes.extend(verified.certificates())
zones = verified.zones()
prev_batch = batch
Expand Down Expand Up @@ -514,7 +514,7 @@ def _update_anchors(self, trust_id: Optional[str] = None, kind: str = ""):
else:
self._observed = trust_set

def _resolve_flat(self, handles: list[str]) -> lv.VerifiedMessage:
def _resolve_flat(self, handles: list[str], *, hints: bool = True) -> lv.VerifiedMessage:
by_space: dict[str, list[str]] = {}
for h in handles:
space, label = _parse_handle(h)
Expand All @@ -523,12 +523,13 @@ def _resolve_flat(self, handles: list[str]) -> lv.VerifiedMessage:
queries = []
for space, labels in by_space.items():
q = _Query(space=space, handles=labels)
with self._lock:
cached = self._zone_cache.get(space)
if cached is not None:
hint = _epoch_hint_from_zone(cached)
if hint is not None:
q.epoch_hint = hint
if hints:
with self._lock:
cached = self._zone_cache.get(space)
if cached is not None:
hint = _epoch_hint_from_zone(cached)
if hint is not None:
q.epoch_hint = hint
queries.append(q)

return self._query(_QueryRequest(queries=queries))
Expand Down
2 changes: 1 addition & 1 deletion fabric/python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "fabric-resolver"
version = "0.1.0"
description = "Python client for the certrelay fabric network"
requires-python = ">=3.10"
dependencies = ["libveritas>=0.1.2"]
dependencies = ["libveritas>=0.1.4"]

[project.optional-dependencies]
signing = ["coincurve"]
Expand Down
18 changes: 12 additions & 6 deletions fabric/rust/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ impl Fabric {
}
let strs: Vec<String> = batch.iter().map(|s| s.to_string()).collect();
let refs: Vec<&str> = strs.iter().map(|s| s.as_str()).collect();
let (verified, relay_url) = self.resolve_flat(&refs).await?;
let (verified, relay_url) = self.resolve_flat(&refs, true).await?;
prev_batch = batch;
batch = lookup.advance(&verified.zones);
all_zones.extend(verified.zones);
Expand Down Expand Up @@ -622,7 +622,7 @@ impl Fabric {
}
let strs: Vec<String> = batch.iter().map(|s| s.to_string()).collect();
let refs: Vec<&str> = strs.iter().map(|s| s.as_str()).collect();
let (verified, _relay_url) = self.resolve_flat(&refs).await?;
let (verified, _relay_url) = self.resolve_flat(&refs, false).await?;
prev_batch = batch;
batch = lookup.advance(&verified.zones);
all_verified.push(verified);
Expand All @@ -638,7 +638,11 @@ impl Fabric {
}

/// Resolve a flat list of non-dotted handles in a single relay query.
async fn resolve_flat(&self, handles: &[&str]) -> Result<(VerifiedMessage, String)> {
async fn resolve_flat(
&self,
handles: &[&str],
hints: bool,
) -> Result<(VerifiedMessage, String)> {
let mut by_space: HashMap<String, Vec<String>> = HashMap::new();
for &h in handles {
let sname = SName::try_from(h).map_err(|e| {
Expand All @@ -658,9 +662,11 @@ impl Fabric {
.into_iter()
.map(|(space, handles)| {
let mut q = Query::new(space.clone(), handles);
if let Some(zone) = self.root_cache.get(&space) {
if let Some(hint) = epoch_hint_from_zone(&zone) {
q = q.with_epoch_hint(hint);
if hints {
if let Some(zone) = self.root_cache.get(&space) {
if let Some(hint) = epoch_hint_from_zone(&zone) {
q = q.with_epoch_hint(hint);
}
}
}
q
Expand Down
2 changes: 1 addition & 1 deletion fabric/swift/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ let package = Package(
.executable(name: "fabric", targets: ["FabricCLI"]),
],
dependencies: [
.package(url: "https://github.com/spacesprotocol/libveritas-swift.git", exact: "0.1.2"),
.package(url: "https://github.com/spacesprotocol/libveritas-swift.git", exact: "0.1.4"),
.package(url: "https://github.com/21-DOT-DEV/swift-secp256k1.git", exact: "0.17.0"),
],
targets: [
Expand Down
24 changes: 13 additions & 11 deletions fabric/swift/Sources/Fabric/Fabric.swift
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ public final class Fabric: @unchecked Sendable {
var batch = lookup.start()
while !batch.isEmpty {
if batch == prevBatch { break }
let verified = try await resolveFlat(batch)
let verified = try await resolveFlat(batch, hints: true)
let zones = verified.zones()
prevBatch = batch
batch = try lookup.advance(zones: zones)
Expand All @@ -432,7 +432,7 @@ public final class Fabric: @unchecked Sendable {
var batch = lookup.start()
while !batch.isEmpty {
if batch == prevBatch { break }
let verified = try await resolveFlat(batch)
let verified = try await resolveFlat(batch, hints: false)
allCertBytes.append(contentsOf: verified.certificates())
let zones = verified.zones()
prevBatch = batch
Expand Down Expand Up @@ -472,7 +472,7 @@ public final class Fabric: @unchecked Sendable {
}

/// Resolve a flat list of non-dotted handles in a single relay query.
private func resolveFlat(_ handles: [String]) async throws -> VerifiedMessage {
private func resolveFlat(_ handles: [String], hints: Bool) async throws -> VerifiedMessage {
var bySpace = [String: [String]]()
for h in handles {
let parsed = parseHandle(h)
Expand All @@ -482,14 +482,16 @@ public final class Fabric: @unchecked Sendable {
var queries = [Query]()
for (space, labels) in bySpace {
var q = Query(space: space, handles: labels)
lock.lock()
let cached = zoneCache[space]
lock.unlock()
if let cached, case .exists(let stateRoot, _, _, let blockHeight, _) = cached.commitment {
q.epoch_hint = EpochHint(
root: stateRoot.map { String(format: "%02x", $0) }.joined(),
height: blockHeight
)
if hints {
lock.lock()
let cached = zoneCache[space]
lock.unlock()
if let cached, case .exists(let stateRoot, _, _, let blockHeight, _) = cached.commitment {
q.epoch_hint = EpochHint(
root: stateRoot.map { String(format: "%02x", $0) }.joined(),
height: blockHeight
)
}
}
queries.append(q)
}
Expand Down
Loading