Skip to content

Commit

Permalink
Merge branch 'master' into dev_connection
Browse files Browse the repository at this point in the history
  • Loading branch information
MacOMNI committed Nov 13, 2024
2 parents 97c77e7 + 7fcb90c commit 2939432
Show file tree
Hide file tree
Showing 57 changed files with 1,957 additions and 776 deletions.
93 changes: 93 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: Coverage

on:
push:
branches: ["master"]
pull_request:
branches: ["master"]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
coverage:
name: Code Coverage
runs-on: [self-hosted, linux]
timeout-minutes: 30
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
submodules: recursive
- run: sudo apt-get update
- uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: librocksdb-dev libzstd-dev libbz2-dev liblz4-dev llvm
# - name: Cache SPM
# uses: actions/cache@v4
# with:
# path: '**/.build'
# key: ${{ runner.os }}-spm-${{ hashFiles('**/Package.resolved') }}
# restore-keys: |
# ${{ runner.os }}-spm-
- name: Cache Cargo
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Cache bandersnatch_vrfs static lib
uses: actions/cache@v4
with:
path: .lib/libbandersnatch_vrfs.a
key: ${{ runner.os }}-libs-libbandersnatch-${{ hashFiles('Utils/Sources/bandersnatch/**') }}
restore-keys: |
${{ runner.os }}-libs-libbandersnatch
- name: Cache bls static lib
uses: actions/cache@v4
with:
path: .lib/libbls.a
key: ${{ runner.os }}-libs-libbls-${{ hashFiles('Utils/Sources/bls/**') }}
restore-keys: |
${{ runner.os }}-libs-libbls
- name: Cache erasure-coding static lib
uses: actions/cache@v4
with:
path: .lib/libec.a
key: ${{ runner.os }}-libs-libec-${{ hashFiles('Utils/Sources/erasure-coding/**') }}
restore-keys: |
${{ runner.os }}-libs-libec
- name: Setup Swift
uses: SwiftyLab/setup-swift@latest
- name: Setup Rust
uses: dtolnay/rust-toolchain@nightly
- name: Build deps
run: make deps
- name: Test Coverage
run: make test-coverage
- name: Merge and generate coverage report
run: |
llvm-profdata merge -sparse $(find . -type f -path '*/.build/*/debug/codecov/*.profdata') -o default.profdata
for file in **/Tests; do
BIN_PATH="$(swift build --show-bin-path --package-path "$(dirname "$file")")"
XCTEST_PATHS=$(find "${BIN_PATH}" -name '*.xctest')
for XCTEST_PATH in $XCTEST_PATHS; do
echo "Processing $XCTEST_PATH"
# Export the code coverage for the current subproject and append to coverage.lcov
llvm-cov export "${XCTEST_PATH}" \
-instr-profile=default.profdata \
-format lcov >> coverage.lcov \
-ignore-filename-regex=".build/repositories/*"
done
done
- uses: codecov/codecov-action@v4
with:
file: coverage.lcov
fail_ci_if_error: true # optional (default = false)
token: ${{ secrets.CODECOV_TOKEN }} # required
verbose: true # optional (default = false)
4 changes: 3 additions & 1 deletion Blockchain/Sources/Blockchain/Blockchain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ public final class Blockchain: ServiceBase, @unchecked Sendable {

let runtime = Runtime(config: config)
let parent = try await dataProvider.getState(hash: block.header.parentHash)
let stateRoot = await parent.value.stateRoot
let timeslot = timeProvider.getTime().timeToTimeslot(config: config)
// TODO: figure out what is the best way to deal with block received a bit too early
let state = try await runtime.apply(block: block, state: parent, context: .init(timeslot: timeslot + 1))
let context = Runtime.ApplyContext(timeslot: timeslot + 1, stateRoot: stateRoot)
let state = try await runtime.apply(block: block, state: parent, context: context)

try await dataProvider.blockImported(block: block, state: state)

Expand Down
24 changes: 15 additions & 9 deletions Blockchain/Sources/Blockchain/Config/ProtocolConfig+Preset.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ extension Ref where T == ProtocolConfig {
preimagePurgePeriod: 28800,
epochLength: 6,
auditBiasFactor: 2,
coreAccumulationGas: Gas(10_000_000), // TODO: check this
workPackageAuthorizerGas: Gas(10_000_000), // TODO: check this
workPackageRefineGas: Gas(10_000_000), // TODO: check this
coreAccumulationGas: Gas(100_000),
workPackageAuthorizerGas: Gas(1_000_000),
workPackageRefineGas: Gas(500_000_000),
totalAccumulationGas: Gas(341_000_000),
recentHistorySize: 8,
maxWorkItems: 4,
maxDepsInWorkReport: 8,
maxTicketsPerExtrinsic: 4,
maxLookupAnchorAge: 14400,
transferMemoSize: 128,
Expand Down Expand Up @@ -49,11 +51,13 @@ extension Ref where T == ProtocolConfig {
preimagePurgePeriod: 28800,
epochLength: 12,
auditBiasFactor: 2,
coreAccumulationGas: Gas(10_000_000), // TODO: check this
workPackageAuthorizerGas: Gas(10_000_000), // TODO: check this
workPackageRefineGas: Gas(10_000_000), // TODO: check this
coreAccumulationGas: Gas(100_000),
workPackageAuthorizerGas: Gas(1_000_000),
workPackageRefineGas: Gas(500_000_000),
totalAccumulationGas: Gas(341_000_000),
recentHistorySize: 8,
maxWorkItems: 4,
maxDepsInWorkReport: 8,
maxTicketsPerExtrinsic: 16,
maxLookupAnchorAge: 14400,
transferMemoSize: 128,
Expand Down Expand Up @@ -86,11 +90,13 @@ extension Ref where T == ProtocolConfig {
preimagePurgePeriod: 28800,
epochLength: 600,
auditBiasFactor: 2,
coreAccumulationGas: Gas(10_000_000), // TODO: check this
workPackageAuthorizerGas: Gas(10_000_000), // TODO: check this
workPackageRefineGas: Gas(10_000_000), // TODO: check this
coreAccumulationGas: Gas(100_000),
workPackageAuthorizerGas: Gas(1_000_000),
workPackageRefineGas: Gas(500_000_000),
totalAccumulationGas: Gas(341_000_000),
recentHistorySize: 8,
maxWorkItems: 4,
maxDepsInWorkReport: 8,
maxTicketsPerExtrinsic: 16,
maxLookupAnchorAge: 14400,
transferMemoSize: 128,
Expand Down
47 changes: 40 additions & 7 deletions Blockchain/Sources/Blockchain/Config/ProtocolConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,24 @@ public struct ProtocolConfig: Sendable, Codable, Equatable {
// GR: The total gas allocated for a work-package’s Refine logic.
public var workPackageRefineGas: Gas

// GT: The total gas allocated across all cores for Accumulation.
public var totalAccumulationGas: Gas

// H = 8: The size of recent history, in blocks.
public var recentHistorySize: Int

// I = 4: The maximum amount of work items in a package.
public var maxWorkItems: Int

// J = 8: The maximum sum of dependency items in a work-report.
public var maxDepsInWorkReport: Int

// K = 16: The maximum number of tickets which may be submitted in a single extrinsic.
public var maxTicketsPerExtrinsic: Int

// L = 14, 400: The maximum age in timeslots of the lookup anchor.
public var maxLookupAnchorAge: Int

// WT = 128: The size of a transfer memo in octets.
public var transferMemoSize: Int

// N = 2: The number of ticket entries per validator.
public var ticketEntriesPerValidator: Int

Expand All @@ -67,16 +70,16 @@ public struct ProtocolConfig: Sendable, Codable, Equatable {
// R = 10: The rotation period of validator-core assignments, in timeslots.
public var coreAssignmentRotationPeriod: Int

// S = 4,000,000: The maximum size of service code in octets.
public var maxServiceCodeSize: Int

// U = 5: The period in timeslots after which reported but unavailable work may be replaced.
public var preimageReplacementPeriod: Int

// V = 1023: The total number of validators.
public var totalNumberOfValidators: Int

// WC = 684: The basic size of our erasure-coded pieces.
// WC = 4,000,000: The maximum size of service code in octets.
public var maxServiceCodeSize: Int

// WE = 684: The basic size of our erasure-coded pieces.
public var erasureCodedPieceSize: Int

// WM = 2^11: The maximum number of entries in a work-package manifest.
Expand All @@ -92,6 +95,9 @@ public struct ProtocolConfig: Sendable, Codable, Equatable {
// WS = 6: The size of an exported segment in erasure-coded pieces.
public var erasureCodedSegmentSize: Int

// WT = 128: The size of a transfer memo in octets.
public var transferMemoSize: Int

// Y = 500: The number of slots into an epoch at which ticket-submission ends.
public var ticketSubmissionEndSlot: Int

Expand Down Expand Up @@ -119,8 +125,10 @@ public struct ProtocolConfig: Sendable, Codable, Equatable {
coreAccumulationGas: Gas,
workPackageAuthorizerGas: Gas,
workPackageRefineGas: Gas,
totalAccumulationGas: Gas,
recentHistorySize: Int,
maxWorkItems: Int,
maxDepsInWorkReport: Int,
maxTicketsPerExtrinsic: Int,
maxLookupAnchorAge: Int,
transferMemoSize: Int,
Expand Down Expand Up @@ -154,8 +162,10 @@ public struct ProtocolConfig: Sendable, Codable, Equatable {
self.coreAccumulationGas = coreAccumulationGas
self.workPackageAuthorizerGas = workPackageAuthorizerGas
self.workPackageRefineGas = workPackageRefineGas
self.totalAccumulationGas = totalAccumulationGas
self.recentHistorySize = recentHistorySize
self.maxWorkItems = maxWorkItems
self.maxDepsInWorkReport = maxDepsInWorkReport
self.maxTicketsPerExtrinsic = maxTicketsPerExtrinsic
self.maxLookupAnchorAge = maxLookupAnchorAge
self.transferMemoSize = transferMemoSize
Expand Down Expand Up @@ -215,9 +225,13 @@ extension ProtocolConfig {
? other.workPackageAuthorizerGas : workPackageAuthorizerGas,
workPackageRefineGas: other.workPackageRefineGas.value != 0
? other.workPackageRefineGas : workPackageRefineGas,
totalAccumulationGas: other.totalAccumulationGas.value != 0
? other.totalAccumulationGas : totalAccumulationGas,
recentHistorySize: other.recentHistorySize != 0
? other.recentHistorySize : recentHistorySize,
maxWorkItems: other.maxWorkItems != 0 ? other.maxWorkItems : maxWorkItems,
maxDepsInWorkReport: other.maxDepsInWorkReport != 0
? other.maxDepsInWorkReport : maxDepsInWorkReport,
maxTicketsPerExtrinsic: other.maxTicketsPerExtrinsic != 0
? other.maxTicketsPerExtrinsic : maxTicketsPerExtrinsic,
maxLookupAnchorAge: other.maxLookupAnchorAge != 0
Expand Down Expand Up @@ -295,8 +309,12 @@ extension ProtocolConfig {
workPackageRefineGas = try decode(
.workPackageRefineGas, defaultValue: Gas(0), required: required
)
totalAccumulationGas = try decode(
.totalAccumulationGas, defaultValue: Gas(0), required: required
)
recentHistorySize = try decode(.recentHistorySize, defaultValue: 0, required: required)
maxWorkItems = try decode(.maxWorkItems, defaultValue: 0, required: required)
maxDepsInWorkReport = try decode(.maxDepsInWorkReport, defaultValue: 0, required: required)
maxTicketsPerExtrinsic = try decode(
.maxTicketsPerExtrinsic, defaultValue: 0, required: required
)
Expand Down Expand Up @@ -434,6 +452,14 @@ extension ProtocolConfig {
}
}

public enum TotalAccumulationGas: ReadGas {
public typealias TConfig = ProtocolConfigRef
public typealias TOutput = Gas
public static func read(config: ProtocolConfigRef) -> Gas {
config.value.totalAccumulationGas
}
}

public enum RecentHistorySize: ReadInt {
public typealias TConfig = ProtocolConfigRef
public static func read(config: ProtocolConfigRef) -> Int {
Expand All @@ -448,6 +474,13 @@ extension ProtocolConfig {
}
}

public enum MaxDepsInWorkReport: ReadInt {
public typealias TConfig = ProtocolConfigRef
public static func read(config: ProtocolConfigRef) -> Int {
config.value.maxDepsInWorkReport
}
}

public enum MaxTicketsPerExtrinsic: ReadInt {
public typealias TConfig = ProtocolConfigRef
public static func read(config: ProtocolConfigRef) -> Int {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ import Foundation
import Utils

public struct AccumulateArguments: Codable {
/// o
public var result: WorkResult
/// l
public var paylaodHash: Data32
/// k
public var packageHash: Data32
/// a
public var authorizationOutput: Data

public init(result: WorkResult, paylaodHash: Data32, packageHash: Data32, authorizationOutput: Data) {
Expand Down Expand Up @@ -60,7 +64,7 @@ public struct AccumulateState {
/// X
public struct AccumlateResultContext {
/// d
public var serviceAccounts: [ServiceIndex: ServiceAccount]
public var serviceAccounts: ServiceAccounts
/// s: the accumulating service account index
public var serviceIndex: ServiceIndex
/// u
Expand All @@ -75,7 +79,7 @@ public protocol AccumulateFunction {
func invoke(
config: ProtocolConfigRef,
// prior accounts
accounts: ServiceAccounts,
accounts: inout some ServiceAccounts,
// u
state: AccumulateState,
// s
Expand Down
Loading

0 comments on commit 2939432

Please sign in to comment.