diff --git a/Blockchain/Sources/Blockchain/Config/ProtocolConfig.swift b/Blockchain/Sources/Blockchain/Config/ProtocolConfig.swift index 193f0cdf..7884d01c 100644 --- a/Blockchain/Sources/Blockchain/Config/ProtocolConfig.swift +++ b/Blockchain/Sources/Blockchain/Config/ProtocolConfig.swift @@ -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. diff --git a/Blockchain/Sources/Blockchain/RuntimeProtocols/Safrole.swift b/Blockchain/Sources/Blockchain/RuntimeProtocols/Safrole.swift index 76deae39..e478051a 100644 --- a/Blockchain/Sources/Blockchain/RuntimeProtocols/Safrole.swift +++ b/Blockchain/Sources/Blockchain/RuntimeProtocols/Safrole.swift @@ -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 diff --git a/Blockchain/Sources/Blockchain/State/StateKeys.swift b/Blockchain/Sources/Blockchain/State/StateKeys.swift index df80ebbe..556f5faf 100644 --- a/Blockchain/Sources/Blockchain/State/StateKeys.swift +++ b/Blockchain/Sources/Blockchain/State/StateKeys.swift @@ -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)! } @@ -316,7 +316,7 @@ public enum StateKeys { } public func encode() -> Data32 { - constructKey(index, length, hash.blake2b256hash().data) + constructKey(index, length, hash.blake2b256hash().data[2...]) } } } diff --git a/Blockchain/Sources/Blockchain/Types/EpochMarker.swift b/Blockchain/Sources/Blockchain/Types/EpochMarker.swift index 4506678e..01d0eb4c 100644 --- a/Blockchain/Sources/Blockchain/Types/EpochMarker.swift +++ b/Blockchain/Sources/Blockchain/Types/EpochMarker.swift @@ -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 } } diff --git a/Blockchain/Sources/Blockchain/VMInvocations/Invocations/AccumulateInvocation.swift b/Blockchain/Sources/Blockchain/VMInvocations/Invocations/AccumulateInvocation.swift index d65f7596..f129f0aa 100644 --- a/Blockchain/Sources/Blockchain/VMInvocations/Invocations/AccumulateInvocation.swift +++ b/Blockchain/Sources/Blockchain/VMInvocations/Invocations/AccumulateInvocation.swift @@ -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 diff --git a/Blockchain/Sources/Blockchain/VMInvocations/Invocations/OnTransferInvocation.swift b/Blockchain/Sources/Blockchain/VMInvocations/Invocations/OnTransferInvocation.swift index 6271b5e2..fedc57e4 100644 --- a/Blockchain/Sources/Blockchain/VMInvocations/Invocations/OnTransferInvocation.swift +++ b/Blockchain/Sources/Blockchain/VMInvocations/Invocations/OnTransferInvocation.swift @@ -28,7 +28,7 @@ extension OnTransferFunction { _ = await invokePVM( config: config, blob: account.codeHash.data, - pc: 15, + pc: 10, gas: gasLimitSum, argumentData: argument, ctx: ctx