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

0.5.3 updates #260

Merged
merged 4 commits into from
Jan 5, 2025
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
21 changes: 17 additions & 4 deletions Blockchain/Sources/Blockchain/Types/WorkOutput.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
public enum WorkResultError: Error, CaseIterable {
case outOfGas
case panic
/// the number of exports made was invalidly reported
case badExports
/// the service's code was not available for lookup in state at the posterior state of the lookup-anchor block
case invalidCode
case codeTooLarge // code larger than MaxServiceCodeSize
/// code larger than MaxServiceCodeSize
case codeTooLarge
}

public struct WorkOutput: Sendable, Equatable {
Expand All @@ -21,6 +25,7 @@
case success
case outOfGas
case panic
case badExports
case invalidCode
case codeTooLarge
}
Expand All @@ -37,8 +42,10 @@
case 2:
self = .init(.failure(.panic))
case 3:
self = .init(.failure(.invalidCode))
self = .init(.failure(.badExports))

Check warning on line 45 in Blockchain/Sources/Blockchain/Types/WorkOutput.swift

View check run for this annotation

Codecov / codecov/patch

Blockchain/Sources/Blockchain/Types/WorkOutput.swift#L45

Added line #L45 was not covered by tests
case 4:
self = .init(.failure(.invalidCode))

Check warning on line 47 in Blockchain/Sources/Blockchain/Types/WorkOutput.swift

View check run for this annotation

Codecov / codecov/patch

Blockchain/Sources/Blockchain/Types/WorkOutput.swift#L47

Added line #L47 was not covered by tests
case 5:
self = .init(.failure(.codeTooLarge))
default:
throw DecodingError.dataCorrupted(
Expand All @@ -56,6 +63,8 @@
self = .init(.failure(.outOfGas))
} else if container.contains(.panic) {
self = .init(.failure(.panic))
} else if container.contains(.badExports) {
self = .init(.failure(.badExports))

Check warning on line 67 in Blockchain/Sources/Blockchain/Types/WorkOutput.swift

View check run for this annotation

Codecov / codecov/patch

Blockchain/Sources/Blockchain/Types/WorkOutput.swift#L66-L67

Added lines #L66 - L67 were not covered by tests
} else if container.contains(.invalidCode) {
self = .init(.failure(.invalidCode))
} else if container.contains(.codeTooLarge) {
Expand Down Expand Up @@ -84,10 +93,12 @@
try container.encode(UInt8(1))
case .panic:
try container.encode(UInt8(2))
case .invalidCode:
case .badExports:
try container.encode(UInt8(3))
case .codeTooLarge:
case .invalidCode:
try container.encode(UInt8(4))
case .codeTooLarge:
try container.encode(UInt8(5))

Check warning on line 101 in Blockchain/Sources/Blockchain/Types/WorkOutput.swift

View check run for this annotation

Codecov / codecov/patch

Blockchain/Sources/Blockchain/Types/WorkOutput.swift#L101

Added line #L101 was not covered by tests
}
}
} else {
Expand All @@ -101,6 +112,8 @@
try container.encodeNil(forKey: .outOfGas)
case .panic:
try container.encodeNil(forKey: .panic)
case .badExports:
try container.encodeNil(forKey: .badExports)

Check warning on line 116 in Blockchain/Sources/Blockchain/Types/WorkOutput.swift

View check run for this annotation

Codecov / codecov/patch

Blockchain/Sources/Blockchain/Types/WorkOutput.swift#L116

Added line #L116 was not covered by tests
case .invalidCode:
try container.encodeNil(forKey: .invalidCode)
case .codeTooLarge:
Expand Down
19 changes: 18 additions & 1 deletion Blockchain/Sources/Blockchain/Types/WorkPackage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// h
public var authorizationServiceIndex: ServiceIndex

// c
// u
public var authorizationCodeHash: Data32

// p
Expand Down Expand Up @@ -59,3 +59,20 @@
)
}
}

