Skip to content

Commit 31eef46

Browse files
4082: Update fvm test to use vm.RunV2 r=pattyshack a=pattyshack 4089: Move logical time into a separate package r=pattyshack a=pattyshack To be reuse for the generalized transactional manager. 4096: Fix error predicate typo r=pattyshack a=pattyshack Co-authored-by: Patrick Lee <[email protected]>
4 parents 6311273 + d0eb28e + d1d4efc + 1bdf7cc commit 31eef46

File tree

16 files changed

+412
-309
lines changed

16 files changed

+412
-309
lines changed

fvm/bootstrap.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/onflow/flow-go/fvm/errors"
1414
"github.com/onflow/flow-go/fvm/meter"
1515
"github.com/onflow/flow-go/fvm/storage"
16+
"github.com/onflow/flow-go/fvm/storage/logical"
1617
"github.com/onflow/flow-go/model/flow"
1718
"github.com/onflow/flow-go/module/epochs"
1819
)
@@ -259,7 +260,7 @@ func (BootstrapProcedure) Type() ProcedureType {
259260
return BootstrapProcedureType
260261
}
261262

262-
func (proc *BootstrapProcedure) ExecutionTime() derived.LogicalTime {
263+
func (proc *BootstrapProcedure) ExecutionTime() logical.Time {
263264
return 0
264265
}
265266

fvm/derived/derived_block_data.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/onflow/cadence/runtime/interpreter"
88

99
"github.com/onflow/flow-go/fvm/state"
10+
"github.com/onflow/flow-go/fvm/storage/logical"
1011
)
1112

