Skip to content

Commit 0834140

Browse files
committed
Remove delta usage from badger interactions
1 parent 6cb572d commit 0834140

File tree

4 files changed

+41
-36
lines changed

4 files changed

+41
-36
lines changed

cmd/util/cmd/exec-data-json-export/delta_snapshot_exporter.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"path/filepath"
99

1010
"github.com/onflow/flow-go/cmd/util/cmd/common"
11-
"github.com/onflow/flow-go/engine/execution/state/delta"
11+
"github.com/onflow/flow-go/fvm/state"
1212
"github.com/onflow/flow-go/model/flow"
1313
"github.com/onflow/flow-go/module/metrics"
1414
"github.com/onflow/flow-go/storage/badger"
@@ -49,7 +49,7 @@ func ExportDeltaSnapshots(blockID flow.Identifier, dbPath string, outputPath str
4949
return nil
5050
}
5151

52-
var snap []*delta.Snapshot
52+
var snap []*state.ExecutionSnapshot
5353
err = db.View(operation.RetrieveExecutionStateInteractions(activeBlockID, &snap))
5454
if err != nil {
5555
return fmt.Errorf("could not load delta snapshot: %w", err)
@@ -59,13 +59,13 @@ func ExportDeltaSnapshots(blockID flow.Identifier, dbPath string, outputPath str
5959
// end of snapshots
6060
return nil
6161
}
62-
m, err := json.Marshal(snap[0].Delta.UpdatedRegisters())
62+
m, err := json.Marshal(snap[0].UpdatedRegisters())
6363
if err != nil {
6464
return fmt.Errorf("could not load delta snapshot: %w", err)
6565
}
6666

6767
reads := make([]string, 0)
68-
for _, r := range snap[0].Reads {
68+
for _, r := range snap[0].ReadSet {
6969

7070
json, err := json.Marshal(r)
7171
if err != nil {

engine/execution/state/bootstrap/bootstrap.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
"github.com/rs/zerolog"
99

1010
"github.com/onflow/flow-go/engine/execution/state"
11-
"github.com/onflow/flow-go/engine/execution/state/delta"
1211
"github.com/onflow/flow-go/fvm"
12+
fvmstate "github.com/onflow/flow-go/fvm/state"
1313
"github.com/onflow/flow-go/ledger"
1414
"github.com/onflow/flow-go/model/flow"
1515
"github.com/onflow/flow-go/storage"
@@ -113,8 +113,8 @@ func (b *Bootstrapper) BootstrapExecutionDatabase(db *badger.DB, commit flow.Sta
113113
return fmt.Errorf("could not index genesis state commitment: %w", err)
114114
}
115115

116-
views := make([]*delta.Snapshot, 0)
117-
err = operation.InsertExecutionStateInteractions(genesis.ID(), views)(txn)
116+
snapshots := make([]*fvmstate.ExecutionSnapshot, 0)
117+
err = operation.InsertExecutionStateInteractions(genesis.ID(), snapshots)(txn)
118118
if err != nil {
119119
return fmt.Errorf("could not bootstrap execution state interactions: %w", err)
120120
}
Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
package operation
22

33
import (
4-
"github.com/onflow/flow-go/engine/execution/state/delta"
4+
"github.com/onflow/flow-go/fvm/state"
55
"github.com/onflow/flow-go/model/flow"
66

77
"github.com/dgraph-io/badger/v2"
88
)
99

10-
func InsertExecutionStateInteractions(blockID flow.Identifier, interactions []*delta.Snapshot) func(*badger.Txn) error {
11-
return insert(makePrefix(codeExecutionStateInteractions, blockID), interactions)
10+
func InsertExecutionStateInteractions(
11+
blockID flow.Identifier,
12+
executionSnapshots []*state.ExecutionSnapshot,
13+
) func(*badger.Txn) error {
14+
return insert(
15+
makePrefix(codeExecutionStateInteractions, blockID),
16+
executionSnapshots)
1217
}
1318

14-
func RetrieveExecutionStateInteractions(blockID flow.Identifier, interactions *[]*delta.Snapshot) func(*badger.Txn) error {
15-
return retrieve(makePrefix(codeExecutionStateInteractions, blockID), interactions)
19+
func RetrieveExecutionStateInteractions(
20+
blockID flow.Identifier,
21+
executionSnapshots *[]*state.ExecutionSnapshot,
22+
) func(*badger.Txn) error {
23+
return retrieve(
24+
makePrefix(codeExecutionStateInteractions, blockID), executionSnapshots)
1625
}

storage/badger/operation/interactions_test.go

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,52 +9,48 @@ import (
99
"github.com/stretchr/testify/assert"
1010
"github.com/stretchr/testify/require"
1111

12-
"github.com/onflow/flow-go/engine/execution/state/delta"
12+
"github.com/onflow/flow-go/fvm/state"
1313
"github.com/onflow/flow-go/model/flow"
1414
"github.com/onflow/flow-go/utils/unittest"
1515
)
1616

1717
func TestStateInteractionsInsertCheckRetrieve(t *testing.T) {
1818
unittest.RunWithBadgerDB(t, func(db *badger.DB) {
1919

20-
d1 := delta.NewDeltaView(nil)
21-
22-
d2 := delta.NewDeltaView(nil)
23-
2420
id1 := flow.NewRegisterID(
2521
string([]byte("\x89krg\u007fBN\x1d\xf5\xfb\xb8r\xbc4\xbd\x98ռ\xf1\xd0twU\xbf\x16N\xb4?,\xa0&;")),
2622
"")
27-
2823
id2 := flow.NewRegisterID(string([]byte{2}), "")
2924
id3 := flow.NewRegisterID(string([]byte{3}), "")
3025

31-
// some set and reads
32-
err := d1.Set(id1, []byte("zażółć gęślą jaźń"))
33-
require.NoError(t, err)
34-
err = d1.Set(id2, []byte("b"))
35-
require.NoError(t, err)
36-
err = d1.Set(id2, []byte("c"))
37-
require.NoError(t, err)
38-
39-
_, err = d1.Get(id2)
40-
require.NoError(t, err)
41-
_, err = d1.Get(id3)
42-
require.NoError(t, err)
43-
44-
interactions := []*delta.Snapshot{&d1.Interactions().Snapshot, &d2.Interactions().Snapshot}
26+
snapshot := &state.ExecutionSnapshot{
27+
ReadSet: map[flow.RegisterID]struct{}{
28+
id2: struct{}{},
29+
id3: struct{}{},
30+
},
31+
WriteSet: map[flow.RegisterID]flow.RegisterValue{
32+
id1: []byte("zażółć gęślą jaźń"),
33+
id2: []byte("c"),
34+
},
35+
}
36+
37+
interactions := []*state.ExecutionSnapshot{
38+
snapshot,
39+
&state.ExecutionSnapshot{},
40+
}
4541

4642
blockID := unittest.IdentifierFixture()
4743

48-
err = db.Update(InsertExecutionStateInteractions(blockID, interactions))
44+
err := db.Update(InsertExecutionStateInteractions(blockID, interactions))
4945
require.Nil(t, err)
5046

51-
var readInteractions []*delta.Snapshot
47+
var readInteractions []*state.ExecutionSnapshot
5248

5349
err = db.View(RetrieveExecutionStateInteractions(blockID, &readInteractions))
5450
require.NoError(t, err)
5551

5652
assert.Equal(t, interactions, readInteractions)
57-
58-
assert.Equal(t, d1.Delta(), d1.Interactions().Delta)
53+
assert.Equal(t, snapshot.WriteSet, readInteractions[0].WriteSet)
54+
assert.Equal(t, snapshot.ReadSet, readInteractions[0].ReadSet)
5955
})
6056
}

0 commit comments

Comments
 (0)