Skip to content

Commit

Permalink
small changes
Browse files Browse the repository at this point in the history
  • Loading branch information
qiweiii committed Nov 20, 2024
1 parent 7fcb90c commit b05f062
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Blockchain/Sources/Blockchain/Config/ProtocolConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public struct ProtocolConfig: Sendable, Codable, Equatable {
// P = 6: The slot period, in seconds.
public var slotPeriodSeconds: Int

// Q = 80: The maximum number of items in the authorizations queue.
// Q = 80: The number of items in the authorizations queue.
public var maxAuthorizationsQueueItems: Int

// R = 10: The rotation period of validator-core assignments, in timeslots.
Expand Down
3 changes: 2 additions & 1 deletion Blockchain/Sources/Blockchain/RuntimeProtocols/Safrole.swift
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,8 @@ extension Safrole {
}

let epochMark = try isEpochChange ? EpochMarker(
entropy: newEntropyPool.1,
entropyOne: newEntropyPool.1,
entropyTwo: newEntropyPool.2,
validators: ConfigFixedSizeArray(config: config, array: newNextValidators.map(\.bandersnatch))
) : nil

Expand Down
24 changes: 12 additions & 12 deletions Blockchain/Sources/Blockchain/State/StateKeys.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,22 @@ private func constructKey(_ idx: UInt8, _ service: ServiceIndex) -> Data32 {
return Data32(data)!
}

private func constructKey(_ service: ServiceIndex, _ val: UInt32, _: Data) -> Data32 {
var data = Data(capacity: 32)
private func constructKey(_ service: ServiceIndex, _ val: UInt32, _ data: Data) -> Data32 {
var stateKey = Data(capacity: 32)

withUnsafeBytes(of: service) { servicePtr in
withUnsafeBytes(of: val) { valPtr in
data.append(servicePtr.load(as: UInt8.self))
data.append(valPtr.load(as: UInt8.self))
data.append(servicePtr.load(fromByteOffset: 1, as: UInt8.self))
data.append(valPtr.load(fromByteOffset: 1, as: UInt8.self))
data.append(servicePtr.load(fromByteOffset: 2, as: UInt8.self))
data.append(valPtr.load(fromByteOffset: 2, as: UInt8.self))
data.append(servicePtr.load(fromByteOffset: 3, as: UInt8.self))
data.append(valPtr.load(fromByteOffset: 3, as: UInt8.self))
stateKey.append(servicePtr.load(as: UInt8.self))
stateKey.append(valPtr.load(as: UInt8.self))
stateKey.append(servicePtr.load(fromByteOffset: 1, as: UInt8.self))
stateKey.append(valPtr.load(fromByteOffset: 1, as: UInt8.self))
stateKey.append(servicePtr.load(fromByteOffset: 2, as: UInt8.self))
stateKey.append(valPtr.load(fromByteOffset: 2, as: UInt8.self))
stateKey.append(servicePtr.load(fromByteOffset: 3, as: UInt8.self))
stateKey.append(valPtr.load(fromByteOffset: 3, as: UInt8.self))
}
}
data.append(contentsOf: data[relative: 0 ..< 24])
stateKey.append(contentsOf: data[relative: 0 ..< 24])
return Data32(data)!
}

Expand Down Expand Up @@ -316,7 +316,7 @@ public enum StateKeys {
}

public func encode() -> Data32 {
constructKey(index, length, hash.blake2b256hash().data)
constructKey(index, length, hash.blake2b256hash().data[2...])
}
}
}
9 changes: 6 additions & 3 deletions Blockchain/Sources/Blockchain/Types/EpochMarker.swift
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
import Utils

public struct EpochMarker: Sendable, Equatable, Codable {
public var entropy: Data32
public var entropyOne: Data32
public var entropyTwo: Data32
public var validators: ConfigFixedSizeArray<
BandersnatchPublicKey,
ProtocolConfig.TotalNumberOfValidators
>

public init(
entropy: Data32,
entropyOne: Data32,
entropyTwo: Data32,
validators: ConfigFixedSizeArray<
BandersnatchPublicKey,
ProtocolConfig.TotalNumberOfValidators
>
) {
self.entropy = entropy
self.entropyOne = entropyOne
self.entropyTwo = entropyTwo
self.validators = validators
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ extension AccumulateFunction {
let (exitReason, gas, output) = await invokePVM(
config: config,
blob: accumulatingAccountDetails.codeHash.data,
pc: 10,
pc: 5,
gas: gas,
argumentData: argument,
ctx: ctx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ extension OnTransferFunction {
_ = await invokePVM(
config: config,
blob: account.codeHash.data,
pc: 15,
pc: 10,
gas: gasLimitSum,
argumentData: argument,
ctx: ctx
Expand Down

0 comments on commit b05f062

Please sign in to comment.