From 1ef063bacde810005a367c1fe47b291e243bdd50 Mon Sep 17 00:00:00 2001 From: Bryan Chen Date: Wed, 19 Jun 2024 15:50:19 +1200 Subject: [PATCH] dummy run --- .../Blockchain/Types/SafroleState.swift | 4 +- .../Sources/Blockchain/Types/State.swift | 12 ++--- Boka/Package.resolved | 47 ++++++++++++++++++- Boka/Package.swift | 2 + Boka/Sources/Boka.swift | 4 +- Node/Sources/Node/Genesis.swift | 4 +- Node/Sources/Node/Node.swift | 5 +- Utils/Sources/Utils/LimitedSizeArray.swift | 2 +- Utils/Sources/Utils/Ref.swift | 10 +++- 9 files changed, 73 insertions(+), 17 deletions(-) diff --git a/Blockchain/Sources/Blockchain/Types/SafroleState.swift b/Blockchain/Sources/Blockchain/Types/SafroleState.swift index 3efd875a..4ba508c5 100644 --- a/Blockchain/Sources/Blockchain/Types/SafroleState.swift +++ b/Blockchain/Sources/Blockchain/Types/SafroleState.swift @@ -59,9 +59,9 @@ public struct SafroleState { extension SafroleState: Dummy { public static var dummy: SafroleState { SafroleState( - pendingValidators: [], + pendingValidators: FixedSizeArray(defaultValue: ValidatorKey.dummy), epochRoot: BandersnatchRingVRFRoot(), - slotSealerSeries: .left([]), + slotSealerSeries: .right(FixedSizeArray(defaultValue: BandersnatchPublicKey())), ticketAccumulator: [] ) } diff --git a/Blockchain/Sources/Blockchain/Types/State.swift b/Blockchain/Sources/Blockchain/Types/State.swift index bc1ea549..fab9d0d3 100644 --- a/Blockchain/Sources/Blockchain/Types/State.swift +++ b/Blockchain/Sources/Blockchain/Types/State.swift @@ -144,17 +144,17 @@ public typealias StateRef = Ref extension State: Dummy { public static var dummy: State { State( - coreAuthorizationPool: [], + coreAuthorizationPool: FixedSizeArray(defaultValue: []), lastBlock: Block.dummy, safroleState: SafroleState.dummy, serviceAccounts: [:], entropyPool: (H256(), H256(), H256(), H256()), - validatorQueue: [], - currentValidators: [], - previousValidators: [], - reports: [], + validatorQueue: FixedSizeArray(defaultValue: ValidatorKey.dummy), + currentValidators: FixedSizeArray(defaultValue: ValidatorKey.dummy), + previousValidators: FixedSizeArray(defaultValue: ValidatorKey.dummy), + reports: FixedSizeArray(defaultValue: nil), timestamp: 0, - authorizationQueue: [], + authorizationQueue: FixedSizeArray(defaultValue: FixedSizeArray(defaultValue: H256())), privilegedServiceIndices: ( empower: ServiceIdentifier(), assign: ServiceIdentifier(), diff --git a/Boka/Package.resolved b/Boka/Package.resolved index 65461619..e5aca38c 100644 --- a/Boka/Package.resolved +++ b/Boka/Package.resolved @@ -1,6 +1,24 @@ { - "originHash" : "c2c4ac49ab6304f22b8cf4828c0252cd6132c8f70c5f448a10f35a165e73f638", + "originHash" : "bd44440d7f85d30386716bbd2cc933f21b5ebbc0e75fbfc91dc6a138b6c8ce43", "pins" : [ + { + "identity" : "async-channels", + "kind" : "remoteSourceControl", + "location" : "https://github.com/gh123man/Async-Channels", + "state" : { + "branch" : "679ee7d", + "revision" : "679ee7d35e493e181be844dadbe78636cefaace4" + } + }, + { + "identity" : "scalecodec.swift", + "kind" : "remoteSourceControl", + "location" : "https://github.com/tesseract-one/ScaleCodec.swift.git", + "state" : { + "revision" : "af241cfa8491ac0312ff89ff0389c09879d41a74", + "version" : "0.3.1" + } + }, { "identity" : "swift-argument-parser", "kind" : "remoteSourceControl", @@ -9,6 +27,33 @@ "revision" : "0fbc8848e389af3bb55c182bc19ca9d5dc2f255b", "version" : "1.4.0" } + }, + { + "identity" : "swift-async-algorithms", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-async-algorithms", + "state" : { + "revision" : "6ae9a051f76b81cc668305ceed5b0e0a7fd93d20", + "version" : "1.0.1" + } + }, + { + "identity" : "swift-collections", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-collections.git", + "state" : { + "revision" : "ee97538f5b81ae89698fd95938896dec5217b148", + "version" : "1.1.1" + } + }, + { + "identity" : "tuples.swift", + "kind" : "remoteSourceControl", + "location" : "https://github.com/tesseract-one/Tuples.swift.git", + "state" : { + "revision" : "4d2cf7c64443cdf4df833d0bedd767bf9dbc49d9", + "version" : "0.1.3" + } } ], "version" : 3 diff --git a/Boka/Package.swift b/Boka/Package.swift index 64e5ff6c..09c0d8da 100644 --- a/Boka/Package.swift +++ b/Boka/Package.swift @@ -9,6 +9,7 @@ let package = Package( .macOS(.v14), ], dependencies: [ + .package(path: "../Node"), .package(url: "https://github.com/apple/swift-argument-parser", from: "1.4.0"), ], targets: [ @@ -17,6 +18,7 @@ let package = Package( .executableTarget( name: "Boka", dependencies: [ + "Node", .product(name: "ArgumentParser", package: "swift-argument-parser"), ] ), diff --git a/Boka/Sources/Boka.swift b/Boka/Sources/Boka.swift index fa09da91..1e0c42b9 100644 --- a/Boka/Sources/Boka.swift +++ b/Boka/Sources/Boka.swift @@ -5,10 +5,12 @@ // https://swiftpackageindex.com/apple/swift-argument-parser/documentation import ArgumentParser +import Node @main struct Boka: ParsableCommand { mutating func run() throws { - print("Hello, world!") + let node = try Node(genesis: .dev) + node.sayHello() } } diff --git a/Node/Sources/Node/Genesis.swift b/Node/Sources/Node/Genesis.swift index 032f703c..a9ffdfe4 100644 --- a/Node/Sources/Node/Genesis.swift +++ b/Node/Sources/Node/Genesis.swift @@ -7,12 +7,12 @@ public enum Genesis { } public extension Genesis { - func toState() -> StateRef { + func toState() throws -> StateRef { switch self { case .file: fatalError("TODO: not implemented") case .dev: - fatalError("TODO: not implemented") + StateRef.dummy } } } diff --git a/Node/Sources/Node/Node.swift b/Node/Sources/Node/Node.swift index 3cf4cc98..a586f944 100644 --- a/Node/Sources/Node/Node.swift +++ b/Node/Sources/Node/Node.swift @@ -3,8 +3,9 @@ import Blockchain public class Node { public private(set) var blockchain: Blockchain - public init(genesis: StateRef) { - blockchain = Blockchain(heads: [genesis], finalizedHead: genesis) + public init(genesis: Genesis) throws { + let genesisState = try genesis.toState() + blockchain = Blockchain(heads: [genesisState], finalizedHead: genesisState) } public func sayHello() { diff --git a/Utils/Sources/Utils/LimitedSizeArray.swift b/Utils/Sources/Utils/LimitedSizeArray.swift index d691e8fa..b9f97ec0 100644 --- a/Utils/Sources/Utils/LimitedSizeArray.swift +++ b/Utils/Sources/Utils/LimitedSizeArray.swift @@ -24,7 +24,7 @@ public struct LimitedSizeArray { private func validate() { assert(array.count >= Self.minLength) - assert(array.count < Self.maxLength) + assert(array.count <= Self.maxLength) } } diff --git a/Utils/Sources/Utils/Ref.swift b/Utils/Sources/Utils/Ref.swift index 0f1b606c..275527f0 100644 --- a/Utils/Sources/Utils/Ref.swift +++ b/Utils/Sources/Utils/Ref.swift @@ -1,4 +1,4 @@ -public class Ref { +public final class Ref { public let value: T public init(_ value: T) { @@ -6,7 +6,7 @@ public class Ref { } } -public class RefMut { +public final class RefMut { public var value: T public init(_ value: T) { @@ -29,3 +29,9 @@ extension Ref: Hashable where T: Hashable { hasher.combine(value) } } + +extension Ref: Dummy where T: Dummy { + public static var dummy: Ref { + Ref(T.dummy) + } +}