From 52cc13b9838f352ba7665718fa54afbf74d09f70 Mon Sep 17 00:00:00 2001 From: Bryan Chen Date: Sat, 9 Nov 2024 00:23:22 +1300 Subject: [PATCH] working --- Blockchain/Sources/Blockchain/RuntimeProtocols/Runtime.swift | 4 ++-- Blockchain/Sources/Blockchain/Validator/BlockAuthor.swift | 3 +-- Blockchain/Tests/BlockchainTests/BlockAuthorTests.swift | 3 ++- Blockchain/Tests/BlockchainTests/StateTrieTests.swift | 3 --- 4 files changed, 5 insertions(+), 8 deletions(-) diff --git a/Blockchain/Sources/Blockchain/RuntimeProtocols/Runtime.swift b/Blockchain/Sources/Blockchain/RuntimeProtocols/Runtime.swift index 102fd5cf..843dee75 100644 --- a/Blockchain/Sources/Blockchain/RuntimeProtocols/Runtime.swift +++ b/Blockchain/Sources/Blockchain/RuntimeProtocols/Runtime.swift @@ -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 } } diff --git a/Blockchain/Sources/Blockchain/Validator/BlockAuthor.swift b/Blockchain/Sources/Blockchain/Validator/BlockAuthor.swift index 9cea5de0..785a027f 100644 --- a/Blockchain/Sources/Blockchain/Validator/BlockAuthor.swift +++ b/Blockchain/Sources/Blockchain/Validator/BlockAuthor.swift @@ -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) @@ -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, diff --git a/Blockchain/Tests/BlockchainTests/BlockAuthorTests.swift b/Blockchain/Tests/BlockchainTests/BlockAuthorTests.swift index 6890933d..4a0b3ed5 100644 --- a/Blockchain/Tests/BlockchainTests/BlockAuthorTests.swift +++ b/Blockchain/Tests/BlockchainTests/BlockAuthorTests.swift @@ -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) @@ -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 )) } diff --git a/Blockchain/Tests/BlockchainTests/StateTrieTests.swift b/Blockchain/Tests/BlockchainTests/StateTrieTests.swift index 60526eaa..7b090ce0 100644 --- a/Blockchain/Tests/BlockchainTests/StateTrieTests.swift +++ b/Blockchain/Tests/BlockchainTests/StateTrieTests.swift @@ -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 {