From f16a9fb2dd533697f6f615a0ec22bbe9cce9b1e3 Mon Sep 17 00:00:00 2001 From: MacOMNI <414294494@qq.com> Date: Mon, 19 Aug 2024 15:26:56 +0800 Subject: [PATCH 1/6] #update ignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index a1e56cda..6ac8b77e 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ target # static lib files .lib/ +tasks.json From 250f0528d5943122818de64b7683c1e6c9a0de70 Mon Sep 17 00:00:00 2001 From: MacOMNI <414294494@qq.com> Date: Mon, 19 Aug 2024 16:35:00 +0800 Subject: [PATCH 2/6] try to fix ExtrinsicPreimages issue --- Blockchain/Sources/Blockchain/Runtime.swift | 4 ++-- .../Sources/Blockchain/Types/ExtrinsicPreimages.swift | 10 +++++----- Utils/Sources/Utils/FixedSizeData.swift | 4 ++++ 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Blockchain/Sources/Blockchain/Runtime.swift b/Blockchain/Sources/Blockchain/Runtime.swift index 7fa91749..37ea2cda 100644 --- a/Blockchain/Sources/Blockchain/Runtime.swift +++ b/Blockchain/Sources/Blockchain/Runtime.swift @@ -129,8 +129,8 @@ public final class Runtime { item.blocks += 1 item.tickets += UInt32(block.extrinsic.tickets.tickets.count) item.preimages += UInt32(block.extrinsic.preimages.preimages.count) - item.preimagesBytes += UInt32(block.extrinsic.preimages.preimages.reduce(into: 0) { $0 += $1.size }) - + // try to change preimage size to preimage data or serviceIndices + item.preimagesBytes += UInt32(block.extrinsic.preimages.preimages.reduce(into: 0) { $0 += $1.serviceIndices.getCount() }) acc[block.header.authorIndex] = item for report in block.extrinsic.reports.guarantees { diff --git a/Blockchain/Sources/Blockchain/Types/ExtrinsicPreimages.swift b/Blockchain/Sources/Blockchain/Types/ExtrinsicPreimages.swift index 9f883a33..311bef0d 100644 --- a/Blockchain/Sources/Blockchain/Types/ExtrinsicPreimages.swift +++ b/Blockchain/Sources/Blockchain/Types/ExtrinsicPreimages.swift @@ -4,11 +4,11 @@ import Utils public struct ExtrinsicPreimages: Sendable, Equatable { public struct SizeAndData: Sendable, Equatable { - public var size: DataLength + public var serviceIndices: ServiceIdentifier public var data: Data - public init(size: DataLength, data: Data) { - self.size = size + public init(serviceIndices: ServiceIdentifier, data: Data) { + self.serviceIndices = serviceIndices self.data = data } } @@ -44,13 +44,13 @@ extension ExtrinsicPreimages: ScaleCodec.Codable { extension ExtrinsicPreimages.SizeAndData: ScaleCodec.Codable { public init(from decoder: inout some ScaleCodec.Decoder) throws { try self.init( - size: decoder.decode(), + serviceIndices: decoder.decode(), data: decoder.decode() ) } public func encode(in encoder: inout some ScaleCodec.Encoder) throws { - try encoder.encode(size) + try encoder.encode(serviceIndices) try encoder.encode(data) } } diff --git a/Utils/Sources/Utils/FixedSizeData.swift b/Utils/Sources/Utils/FixedSizeData.swift index 248067c6..b2805753 100644 --- a/Utils/Sources/Utils/FixedSizeData.swift +++ b/Utils/Sources/Utils/FixedSizeData.swift @@ -14,6 +14,10 @@ public struct FixedSizeData: Sendable { public init() { data = Data(repeating: 0, count: T.value) } + + public func getCount() -> Int { + return data.count; + } } extension FixedSizeData: Equatable, Hashable {} From 100ea81e0cc2c5285ffe62bf5cf937ac29b68a94 Mon Sep 17 00:00:00 2001 From: MacOMNI <414294494@qq.com> Date: Mon, 19 Aug 2024 16:40:29 +0800 Subject: [PATCH 3/6] fix fixedSizeData issue --- Blockchain/Sources/Blockchain/Runtime.swift | 2 +- Utils/Sources/Utils/FixedSizeData.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Blockchain/Sources/Blockchain/Runtime.swift b/Blockchain/Sources/Blockchain/Runtime.swift index 37ea2cda..bcee5738 100644 --- a/Blockchain/Sources/Blockchain/Runtime.swift +++ b/Blockchain/Sources/Blockchain/Runtime.swift @@ -130,7 +130,7 @@ public final class Runtime { item.tickets += UInt32(block.extrinsic.tickets.tickets.count) item.preimages += UInt32(block.extrinsic.preimages.preimages.count) // try to change preimage size to preimage data or serviceIndices - item.preimagesBytes += UInt32(block.extrinsic.preimages.preimages.reduce(into: 0) { $0 += $1.serviceIndices.getCount() }) + item.preimagesBytes += UInt32(block.extrinsic.preimages.preimages.reduce(into: 0) { $0 += $1.serviceIndices.getCount }) acc[block.header.authorIndex] = item for report in block.extrinsic.reports.guarantees { diff --git a/Utils/Sources/Utils/FixedSizeData.swift b/Utils/Sources/Utils/FixedSizeData.swift index b2805753..9aa063bd 100644 --- a/Utils/Sources/Utils/FixedSizeData.swift +++ b/Utils/Sources/Utils/FixedSizeData.swift @@ -15,7 +15,7 @@ public struct FixedSizeData: Sendable { data = Data(repeating: 0, count: T.value) } - public func getCount() -> Int { + public var getCount:Int { return data.count; } } From 3b6085d450b54df368d85aeae68b07471048855c Mon Sep 17 00:00:00 2001 From: MacOMNI <414294494@qq.com> Date: Mon, 19 Aug 2024 16:47:39 +0800 Subject: [PATCH 4/6] try to fix ExtrinsicPreimages issue --- Blockchain/Sources/Blockchain/Runtime.swift | 2 +- Utils/Sources/Utils/FixedSizeData.swift | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/Blockchain/Sources/Blockchain/Runtime.swift b/Blockchain/Sources/Blockchain/Runtime.swift index bcee5738..ded76a5f 100644 --- a/Blockchain/Sources/Blockchain/Runtime.swift +++ b/Blockchain/Sources/Blockchain/Runtime.swift @@ -130,7 +130,7 @@ public final class Runtime { item.tickets += UInt32(block.extrinsic.tickets.tickets.count) item.preimages += UInt32(block.extrinsic.preimages.preimages.count) // try to change preimage size to preimage data or serviceIndices - item.preimagesBytes += UInt32(block.extrinsic.preimages.preimages.reduce(into: 0) { $0 += $1.serviceIndices.getCount }) + item.preimagesBytes += UInt32(block.extrinsic.preimages.preimages.count*ConstInt32.value) acc[block.header.authorIndex] = item for report in block.extrinsic.reports.guarantees { diff --git a/Utils/Sources/Utils/FixedSizeData.swift b/Utils/Sources/Utils/FixedSizeData.swift index 9aa063bd..248067c6 100644 --- a/Utils/Sources/Utils/FixedSizeData.swift +++ b/Utils/Sources/Utils/FixedSizeData.swift @@ -14,10 +14,6 @@ public struct FixedSizeData: Sendable { public init() { data = Data(repeating: 0, count: T.value) } - - public var getCount:Int { - return data.count; - } } extension FixedSizeData: Equatable, Hashable {} From 6b78d98ec20aa5f2d618cd667326ae0c28efb120 Mon Sep 17 00:00:00 2001 From: MacOMNI <414294494@qq.com> Date: Mon, 19 Aug 2024 17:24:32 +0800 Subject: [PATCH 5/6] #update Preimages serviceIndices --- Blockchain/Sources/Blockchain/Runtime.swift | 4 ++-- Blockchain/Sources/Blockchain/Types/ExtrinsicPreimages.swift | 4 ++-- Blockchain/Sources/Blockchain/Types/primitives.swift | 2 ++ 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Blockchain/Sources/Blockchain/Runtime.swift b/Blockchain/Sources/Blockchain/Runtime.swift index ded76a5f..537370da 100644 --- a/Blockchain/Sources/Blockchain/Runtime.swift +++ b/Blockchain/Sources/Blockchain/Runtime.swift @@ -129,8 +129,8 @@ public final class Runtime { item.blocks += 1 item.tickets += UInt32(block.extrinsic.tickets.tickets.count) item.preimages += UInt32(block.extrinsic.preimages.preimages.count) - // try to change preimage size to preimage data or serviceIndices - item.preimagesBytes += UInt32(block.extrinsic.preimages.preimages.count*ConstInt32.value) + // try to change preimage size to serviceIndices + item.preimagesBytes += UInt32(block.extrinsic.preimages.preimages.reduce(into: 0) { $0 += $1.serviceIndices }) acc[block.header.authorIndex] = item for report in block.extrinsic.reports.guarantees { diff --git a/Blockchain/Sources/Blockchain/Types/ExtrinsicPreimages.swift b/Blockchain/Sources/Blockchain/Types/ExtrinsicPreimages.swift index 311bef0d..c7cd5a3f 100644 --- a/Blockchain/Sources/Blockchain/Types/ExtrinsicPreimages.swift +++ b/Blockchain/Sources/Blockchain/Types/ExtrinsicPreimages.swift @@ -4,10 +4,10 @@ import Utils public struct ExtrinsicPreimages: Sendable, Equatable { public struct SizeAndData: Sendable, Equatable { - public var serviceIndices: ServiceIdentifier + public var serviceIndices: ServiceIndices public var data: Data - public init(serviceIndices: ServiceIdentifier, data: Data) { + public init(serviceIndices: ServiceIndices, data: Data) { self.serviceIndices = serviceIndices self.data = data } diff --git a/Blockchain/Sources/Blockchain/Types/primitives.swift b/Blockchain/Sources/Blockchain/Types/primitives.swift index 4f81431c..6880a6da 100644 --- a/Blockchain/Sources/Blockchain/Types/primitives.swift +++ b/Blockchain/Sources/Blockchain/Types/primitives.swift @@ -4,7 +4,9 @@ public typealias Balances = UInt64 public typealias ServiceIdentifier = Data32 public typealias TimeslotIndex = UInt32 public typealias Gas = UInt64 +public typealias ServiceIndices = UInt32 public typealias DataLength = UInt32 + public typealias ValidatorIndex = UInt32 // TODO: confirm this public typealias CoreIndex = UInt32 // TODO: confirm this public typealias TicketIndex = UInt8 From dcc3a4dce520603361f8ea820219fdbf4a3adb14 Mon Sep 17 00:00:00 2001 From: MacOMNI <414294494@qq.com> Date: Mon, 19 Aug 2024 17:50:55 +0800 Subject: [PATCH 6/6] delete ReportItem guarantors --- Blockchain/Sources/Blockchain/Types/State.swift | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Blockchain/Sources/Blockchain/Types/State.swift b/Blockchain/Sources/Blockchain/Types/State.swift index fec94ad3..2644d3ce 100644 --- a/Blockchain/Sources/Blockchain/Types/State.swift +++ b/Blockchain/Sources/Blockchain/Types/State.swift @@ -4,16 +4,13 @@ import Utils public struct State: Sendable { public struct ReportItem: Sendable, Equatable { public var workReport: WorkReport - public var guarantors: LimitedSizeArray public var timeslot: TimeslotIndex public init( workReport: WorkReport, - guarantors: LimitedSizeArray, timeslot: TimeslotIndex ) { self.workReport = workReport - self.guarantors = guarantors self.timeslot = timeslot } } @@ -204,14 +201,12 @@ extension State.ReportItem: ScaleCodec.Encodable { public init(config: ProtocolConfigRef, from decoder: inout some ScaleCodec.Decoder) throws { try self.init( workReport: WorkReport(config: config, from: &decoder), - guarantors: decoder.decode(), timeslot: decoder.decode() ) } public func encode(in encoder: inout some ScaleCodec.Encoder) throws { try encoder.encode(workReport) - try encoder.encode(guarantors) try encoder.encode(timeslot) } }