1213
type DerivedTransaction interface {
@@ -101,8 +102,8 @@ func (block *DerivedBlockData) NewChildDerivedBlockData() *DerivedBlockData {
101102
}
102103

103104
func (block *DerivedBlockData) NewSnapshotReadDerivedTransactionData(
104-
snapshotTime LogicalTime,
105-
executionTime LogicalTime,
105+
snapshotTime logical.Time,
106+
executionTime logical.Time,
106107
) (
107108
DerivedTransactionCommitter,
108109
error,
@@ -128,8 +129,8 @@ func (block *DerivedBlockData) NewSnapshotReadDerivedTransactionData(
128129
}
129130

130131
func (block *DerivedBlockData) NewDerivedTransactionData(
131-
snapshotTime LogicalTime,
132-
executionTime LogicalTime,
132+
snapshotTime logical.Time,
133+
executionTime logical.Time,
133134
) (
134135
DerivedTransactionCommitter,
135136
error,

fvm/derived/table.go

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@ import (
77
"github.com/hashicorp/go-multierror"
88

99
"github.com/onflow/flow-go/fvm/state"
10+
"github.com/onflow/flow-go/fvm/storage/logical"
1011
)
1112

13+
// TODO(patrick): rm once emulator is updated
14+
const EndOfBlockExecutionTime = logical.EndOfBlockExecutionTime
15+
1216
// ValueComputer is used by DerivedDataTable's GetOrCompute to compute the
1317
// derived value when the value is not in DerivedDataTable (i.e., "cache miss").
1418
type ValueComputer[TKey any, TVal any] interface {
@@ -43,7 +47,7 @@ type DerivedDataTable[TKey comparable, TVal any] struct {
4347
lock sync.RWMutex
4448
items map[TKey]*invalidatableEntry[TVal]
4549

46-
latestCommitExecutionTime LogicalTime
50+
latestCommitExecutionTime logical.Time
4751

4852
invalidators chainedTableInvalidators[TKey, TVal] // Guarded by lock.
4953
}
@@ -53,10 +57,10 @@ type TableTransaction[TKey comparable, TVal any] struct {
5357

5458
// The start time when the snapshot first becomes readable (i.e., the
5559
// "snapshotTime - 1"'s transaction committed the snapshot view).
56-
snapshotTime LogicalTime
60+
snapshotTime logical.Time
5761

5862
// The transaction (or script)'s execution start time (aka TxIndex).
59-
executionTime LogicalTime
63+
executionTime logical.Time
6064

6165
// toValidateTime is used to amortize cost of repeated Validate calls.
6266
// Each Validate call will only validate the time range
@@ -66,7 +70,7 @@ type TableTransaction[TKey comparable, TVal any] struct {
6670
// Note that since newly derived values are computed based on snapshotTime's
6771
// view, each time a newly derived value is added to the transaction,
6872
// toValidateTime is reset back to snapshotTime.
69-
toValidateTime LogicalTime
73+
toValidateTime logical.Time
7074

7175
readSet map[TKey]*invalidatableEntry[TVal]
7276
writeSet map[TKey]*invalidatableEntry[TVal]
@@ -77,7 +81,7 @@ type TableTransaction[TKey comparable, TVal any] struct {
7781
}
7882

7983
func newEmptyTable[TKey comparable, TVal any](
80-
latestCommit LogicalTime,
84+
latestCommit logical.Time,
8185
) *DerivedDataTable[TKey, TVal] {
8286
return &DerivedDataTable[TKey, TVal]{
8387
items: map[TKey]*invalidatableEntry[TVal]{},
@@ -87,7 +91,7 @@ func newEmptyTable[TKey comparable, TVal any](
8791
}
8892

8993
func NewEmptyTable[TKey comparable, TVal any]() *DerivedDataTable[TKey, TVal] {
90-
return newEmptyTable[TKey, TVal](ParentBlockTime)
94+
return newEmptyTable[TKey, TVal](logical.ParentBlockTime)
9195
}
9296

9397
// This variant is needed by the chunk verifier, which does not start at the
@@ -98,7 +102,7 @@ func NewEmptyTableWithOffset[
98102
](
99103
offset uint32,
100104
) *DerivedDataTable[TKey, TVal] {
101-
return newEmptyTable[TKey, TVal](LogicalTime(offset) - 1)
105+
return newEmptyTable[TKey, TVal](logical.Time(offset) - 1)
102106
}
103107

104108
func (table *DerivedDataTable[TKey, TVal]) NewChildTable() *DerivedDataTable[TKey, TVal] {
@@ -122,7 +126,7 @@ func (table *DerivedDataTable[TKey, TVal]) NewChildTable() *DerivedDataTable[TKe
122126

123127
return &DerivedDataTable[TKey, TVal]{
124128
items: items,
125-
latestCommitExecutionTime: ParentBlockTime,
129+
latestCommitExecutionTime: logical.ParentBlockTime,
126130
invalidators: nil,
127131
}
128132
}
@@ -131,7 +135,7 @@ func (table *DerivedDataTable[TKey, TVal]) NextTxIndexForTestingOnly() uint32 {
131135
return uint32(table.LatestCommitExecutionTimeForTestingOnly()) + 1
132136
}
133137

134-
func (table *DerivedDataTable[TKey, TVal]) LatestCommitExecutionTimeForTestingOnly() LogicalTime {
138+
func (table *DerivedDataTable[TKey, TVal]) LatestCommitExecutionTimeForTestingOnly() logical.Time {
135139
table.lock.RLock()
136140
defer table.lock.RUnlock()
137141

@@ -235,7 +239,7 @@ func (table *DerivedDataTable[TKey, TVal]) commit(
235239

236240
if table.latestCommitExecutionTime+1 < txn.snapshotTime &&
237241
(!txn.isSnapshotReadTransaction ||
238-
txn.snapshotTime != EndOfBlockExecutionTime) {
242+
txn.snapshotTime != logical.EndOfBlockExecutionTime) {
239243

240244
return newNotRetryableError(
241245
"invalid TableTransaction: missing commit range [%v, %v)",
@@ -290,9 +294,9 @@ func (table *DerivedDataTable[TKey, TVal]) commit(
290294
}
291295

292296
func (table *DerivedDataTable[TKey, TVal]) newTableTransaction(
293-
upperBoundExecutionTime LogicalTime,
294-
snapshotTime LogicalTime,
295-
executionTime LogicalTime,
297+
upperBoundExecutionTime logical.Time,
298+
snapshotTime logical.Time,
299+
executionTime logical.Time,
296300
isSnapshotReadTransaction bool,
297301
) (
298302
*TableTransaction[TKey, TVal],
@@ -323,28 +327,28 @@ func (table *DerivedDataTable[TKey, TVal]) newTableTransaction(
323327
}
324328

325329
func (table *DerivedDataTable[TKey, TVal]) NewSnapshotReadTableTransaction(
326-
snapshotTime LogicalTime,
327-
executionTime LogicalTime,
330+
snapshotTime logical.Time,
331+
executionTime logical.Time,
328332
) (
329333
*TableTransaction[TKey, TVal],
330334
error,
331335
) {
332336
return table.newTableTransaction(
333-
LargestSnapshotReadTransactionExecutionTime,
337+
logical.LargestSnapshotReadTransactionExecutionTime,
334338
snapshotTime,
335339
executionTime,
336340
true)
337341
}
338342

339343
func (table *DerivedDataTable[TKey, TVal]) NewTableTransaction(
340-
snapshotTime LogicalTime,
341-
executionTime LogicalTime,
344+
snapshotTime logical.Time,
345+
executionTime logical.Time,
342346
) (
343347
*TableTransaction[TKey, TVal],
344348
error,
345349
) {
346350
return table.newTableTransaction(
347-
LargestNormalTransactionExecutionTime,
351+
logical.LargestNormalTransactionExecutionTime,
348352
snapshotTime,
349353
executionTime,
350354
false)
@@ -485,6 +489,6 @@ func (txn *TableTransaction[TKey, TVal]) Commit() RetryableError {
485489
return txn.table.commit(txn)
486490
}
487491

488-
func (txn *TableTransaction[TKey, TVal]) ToValidateTimeForTestingOnly() LogicalTime {
492+
func (txn *TableTransaction[TKey, TVal]) ToValidateTimeForTestingOnly() logical.Time {
489493
return txn.toValidateTime
490494
}

fvm/derived/table_invalidator.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package derived
22

33
import (
44
"github.com/onflow/flow-go/fvm/state"
5+
"github.com/onflow/flow-go/fvm/storage/logical"
56
)
67

78
type TableInvalidator[TKey comparable, TVal any] interface {
@@ -15,15 +16,15 @@ type TableInvalidator[TKey comparable, TVal any] interface {
1516
type tableInvalidatorAtTime[TKey comparable, TVal any] struct {
1617
TableInvalidator[TKey, TVal]
1718

18-
executionTime LogicalTime
19+
executionTime logical.Time
1920
}
2021

2122
// NOTE: chainedInvalidator assumes that the entries are order by non-decreasing
2223
// execution time.
2324
type chainedTableInvalidators[TKey comparable, TVal any] []tableInvalidatorAtTime[TKey, TVal]
2425

2526
func (chained chainedTableInvalidators[TKey, TVal]) ApplicableInvalidators(
26-
toValidateTime LogicalTime,
27+
toValidateTime logical.Time,
2728
) chainedTableInvalidators[TKey, TVal] {
2829
// NOTE: switch to bisection search (or reverse iteration) if the list
2930
// is long.

0 commit comments

Comments
 (0)