Skip to content

Commit

Permalink
Refactor constants (#26)
Browse files Browse the repository at this point in the history
* make constants configuable

* finish refactoring
  • Loading branch information
xlc authored Jun 26, 2024
1 parent bde54bd commit 898419d
Show file tree
Hide file tree
Showing 36 changed files with 1,043 additions and 363 deletions.
2 changes: 2 additions & 0 deletions .swiftformat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--extensionacl on-declarations
--maxwidth 150
8 changes: 8 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,17 @@ disabled_rules:
- trailing_comma
- todo
- large_tuple
- file_length
- nesting
- opening_brace

excluded:
- "**/.build"

identifier_name:
min_length: 1

line_length:
warning: 140
error: 140
ignores_function_declarations: true
1 change: 1 addition & 0 deletions Blockchain/Sources/Blockchain/BlockAuthor.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
public class BlockAuthor {}
6 changes: 3 additions & 3 deletions Blockchain/Sources/Blockchain/Blockchain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ public class Blockchain {
}
}

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

subscript(index: TimeslotIndex) -> [StateRef]? {
public subscript(index: TimeslotIndex) -> [StateRef]? {
stateByTimeslot[index]
}
}
78 changes: 78 additions & 0 deletions Blockchain/Sources/Blockchain/Config/ProtocolConfig+Preset.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import Utils

extension Ref where T == ProtocolConfig {
// TODO: pick some good numbers for dev env
public static let dev = Ref(ProtocolConfig(
auditTranchePeriod: 8,
additionalMinBalancePerStateItem: 10,
additionalMinBalancePerStateByte: 1,
serviceMinBalance: 100,
totalNumberOfCores: 341,
preimagePurgePeriod: 28800,
epochLength: 600,
auditBiasFactor: 2,
coreAccumulationGas: 10_000_000, // TODO: check this
workPackageAuthorizerGas: 10_000_000, // TODO: check this
workPackageRefineGas: 10_000_000, // TODO: check this
recentHistorySize: 8,
maxWorkItems: 4,
maxTicketsPerExtrinsic: 16,
maxLookupAnchorAge: 14400,
transferMemoSize: 128,
ticketEntriesPerValidator: 2,
maxAuthorizationsPoolItems: 8,
slotPeriodSeconds: 6,
maxAuthorizationsQueueItems: 80,
coreAssignmentRotationPeriod: 10,
maxServiceCodeSize: 4_000_000,
preimageReplacementPeriod: 5,
totalNumberOfValidators: 1023,
erasureCodedPieceSize: 684,
maxWorkPackageManifestEntries: 1 << 11,
maxEncodedWorkPackageSize: 12 * 1 << 20,
maxEncodedWorkReportSize: 96 * 1 << 10,
erasureCodedSegmentSize: 6,
ticketSubmissionEndSlot: 500,
pvmDynamicAddressAlignmentFactor: 4,
pvmProgramInitInputDataSize: 1 << 24,
pvmProgramInitPageSize: 1 << 14,
pvmProgramInitSegmentSize: 1 << 16
))

public static let mainnet = Ref(ProtocolConfig(
auditTranchePeriod: 8,
additionalMinBalancePerStateItem: 10,
additionalMinBalancePerStateByte: 1,
serviceMinBalance: 100,
totalNumberOfCores: 341,
preimagePurgePeriod: 28800,
epochLength: 600,
auditBiasFactor: 2,
coreAccumulationGas: 10_000_000, // TODO: check this
workPackageAuthorizerGas: 10_000_000, // TODO: check this
workPackageRefineGas: 10_000_000, // TODO: check this
recentHistorySize: 8,
maxWorkItems: 4,
maxTicketsPerExtrinsic: 16,
maxLookupAnchorAge: 14400,
transferMemoSize: 128,
ticketEntriesPerValidator: 2,
maxAuthorizationsPoolItems: 8,
slotPeriodSeconds: 6,
maxAuthorizationsQueueItems: 80,
coreAssignmentRotationPeriod: 10,
maxServiceCodeSize: 4_000_000,
preimageReplacementPeriod: 5,
totalNumberOfValidators: 1023,
erasureCodedPieceSize: 684,
maxWorkPackageManifestEntries: 1 << 11,
maxEncodedWorkPackageSize: 12 * 1 << 20,
maxEncodedWorkReportSize: 96 * 1 << 10,
erasureCodedSegmentSize: 6,
ticketSubmissionEndSlot: 500,
pvmDynamicAddressAlignmentFactor: 4,
pvmProgramInitInputDataSize: 1 << 24,
pvmProgramInitPageSize: 1 << 14,
pvmProgramInitSegmentSize: 1 << 16
))
}
Loading

0 comments on commit 898419d

Please sign in to comment.