Skip to content

Commit

Permalink
fix target
Browse files Browse the repository at this point in the history
  • Loading branch information
xlc committed Jul 15, 2024
1 parent a8ec8c5 commit 3adfba6
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 27 deletions.
3 changes: 3 additions & 0 deletions Blockchain/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ let package = Package(
dependencies: [
"Blockchain",
.product(name: "Testing", package: "swift-testing"),
],
linkerSettings: [
.unsafeFlags(["-L../Utils/Sources/blst/lib"]),
]
),
],
Expand Down
14 changes: 9 additions & 5 deletions Blockchain/Sources/Blockchain/Safrole.swift
Original file line number Diff line number Diff line change
Expand Up @@ -173,16 +173,17 @@ func generateFallbackIndices(entropy: Data32, count: Int) throws -> [Int] {
let hash = try blake2b256(data)
let hash4 = hash.data[0 ..< 4]
let idx = try decode(UInt32.self, from: hash4)
return Int(idx) % count
return Int(idx)
}
}

func pickFallbackValidators(
entropy: Data32,
validators: ConfigFixedSizeArray<ValidatorKey, ProtocolConfig.TotalNumberOfValidators>
validators: ConfigFixedSizeArray<ValidatorKey, ProtocolConfig.TotalNumberOfValidators>,
count: Int
) throws -> [BandersnatchPublicKey] {
let indices = try generateFallbackIndices(entropy: entropy, count: validators.count)
return indices.map { validators[$0].bandersnatch }
let indices = try generateFallbackIndices(entropy: entropy, count: count)
return indices.map { validators[$0 % validators.count].bandersnatch }
}

extension Safrole {
Expand Down Expand Up @@ -239,7 +240,10 @@ extension Safrole {
} else if newEpoch == currentEpoch {
ticketsOrKeys
} else {
try .right(ConfigFixedSizeArray(config: config, array: pickFallbackValidators(entropy: entropy, validators: newCurrentValidators)))
try .right(ConfigFixedSizeArray(
config: config,
array: pickFallbackValidators(entropy: entropy, validators: newCurrentValidators, count: config.value.epochLength)
))
}

let postState = SafrolePostState(
Expand Down
3 changes: 3 additions & 0 deletions JAMTests/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ let package = Package(
"JAMTests",
.product(name: "Testing", package: "swift-testing"),
.product(name: "ScaleCodec", package: "ScaleCodec.swift"),
],
linkerSettings: [
.unsafeFlags(["-L../Utils/Sources/blst/lib"]),
]
),
],
Expand Down
25 changes: 5 additions & 20 deletions Utils/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,33 +33,18 @@ let package = Package(
"blst",
]
),
.target(
.systemLibrary(
name: "blst",
dependencies: [],
path: "./Sources/blst",
exclude: [
".github",
"./build",
"./src",
],
sources: [],
resources: [
.copy("lib/libblst.a"),
],
publicHeadersPath: "./include",
cSettings: [
.headerSearchPath("./include"),
],
linkerSettings: [
.unsafeFlags(["-L../Utils/Sources/blst/lib"]),
.linkedLibrary("blst"),
]
path: "Sources/blst/include"
),
.testTarget(
name: "UtilsTests",
dependencies: [
"Utils",
.product(name: "Testing", package: "swift-testing"),
],
linkerSettings: [
.unsafeFlags(["-L../Utils/Sources/blst/lib"]),
]
),
],
Expand Down
4 changes: 2 additions & 2 deletions Utils/Sources/Utils/ConfigLimitedSizeArray.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public struct ConfigLimitedSizeArray<T, TMinLength: ReadInt, TMaxLength: ReadInt
}

private func validate() {
assert(array.count >= minLength)
assert(array.count <= maxLength)
assert(array.count >= minLength, "count \(array.count) >= minLength \(minLength)")
assert(array.count <= maxLength, "count \(array.count) <= maxLength \(maxLength)")
}
}

Expand Down

0 comments on commit 3adfba6

Please sign in to comment.