extension WorkPackage {
/// a: work-package’s implied authorizer, the hash of the concatenation of the authorization code
/// and the parameterization
public func authorizer(serviceAccounts: some ServiceAccounts) async throws -> Data32 {
try await Blake2b256.hash(authorizationCode(serviceAccounts: serviceAccounts), parameterizationBlob)
}

Check warning on line 68 in Blockchain/Sources/Blockchain/Types/WorkPackage.swift

View check run for this annotation

Codecov / codecov/patch

Blockchain/Sources/Blockchain/Types/WorkPackage.swift#L66-L68

Added lines #L66 - L68 were not covered by tests

/// c: the authorization code
public func authorizationCode(serviceAccounts: some ServiceAccounts) async throws -> Data {
try await serviceAccounts.historicalLookup(
serviceAccount: authorizationServiceIndex,
timeslot: context.lookupAnchor.timeslot,
preimageHash: authorizationCodeHash
) ?? Data()
}

Check warning on line 77 in Blockchain/Sources/Blockchain/Types/WorkPackage.swift

View check run for this annotation

Codecov / codecov/patch

Blockchain/Sources/Blockchain/Types/WorkPackage.swift#L71-L77

Added lines #L71 - L77 were not covered by tests
}
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,8 @@
}

public func gasCost(state: VMState) -> Gas {
let (reg8, reg9): (UInt32, UInt32) = state.readRegister(Registers.Index(raw: 8), Registers.Index(raw: 9))
return Gas(10) + Gas(reg8) + Gas(0x1_0000_0000) * Gas(reg9)
let reg9: UInt64 = state.readRegister(Registers.Index(raw: 9))
return Gas(10) + Gas(reg9)

Check warning on line 431 in Blockchain/Sources/Blockchain/VMInvocations/HostCall/HostCalls.swift

View check run for this annotation

Codecov / codecov/patch

Blockchain/Sources/Blockchain/VMInvocations/HostCall/HostCalls.swift#L430-L431

Added lines #L430 - L431 were not covered by tests
}

public func _callImpl(config: ProtocolConfigRef, state: VMState) async throws {
Expand All @@ -454,8 +454,6 @@
state.writeRegister(Registers.Index(raw: 7), HostCallResultCode.WHO.rawValue)
} else if gasLimit < destAcc!.minOnTransferGas {
state.writeRegister(Registers.Index(raw: 7), HostCallResultCode.LOW.rawValue)
} else if Gas(state.getGas()) < gasLimit {
state.writeRegister(Registers.Index(raw: 7), HostCallResultCode.HIGH.rawValue)
} else if let acc, acc.balance - amount < acc.thresholdBalance(config: config) {
state.writeRegister(Registers.Index(raw: 7), HostCallResultCode.CASH.rawValue)
} else if var acc {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ public enum HostCallResultCode: UInt64 {
case CASH = 0xFFFF_FFFF_FFFF_FFF9
/// LOW = 2^64 − 8: Gas limit too low.
case LOW = 0xFFFF_FFFF_FFFF_FFF8
/// HIGH = 2^64 − 9: Gas limit too high.
case HIGH = 0xFFFF_FFFF_FFFF_FFF7
/// HUH = 2^64 − 10: The item is already solicited or cannot be forgotten.
case HUH = 0xFFFF_FFFF_FFFF_FFF6
/// OK = 0: The return value indicating general success.
Expand Down
11 changes: 10 additions & 1 deletion Node/Package.resolved

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

6 changes: 3 additions & 3 deletions Node/Tests/NodeTests/chainfiles/devnet_allconfig_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
"totalNumberOfCores" : 1,
"totalNumberOfValidators" : 3,
"transferMemoSize" : 128,
"workPackageAuthorizerGas" : 10000000,
"workPackageRefineGas" : 10000000,
"totalAccumulationGas": 35000000,
"workPackageAuthorizerGas" : 50000000,
"workPackageRefineGas" : 5000000000,
"totalAccumulationGas": 3500000000,
"maxDepsInWorkReport": 8
},
"state" : {},
Expand Down