Skip to content

Commit

Permalink
0.5.3 updates (#260)
Browse files Browse the repository at this point in the history
* 0.5.3 updates

* fix comment

* add missing wp properties
  • Loading branch information
qiweiii authored Jan 5, 2025
1 parent 5749790 commit 8960041
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 15 deletions.
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 @@ import Foundation
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 @@ extension WorkOutput: Codable {
case success
case outOfGas
case panic
case badExports
case invalidCode
case codeTooLarge
}
Expand All @@ -37,8 +42,10 @@ extension WorkOutput: Codable {
case 2:
self = .init(.failure(.panic))
case 3:
self = .init(.failure(.invalidCode))
self = .init(.failure(.badExports))
case 4:
self = .init(.failure(.invalidCode))
case 5:
self = .init(.failure(.codeTooLarge))
default:
throw DecodingError.dataCorrupted(
Expand All @@ -56,6 +63,8 @@ extension WorkOutput: Codable {
self = .init(.failure(.outOfGas))
} else if container.contains(.panic) {
self = .init(.failure(.panic))
} else if container.contains(.badExports) {
self = .init(.failure(.badExports))
} else if container.contains(.invalidCode) {
self = .init(.failure(.invalidCode))
} else if container.contains(.codeTooLarge) {
Expand Down Expand Up @@ -84,10 +93,12 @@ extension WorkOutput: Codable {
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))
}
}
} else {
Expand All @@ -101,6 +112,8 @@ extension WorkOutput: Codable {
try container.encodeNil(forKey: .outOfGas)
case .panic:
try container.encodeNil(forKey: .panic)
case .badExports:
try container.encodeNil(forKey: .badExports)
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 @@ public struct WorkPackage: Sendable, Equatable, Codable {
// h
public var authorizationServiceIndex: ServiceIndex

// c
// u
public var authorizationCodeHash: Data32

// p
Expand Down Expand Up @@ -59,3 +59,20 @@ extension WorkPackage: Dummy {
)
}
}

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)
}

/// 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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,8 @@ public class Transfer: HostCall {
}

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)
}

public func _callImpl(config: ProtocolConfigRef, state: VMState) async throws {
Expand All @@ -454,8 +454,6 @@ public class Transfer: HostCall {
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

0 comments on commit 8960041

Please sign in to comment.