Skip to content

Commit

Permalink
replace h256 with data32 (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
xlc authored Jun 27, 2024
1 parent 17f0af2 commit e603d92
Show file tree
Hide file tree
Showing 14 changed files with 99 additions and 82 deletions.
4 changes: 2 additions & 2 deletions Blockchain/Sources/Blockchain/Blockchain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class Blockchain {
public private(set) var heads: [StateRef]
public private(set) var finalizedHead: StateRef

private var stateByBlockHash: [H256: StateRef] = [:]
private var stateByBlockHash: [Data32: StateRef] = [:]
private var stateByTimeslot: [TimeslotIndex: [StateRef]] = [:]

public init(heads: [StateRef], finalizedHead: StateRef) {
Expand Down Expand Up @@ -40,7 +40,7 @@ public class Blockchain {
}

extension Blockchain {
public subscript(hash: H256) -> StateRef? {
public subscript(hash: Data32) -> StateRef? {
stateByBlockHash[hash]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ import Utils

public struct AvailabilitySpecifications: Sendable {
// h
public var workPackageHash: H256
public var workPackageHash: Data32

// l
public var length: DataLength

// u
public var erasureRoot: H256
public var erasureRoot: Data32

// e
public var segmentRoot: H256
public var segmentRoot: Data32

public init(
workPackageHash: H256,
workPackageHash: Data32,
length: DataLength,
erasureRoot: H256,
segmentRoot: H256
erasureRoot: Data32,
segmentRoot: Data32
) {
self.workPackageHash = workPackageHash
self.length = length
Expand All @@ -31,10 +31,10 @@ extension AvailabilitySpecifications: Dummy {
public typealias Config = ProtocolConfigRef
public static func dummy(withConfig _: Config) -> AvailabilitySpecifications {
AvailabilitySpecifications(
workPackageHash: H256(),
workPackageHash: Data32(),
length: 0,
erasureRoot: H256(),
segmentRoot: H256()
erasureRoot: Data32(),
segmentRoot: Data32()
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Utils
public struct ExtrinsicAvailability: Sendable {
public struct AssuranceItem: Sendable {
// a
public var parentHash: H256
public var parentHash: Data32
// f
public var assurance: Data // bit string with length of Constants.TotalNumberOfCores TODO: use a BitString type
// v
Expand All @@ -14,7 +14,7 @@ public struct ExtrinsicAvailability: Sendable {
public var signature: Ed25519Signature

public init(
parentHash: H256,
parentHash: Data32,
assurance: Data,
validatorIndex: ValidatorIndex,
signature: Ed25519Signature
Expand Down
4 changes: 2 additions & 2 deletions Blockchain/Sources/Blockchain/Types/ExtrinsicJudgement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ public struct ExtrinsicJudgement: Sendable {
}
}

public var reportHash: H256
public var reportHash: Data32
public var signatures: ConfigFixedSizeArray<
SignatureItem,
ProtocolConfig.TwoThirdValidatorsPlusOne
>

public init(
reportHash: H256,
reportHash: Data32,
signatures: ConfigFixedSizeArray<
SignatureItem,
ProtocolConfig.TwoThirdValidatorsPlusOne
Expand Down
30 changes: 15 additions & 15 deletions Blockchain/Sources/Blockchain/Types/Header.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import Utils

public struct Header: Sendable {
public struct EpochMarker: Sendable {
public var randomness: H256
public var randomness: Data32
public var keys: ConfigFixedSizeArray<
BandersnatchPublicKey,
ProtocolConfig.TotalNumberOfValidators
>

public init(
randomness: H256,
randomness: Data32,
keys: ConfigFixedSizeArray<
BandersnatchPublicKey,
ProtocolConfig.TotalNumberOfValidators
Expand All @@ -22,13 +22,13 @@ public struct Header: Sendable {
}

// Hp: parent hash
public var parentHash: H256
public var parentHash: Data32

// Hr: prior state root
public var priorStateRoot: H256 // state root of the after parent block execution
public var priorStateRoot: Data32 // state root of the after parent block execution

// Hx: extrinsic hash
public var extrinsicsRoot: H256
public var extrinsicsRoot: Data32

// Ht: timeslot index
public var timeslotIndex: TimeslotIndex
Expand All @@ -50,7 +50,7 @@ public struct Header: Sendable {

// Hj: The judgement marker must contain exactly the sequence of report hashes judged not as
// confidently valid (i.e. either controversial or invalid).
public var judgementsMarkers: [H256]
public var judgementsMarkers: [Data32]

// Hk: a Bandersnatch block author key Hk
public var authorKey: BandersnatchPublicKey
Expand All @@ -62,16 +62,16 @@ public struct Header: Sendable {
public var seal: BandersnatchSignature

public init(
parentHash: H256,
priorStateRoot: H256,
extrinsicsRoot: H256,
parentHash: Data32,
priorStateRoot: Data32,
extrinsicsRoot: Data32,
timeslotIndex: TimeslotIndex,
epoch: EpochMarker?,
winningTickets: ConfigFixedSizeArray<
Ticket,
ProtocolConfig.EpochLength
>?,
judgementsMarkers: [H256],
judgementsMarkers: [Data32],
authorKey: BandersnatchPublicKey,
vrfSignature: BandersnatchSignature,
seal: BandersnatchSignature
Expand All @@ -93,9 +93,9 @@ extension Header: Dummy {
public typealias Config = ProtocolConfigRef
public static func dummy(withConfig _: Config) -> Header {
Header(
parentHash: H256(),
priorStateRoot: H256(),
extrinsicsRoot: H256(),
parentHash: Data32(),
priorStateRoot: Data32(),
extrinsicsRoot: Data32(),
timeslotIndex: 0,
epoch: nil,
winningTickets: nil,
Expand Down Expand Up @@ -152,7 +152,7 @@ extension Header.EpochMarker: ScaleCodec.Encodable {
}

extension Header {
public var hash: H256 {
H256() // TODO: implement this
public var hash: Data32 {
Data32() // TODO: implement this
}
}
8 changes: 4 additions & 4 deletions Blockchain/Sources/Blockchain/Types/JudgementsState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ import Utils

public struct JudgementsState: Sendable {
// ψa: The allow-set contains the hashes of all work-reports which were disputed and judged to be accurate.
public var allowSet: Set<H256>
public var allowSet: Set<Data32>

// ψb: The ban-set contains the hashes of all work-reports which were disputed and whose accuracy
// could not be confidently confirmed.
public var banSet: Set<H256>
public var banSet: Set<Data32>

// ψp; he punish-set is a set of keys of Bandersnatch keys which were found to have guaranteed
// a report which was confidently found to be invalid.
public var punishSet: Set<BandersnatchPublicKey>

public init(
allowSet: Set<H256>,
banSet: Set<H256>,
allowSet: Set<Data32>,
banSet: Set<Data32>,
punishSet: Set<BandersnatchPublicKey>
) {
self.allowSet = allowSet
Expand Down
28 changes: 14 additions & 14 deletions Blockchain/Sources/Blockchain/Types/RefinementContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,29 @@ import Utils
// at the point that the report’s corresponding work-package was evaluated.
public struct RefinementContext: Sendable {
public var anchor: (
headerHash: H256,
stateRoot: H256,
beefyRoot: H256
headerHash: Data32,
stateRoot: Data32,
beefyRoot: Data32
)

public var lokupAnchor: (
headerHash: H256,
headerHash: Data32,
timeslot: TimeslotIndex
)

public var prerequistieWorkPackage: H256?
public var prerequistieWorkPackage: Data32?

public init(
anchor: (
headerHash: H256,
stateRoot: H256,
beefyRoot: H256
headerHash: Data32,
stateRoot: Data32,
beefyRoot: Data32
),
lokupAnchor: (
headerHash: H256,
headerHash: Data32,
timeslot: TimeslotIndex
),
prerequistieWorkPackage: H256?
prerequistieWorkPackage: Data32?
) {
self.anchor = anchor
self.lokupAnchor = lokupAnchor
Expand All @@ -40,12 +40,12 @@ extension RefinementContext: Dummy {
public static func dummy(withConfig _: Config) -> RefinementContext {
RefinementContext(
anchor: (
headerHash: H256(),
stateRoot: H256(),
beefyRoot: H256()
headerHash: Data32(),
stateRoot: Data32(),
beefyRoot: Data32()
),
lokupAnchor: (
headerHash: H256(),
headerHash: Data32(),
timeslot: 0
),
prerequistieWorkPackage: nil
Expand Down
18 changes: 9 additions & 9 deletions Blockchain/Sources/Blockchain/Types/ServiceAccount.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,28 @@ import Utils

public struct ServiceAccount: Sendable {
public struct HashAndLength: Sendable, Hashable {
public var hash: H256
public var hash: Data32
public var length: DataLength

public init(hash: H256, length: DataLength) {
public init(hash: Data32, length: DataLength) {
self.hash = hash
self.length = length
}
}

// s
public var storage: [H256: Data]
public var storage: [Data32: Data]

// p
public var preimages: [H256: Data]
public var preimages: [Data32: Data]

// l
public var preimageInfos: [
HashAndLength: LimitedSizeArray<TimeslotIndex, ConstInt0, ConstInt3>
]

// c
public var codeHash: H256
public var codeHash: Data32

// b
public var balance: Balances
Expand All @@ -37,10 +37,10 @@ public struct ServiceAccount: Sendable {
public var onTransferGasLimit: Gas

public init(
storage: [H256: Data],
preimages: [H256: Data],
storage: [Data32: Data],
preimages: [Data32: Data],
preimageInfos: [HashAndLength: LimitedSizeArray<TimeslotIndex, ConstInt0, ConstInt3>],
codeHash: H256,
codeHash: Data32,
balance: Balances,
accumlateGasLimit: Gas,
onTransferGasLimit: Gas
Expand All @@ -62,7 +62,7 @@ extension ServiceAccount: Dummy {
storage: [:],
preimages: [:],
preimageInfos: [:],
codeHash: H256(),
codeHash: Data32(),
balance: 0,
accumlateGasLimit: 0,
onTransferGasLimit: 0
Expand Down
16 changes: 8 additions & 8 deletions Blockchain/Sources/Blockchain/Types/State.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public struct State: Sendable {
// α: The core αuthorizations pool.
public var coreAuthorizationPool: ConfigFixedSizeArray<
ConfigLimitedSizeArray<
H256,
Data32,
ProtocolConfig.Int0,
ProtocolConfig.MaxAuthorizationsPoolItems
>,
Expand All @@ -38,7 +38,7 @@ public struct State: Sendable {
public var serviceAccounts: [ServiceIdentifier: ServiceAccount]

// η: The eηtropy accumulator and epochal raηdomness.
public var entropyPool: (H256, H256, H256, H256)
public var entropyPool: (Data32, Data32, Data32, Data32)

// ι: The validator keys and metadata to be drawn from next.
public var validatorQueue: ConfigFixedSizeArray<
Expand Down Expand Up @@ -67,7 +67,7 @@ public struct State: Sendable {
// φ: The authorization queue.
public var authorizationQueue: ConfigFixedSizeArray<
ConfigFixedSizeArray<
H256,
Data32,
ProtocolConfig.MaxAuthorizationsQueueItems
>,
ProtocolConfig.TotalNumberOfCores
Expand All @@ -86,7 +86,7 @@ public struct State: Sendable {
public init(
coreAuthorizationPool: ConfigFixedSizeArray<
ConfigLimitedSizeArray<
H256,
Data32,
ProtocolConfig.Int0,
ProtocolConfig.MaxAuthorizationsPoolItems
>,
Expand All @@ -95,7 +95,7 @@ public struct State: Sendable {
lastBlock: Block,
safroleState: SafroleState,
serviceAccounts: [ServiceIdentifier: ServiceAccount],
entropyPool: (H256, H256, H256, H256),
entropyPool: (Data32, Data32, Data32, Data32),
validatorQueue: ConfigFixedSizeArray<
ValidatorKey, ProtocolConfig.TotalNumberOfValidators
>,
Expand All @@ -112,7 +112,7 @@ public struct State: Sendable {
timestamp: TimeslotIndex,
authorizationQueue: ConfigFixedSizeArray<
ConfigFixedSizeArray<
H256,
Data32,
ProtocolConfig.MaxAuthorizationsQueueItems
>,
ProtocolConfig.TotalNumberOfCores
Expand Down Expand Up @@ -150,15 +150,15 @@ extension State: Dummy {
lastBlock: Block.dummy(withConfig: config),
safroleState: SafroleState.dummy(withConfig: config),
serviceAccounts: [:],
entropyPool: (H256(), H256(), H256(), H256()),
entropyPool: (Data32(), Data32(), Data32(), Data32()),
validatorQueue: ConfigFixedSizeArray(withConfig: config, defaultValue: ValidatorKey.dummy(withConfig: config)),
currentValidators: ConfigFixedSizeArray(withConfig: config, defaultValue: ValidatorKey.dummy(withConfig: config)),
previousValidators: ConfigFixedSizeArray(withConfig: config, defaultValue: ValidatorKey.dummy(withConfig: config)),
reports: ConfigFixedSizeArray(withConfig: config, defaultValue: nil),
timestamp: 0,
authorizationQueue: ConfigFixedSizeArray(
withConfig: config,
defaultValue: ConfigFixedSizeArray(withConfig: config, defaultValue: H256())
defaultValue: ConfigFixedSizeArray(withConfig: config, defaultValue: Data32())
),
privilegedServiceIndices: (
empower: ServiceIdentifier(),
Expand Down
Loading

0 comments on commit e603d92

Please sign in to comment.