Skip to content

Commit 2595ce8

Browse files
authored
fix and pass new traces (#371)
1 parent 6242ba4 commit 2595ce8

File tree

206 files changed

+592965
-15
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

206 files changed

+592965
-15
lines changed

Blockchain/Sources/Blockchain/RuntimeProtocols/Accumulation.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -662,12 +662,10 @@ extension Accumulation {
662662

663663
let digests = accumulated.compactMap(\.digests).flatMap(\.self)
664664
let num = digests.filter { $0.serviceIndex == service }.count
665-
666-
if num == 0 { continue }
667-
668665
let gasUsed = accumulateOutput.gasUsed
669666
.filter { $0.serviceIndex == service }
670667
.reduce(Gas(0)) { $0 + $1.gas }
668+
if Int(gasUsed.value) + num == 0 { continue }
671669

672670
accumulateStats[service] = (gasUsed, UInt32(num))
673671
}

Blockchain/Sources/Blockchain/VMInvocations/HostCall/HostCalls.swift

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ public class Read: HostCall {
286286
nil
287287
}
288288

289-
logger.debug("value: \(value?.toHexString() ?? "nil")")
289+
logger.debug("value: \(value?.toDebugHexString() ?? "nil")")
290290

291291
guard let value else {
292292
state.writeRegister(Registers.Index(raw: 7), HostCallResultCode.NONE.rawValue)
@@ -346,6 +346,7 @@ public class Write: HostCall {
346346
throw VMInvocationsError.panic
347347
}
348348

349+
// update footprint for threshold balance check
349350
let oldValue = try await serviceAccounts.value.get(serviceAccount: serviceIndex, storageKey: key)
350351
if regs[3] == 0 {
351352
accountDetails.updateFootprintStorage(key: key, oldValue: oldValue, newValue: nil)
@@ -1213,6 +1214,8 @@ public class Solicit: HostCall {
12131214
let hashData = try? state.readMemory(address: startAddr, length: 32)
12141215
let hash = Data32(hashData ?? Data())
12151216

1217+
logger.debug("hash: \(hash?.description ?? "nil"), length: \(length)")
1218+
12161219
guard let hash else {
12171220
throw VMInvocationsError.panic
12181221
}
@@ -1222,21 +1225,40 @@ public class Solicit: HostCall {
12221225
preimageHash: hash,
12231226
length: length
12241227
)
1228+
logger.debug("previous info: \(String(describing: preimageInfo))")
1229+
12251230
let notRequestedYet = preimageInfo == nil
12261231
let isPreviouslyAvailable = preimageInfo?.count == 2
12271232
let canSolicit = notRequestedYet || isPreviouslyAvailable
12281233

1229-
let acc = try await x.state.accounts.value.get(serviceAccount: x.serviceIndex)
1230-
12311234
if !canSolicit {
12321235
state.writeRegister(Registers.Index(raw: 7), HostCallResultCode.HUH.rawValue)
1233-
} else if let acc, acc.balance < acc.thresholdBalance(config: config) {
1236+
return
1237+
}
1238+
1239+
var acc = try await x.state.accounts.value.get(serviceAccount: x.serviceIndex)
1240+
1241+
if var tempAcc = acc {
1242+
// update footprints for threshold balance check
1243+
let oldValue = try await x.state.accounts.value.get(serviceAccount: x.serviceIndex, preimageHash: hash, length: length)
1244+
if notRequestedYet {
1245+
tempAcc.updateFootprintPreimage(oldValue: oldValue, newValue: [], length: length)
1246+
} else if isPreviouslyAvailable, var preimageInfo {
1247+
try preimageInfo.append(timeslot)
1248+
tempAcc.updateFootprintPreimage(oldValue: oldValue, newValue: preimageInfo, length: length)
1249+
}
1250+
acc = tempAcc
1251+
}
1252+
1253+
if let acc, acc.balance < acc.thresholdBalance(config: config) {
12341254
state.writeRegister(Registers.Index(raw: 7), HostCallResultCode.FULL.rawValue)
12351255
} else {
12361256
state.writeRegister(Registers.Index(raw: 7), HostCallResultCode.OK.rawValue)
12371257
if notRequestedYet {
1258+
logger.debug("solicit new preimage")
12381259
try await x.state.accounts.set(serviceAccount: x.serviceIndex, preimageHash: hash, length: length, value: [])
12391260
} else if isPreviouslyAvailable, var preimageInfo {
1261+
logger.debug("solicit existing preimage")
12401262
try preimageInfo.append(timeslot)
12411263
try await x.state.accounts.set(
12421264
serviceAccount: x.serviceIndex,

Fuzzing/Sources/Fuzzing/FuzzingClient.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,8 @@ public class FuzzingClient {
228228
var targetMap: [String: String] = [:]
229229
var duplicateTargetKeys: [String] = []
230230
for kv in targetState {
231-
let keyHex = kv.key.data.toHexString()
232-
let valueHex = kv.value.toHexString()
231+
let keyHex = kv.key.data.toDebugHexString()
232+
let valueHex = kv.value.toDebugHexString()
233233
if targetMap[keyHex] != nil {
234234
duplicateTargetKeys.append(keyHex)
235235
logger.warning("Duplicate key in target state: \(keyHex)")
@@ -240,8 +240,8 @@ public class FuzzingClient {
240240
var expectedMap: [String: String] = [:]
241241
var duplicateExpectedKeys: [String] = []
242242
for kv in expectedState {
243-
let keyHex = kv.key.data.toHexString()
244-
let valueHex = kv.value.toHexString()
243+
let keyHex = kv.key.data.toDebugHexString()
244+
let valueHex = kv.value.toDebugHexString()
245245
if expectedMap[keyHex] != nil {
246246
duplicateExpectedKeys.append(keyHex)
247247
logger.warning("Duplicate key in expected state: \(keyHex)")

JAMTests/Tests/JAMTests/jamtestnet/FuzzTests.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,16 @@ struct FuzzTests {
5050
func v070(_: Testcase) async throws {
5151
// try await TraceTest.test(input)
5252
}
53+
54+
@Test(arguments: try loadTests(
55+
version: "0.7.1",
56+
filters: [
57+
// empty to include all
58+
],
59+
ignore: [
60+
]
61+
))
62+
func v071(input: Testcase) async throws {
63+
try await TraceTest.test(input)
64+
}
5365
}

JAMTests/Tests/JAMTests/jamtestnet/PolkajamTests.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ struct PolkajamTests {
3434
try await TraceTest.test(input)
3535
}
3636

37+
@Test(arguments: try JamTestnet.loadTests(path: "traces/fuzzy_light", src: .w3f))
38+
func fuzzyLightTests(_ input: Testcase) async throws {
39+
try await TraceTest.test(input)
40+
}
41+
3742
@Test(arguments: try JamTestnet.loadTests(path: "traces/fuzzy", src: .w3f))
3843
func fuzzyTests(_ input: Testcase) async throws {
3944
try await TraceTest.test(input)
1.51 MB
Binary file not shown.

JAMTests/fuzz/0.7.1/1761552708/00000048.json

Lines changed: 683 additions & 0 deletions
Large diffs are not rendered by default.
1.51 MB
Binary file not shown.

JAMTests/fuzz/0.7.1/1761552708/00000049.json

Lines changed: 790 additions & 0 deletions
Large diffs are not rendered by default.
930 KB
Binary file not shown.

0 commit comments

Comments
 (0)