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

Refine invocation #237

Merged
merged 3 commits into from
Dec 11, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ extension Ref where T == ProtocolConfig {
erasureCodedPieceSize: 684,
maxWorkPackageManifestEntries: 1 << 11,
maxEncodedWorkPackageSize: 12 * 1 << 20,
maxEncodedWorkReportSize: 96 * 1 << 10,
segmentSize: 4104,
maxWorkReportOutputSize: 96 * 1 << 10,
erasureCodedSegmentSize: 6,
ticketSubmissionEndSlot: 2,
pvmDynamicAddressAlignmentFactor: 2,
Expand Down Expand Up @@ -72,7 +73,8 @@ extension Ref where T == ProtocolConfig {
erasureCodedPieceSize: 684,
maxWorkPackageManifestEntries: 1 << 11,
maxEncodedWorkPackageSize: 12 * 1 << 20,
maxEncodedWorkReportSize: 96 * 1 << 10,
segmentSize: 4104,
maxWorkReportOutputSize: 96 * 1 << 10,
erasureCodedSegmentSize: 6,
ticketSubmissionEndSlot: 10,
pvmDynamicAddressAlignmentFactor: 2,
Expand Down Expand Up @@ -111,7 +113,8 @@ extension Ref where T == ProtocolConfig {
erasureCodedPieceSize: 684,
maxWorkPackageManifestEntries: 1 << 11,
maxEncodedWorkPackageSize: 12 * 1 << 20,
maxEncodedWorkReportSize: 96 * 1 << 10,
segmentSize: 4104,
maxWorkReportOutputSize: 96 * 1 << 10,
erasureCodedSegmentSize: 6,
ticketSubmissionEndSlot: 500,
pvmDynamicAddressAlignmentFactor: 2,
Expand Down
38 changes: 26 additions & 12 deletions Blockchain/Sources/Blockchain/Config/ProtocolConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,17 @@
// WM = 2^11: The maximum number of entries in a work-package manifest.
public var maxWorkPackageManifestEntries: Int

// WP = 12 * 2^20: The maximum size of an encoded work-package together with its extrinsic data and import impli-
// WB = 12 * 2^20: The maximum size of an encoded work-package together with its extrinsic data and import impli-
// cations, in octets.
public var maxEncodedWorkPackageSize: Int

// WR = 96 * 2^10: The maximum size of an encoded work-report in octets.
public var maxEncodedWorkReportSize: Int
// WG = WP*WE = 4104: The size of a segment in octets.
public var segmentSize: Int

// WS = 6: The size of an exported segment in erasure-coded pieces.
// WR = 48 * 2^10: The maximum total size of all output blobs in a work-report, in octets.
public var maxWorkReportOutputSize: Int

// WP = 6: The number of erasure-coded pieces in a segment.
public var erasureCodedSegmentSize: Int

// WT = 128: The size of a transfer memo in octets.
Expand Down Expand Up @@ -143,7 +146,8 @@
erasureCodedPieceSize: Int,
maxWorkPackageManifestEntries: Int,
maxEncodedWorkPackageSize: Int,
maxEncodedWorkReportSize: Int,
segmentSize: Int,
maxWorkReportOutputSize: Int,
erasureCodedSegmentSize: Int,
ticketSubmissionEndSlot: Int,
pvmDynamicAddressAlignmentFactor: Int,
Expand Down Expand Up @@ -180,7 +184,8 @@
self.erasureCodedPieceSize = erasureCodedPieceSize
self.maxWorkPackageManifestEntries = maxWorkPackageManifestEntries
self.maxEncodedWorkPackageSize = maxEncodedWorkPackageSize
self.maxEncodedWorkReportSize = maxEncodedWorkReportSize
self.segmentSize = segmentSize
self.maxWorkReportOutputSize = maxWorkReportOutputSize
self.erasureCodedSegmentSize = erasureCodedSegmentSize
self.ticketSubmissionEndSlot = ticketSubmissionEndSlot
self.pvmDynamicAddressAlignmentFactor = pvmDynamicAddressAlignmentFactor
Expand Down Expand Up @@ -260,8 +265,9 @@
? other.maxWorkPackageManifestEntries : maxWorkPackageManifestEntries,
maxEncodedWorkPackageSize: other.maxEncodedWorkPackageSize != 0
? other.maxEncodedWorkPackageSize : maxEncodedWorkPackageSize,
maxEncodedWorkReportSize: other.maxEncodedWorkReportSize != 0
? other.maxEncodedWorkReportSize : maxEncodedWorkReportSize,
segmentSize: other.segmentSize != 0 ? other.segmentSize : segmentSize,
maxWorkReportOutputSize: other.maxWorkReportOutputSize != 0
? other.maxWorkReportOutputSize : maxWorkReportOutputSize,
erasureCodedSegmentSize: other.erasureCodedSegmentSize != 0
? other.erasureCodedSegmentSize : erasureCodedSegmentSize,
ticketSubmissionEndSlot: other.ticketSubmissionEndSlot != 0
Expand Down Expand Up @@ -347,8 +353,9 @@
maxEncodedWorkPackageSize = try decode(
.maxEncodedWorkPackageSize, defaultValue: 0, required: required
)
maxEncodedWorkReportSize = try decode(
.maxEncodedWorkReportSize, defaultValue: 0, required: required
segmentSize = try decode(.segmentSize, defaultValue: 0, required: required)
maxWorkReportOutputSize = try decode(
.maxWorkReportOutputSize, defaultValue: 0, required: required
)
erasureCodedSegmentSize = try decode(
.erasureCodedSegmentSize, defaultValue: 0, required: required
Expand Down Expand Up @@ -579,10 +586,17 @@
}
}

public enum MaxEncodedWorkReportSize: ReadInt {
public enum SegmentSize: ReadInt {
public typealias TConfig = ProtocolConfigRef
public static func read(config: ProtocolConfigRef) -> Int {
config.value.segmentSize
}

Check warning on line 593 in Blockchain/Sources/Blockchain/Config/ProtocolConfig.swift

View check run for this annotation

Codecov / codecov/patch

Blockchain/Sources/Blockchain/Config/ProtocolConfig.swift#L591-L593

Added lines #L591 - L593 were not covered by tests
}

public enum MaxWorkReportOutputSize: ReadInt {
public typealias TConfig = ProtocolConfigRef
public static func read(config: ProtocolConfigRef) -> Int {
config.value.maxEncodedWorkReportSize
config.value.maxWorkReportOutputSize

Check warning on line 599 in Blockchain/Sources/Blockchain/Config/ProtocolConfig.swift

View check run for this annotation

Codecov / codecov/patch

Blockchain/Sources/Blockchain/Config/ProtocolConfig.swift#L599

Added line #L599 was not covered by tests
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
}

public protocol Accumulation: ServiceAccounts {
var timeslot: TimeslotIndex { get }
var privilegedServices: PrivilegedServices { get }
var validatorQueue: ConfigFixedSizeArray<
ValidatorKey, ProtocolConfig.TotalNumberOfValidators
Expand Down Expand Up @@ -359,6 +360,7 @@
config: config,
service: service,
serviceAccounts: &self,
timeslot: timeslot,

Check warning on line 363 in Blockchain/Sources/Blockchain/RuntimeProtocols/Accumulation.swift

View check run for this annotation

Codecov / codecov/patch

Blockchain/Sources/Blockchain/RuntimeProtocols/Accumulation.swift#L363

Added line #L363 was not covered by tests
transfers: transfers
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public protocol OnTransferFunction {
config: ProtocolConfigRef,
service: ServiceIndex,
serviceAccounts: inout some ServiceAccounts,
timeslot: TimeslotIndex,
transfers: [DeferredTransfers]
) async throws
}
2 changes: 2 additions & 0 deletions Blockchain/Sources/Blockchain/State/ServiceAccounts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public protocol ServiceAccounts {
serviceAccount index: ServiceIndex, preimageHash hash: Data32, length: UInt32
) async throws -> StateKeys.ServiceAccountPreimageInfoKey.Value?

func historicalLookup(serviceAccount index: ServiceIndex, timeslot: TimeslotIndex, preimageHash hash: Data32) async throws -> Data?

mutating func set(serviceAccount index: ServiceIndex, account: ServiceAccountDetails?)
mutating func set(serviceAccount index: ServiceIndex, storageKey key: Data32, value: Data?)
mutating func set(serviceAccount index: ServiceIndex, preimageHash hash: Data32, value: Data?)
Expand Down
24 changes: 24 additions & 0 deletions Blockchain/Sources/Blockchain/State/State.swift
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,29 @@
return try await backend.read(StateKeys.ServiceAccountPreimageInfoKey(index: index, hash: hash, length: length))
}

public func historicalLookup(
serviceAccount index: ServiceIndex,
timeslot: TimeslotIndex,
preimageHash hash: Data32
) async throws -> Data? {
if let preimage = try await get(serviceAccount: index, preimageHash: hash),
let preimageInfo = try await get(serviceAccount: index, preimageHash: hash, length: UInt32(preimage.count))
{
var isAvailable = false
if preimageInfo.count == 1 {
isAvailable = preimageInfo[0] <= timeslot
} else if preimageInfo.count == 2 {
isAvailable = preimageInfo[0] <= timeslot && timeslot < preimageInfo[1]
} else if preimageInfo.count == 3 {
isAvailable = preimageInfo[0] <= timeslot && timeslot < preimageInfo[1] && preimageInfo[2] <= timeslot
}

return isAvailable ? preimage : nil
} else {
return nil
}
}

Check warning on line 385 in Blockchain/Sources/Blockchain/State/State.swift

View check run for this annotation

Codecov / codecov/patch

Blockchain/Sources/Blockchain/State/State.swift#L368-L385

Added lines #L368 - L385 were not covered by tests

public mutating func set(serviceAccount index: ServiceIndex, account: ServiceAccountDetails?) {
layer[serviceAccount: index] = account
}
Expand Down Expand Up @@ -455,6 +478,7 @@
config _: ProtocolConfigRef,
service _: ServiceIndex,
serviceAccounts _: inout some ServiceAccounts,
timeslot _: TimeslotIndex,
transfers _: [DeferredTransfers]
) async throws {
fatalError("not implemented")
Expand Down
3 changes: 2 additions & 1 deletion Blockchain/Sources/Blockchain/Types/WorkReport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@
guard refinementContext.prerequisiteWorkPackages.count + lookup.count <= config.value.maxDepsInWorkReport else {
throw .tooManyDependencies
}
guard encodedSize <= config.value.maxEncodedWorkReportSize else {
let resultOutputSize = results.compactMap { result in try? result.output.result.get() }.reduce(0) { $0 + $1.count }
guard authorizationOutput.count + resultOutputSize <= config.value.maxWorkReportOutputSize else {

Check warning on line 94 in Blockchain/Sources/Blockchain/Types/WorkReport.swift

View check run for this annotation

Codecov / codecov/patch

Blockchain/Sources/Blockchain/Types/WorkReport.swift#L93-L94

Added lines #L93 - L94 were not covered by tests
throw .tooBig
}
guard coreIndex < UInt32(config.value.totalNumberOfCores) else {
Expand Down
Loading