Skip to content

Commit

Permalink
working
Browse files Browse the repository at this point in the history
  • Loading branch information
xlc committed Nov 8, 2024
1 parent 4d75b2a commit 52cc13b
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Blockchain/Sources/Blockchain/RuntimeProtocols/Runtime.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public final class Runtime {
public let timeslot: TimeslotIndex
public let stateRoot: Data32

public init(timeslot: TimeslotIndex, stateRoot _: Data32) {
public init(timeslot: TimeslotIndex, stateRoot: Data32) {
self.timeslot = timeslot
stateRoot = Data32()
self.stateRoot = stateRoot
}
}

Expand Down
3 changes: 1 addition & 2 deletions Blockchain/Sources/Blockchain/Validator/BlockAuthor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public final class BlockAuthor: ServiceBase2, @unchecked Sendable {
// TODO: verify we are indeed the block author

let state = try await dataProvider.getState(hash: parentHash)
let stateRoot = await state.value.stateRoot
let epoch = timeslot.timeslotToEpochIndex(config: config)

let pendingTickets = await extrinsicPool.getPendingTickets(epoch: epoch)
Expand Down Expand Up @@ -118,8 +119,6 @@ public final class BlockAuthor: ServiceBase2, @unchecked Sendable {
extrinsics: extrinsic.tickets
)

let stateRoot = try await state.value.save()

let unsignedHeader = Header.Unsigned(
parentHash: parentHash,
priorStateRoot: stateRoot,
Expand Down
3 changes: 2 additions & 1 deletion Blockchain/Tests/BlockchainTests/BlockAuthorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ struct BlockAuthorTests {
let config = services.config
let timeProvider = services.timeProvider
let genesisState = services.genesisState
let stateRoot = await genesisState.value.stateRoot

let timeslot = timeProvider.getTime().timeToTimeslot(config: config)

Expand All @@ -44,7 +45,7 @@ struct BlockAuthorTests {
// Verify block
try _ = await runtime.apply(block: block, state: genesisState, context: .init(
timeslot: timeslot + 1,
stateRoot: genesisState.value.stateRoot
stateRoot: stateRoot
))
}

Expand Down
3 changes: 0 additions & 3 deletions Blockchain/Tests/BlockchainTests/StateTrieTests.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import Foundation
import Testing
import TracingUtils
import Utils

@testable import Blockchain

private let logger = Logger(label: "StateTrieTests")

private func merklize(_ data: some Sequence<(key: Data32, value: Data)>) -> Data32 {
var dict = [Data32: Data]()
for (key, value) in data {
Expand Down

0 comments on commit 52cc13b

Please sign in to comment.