Skip to content

Commit 1526389

Browse files
committed
Fix cache invalidation logic
1 parent 3d32e03 commit 1526389

File tree

4 files changed

+37
-26
lines changed

4 files changed

+37
-26
lines changed

blockchain/contracts/contracts.go

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"embed"
2323
"fmt"
2424
"github.com/onflow/flow-cli/flowkit/config"
25-
"github.com/onflow/flow-go-sdk"
2625
)
2726

2827
// Embed all contracts in this folder
@@ -32,44 +31,45 @@ var contracts embed.FS
3231

3332
// Core defines core contract to be embedded, along with their locations in the emulator
3433
var Core = []config.Contract{
35-
{
36-
Name: "NonFungibleToken",
37-
Aliases: config.Aliases{
38-
config.Alias{
39-
Network: "emulator",
40-
Address: flow.HexToAddress("0xf8d6e0586b0a20c7"),
41-
},
42-
},
43-
},
44-
{
45-
Name: "FungibleToken",
46-
Aliases: config.Aliases{
47-
config.Alias{
48-
Network: "emulator",
49-
Address: flow.HexToAddress("0xee82856bf20e2aa6"),
50-
},
51-
},
52-
},
53-
// TODO: Need to support new import schema in order to resolve core contracts
5434
/*
5535
{
56-
Name: "FlowToken",
36+
Name: "NonFungibleToken",
5737
Aliases: config.Aliases{
5838
config.Alias{
5939
Network: "emulator",
60-
Address: flow.HexToAddress("0x0ae53cb6e3f42a79"),
40+
Address: flow.HexToAddress("0xf8d6e0586b0a20c7"),
6141
},
6242
},
6343
},
6444
{
65-
Name: "MetadataViews",
45+
Name: "FungibleToken",
6646
Aliases: config.Aliases{
6747
config.Alias{
6848
Network: "emulator",
69-
Address: flow.HexToAddress("0xf8d6e0586b0a20c7"),
49+
Address: flow.HexToAddress("0xee82856bf20e2aa6"),
7050
},
7151
},
7252
},
53+
// TODO: Need to support new import schema in order to resolve core contracts
54+
55+
{
56+
Name: "FlowToken",
57+
Aliases: config.Aliases{
58+
config.Alias{
59+
Network: "emulator",
60+
Address: flow.HexToAddress("0x0ae53cb6e3f42a79"),
61+
},
62+
},
63+
},
64+
{
65+
Name: "MetadataViews",
66+
Aliases: config.Aliases{
67+
config.Alias{
68+
Network: "emulator",
69+
Address: flow.HexToAddress("0xf8d6e0586b0a20c7"),
70+
},
71+
},
72+
},
7373
*/
7474
}
7575

blockchain/flowkit.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ type blockchain interface {
7272

7373
initBlockHeight() int
7474

75+
numAccounts() int
76+
7577
getFlowJson() (string, error)
7678
}
7779

@@ -92,6 +94,7 @@ func newFlowkit() (*flowKit, error) {
9294
}
9395

9496
interceptor := NewInterceptor()
97+
emulatorLogger := zerolog.New(interceptor)
9598

9699
emulator := gateway.NewEmulatorGatewayWithOpts(
97100
&gateway.EmulatorKey{
@@ -100,7 +103,7 @@ func newFlowkit() (*flowKit, error) {
100103
HashAlgo: emu.DefaultServiceKeyHashAlgo,
101104
},
102105
gateway.WithEmulatorOptions(
103-
emu.WithLogger(zerolog.New(interceptor)),
106+
emu.WithLogger(emulatorLogger),
104107
emu.WithStore(memstore.New()),
105108
emu.WithTransactionValidationEnabled(false),
106109
emu.WithStorageLimitEnabled(false),
@@ -190,6 +193,10 @@ func (fk *flowKit) initBlockHeight() int {
190193
return initialAccounts + len(contracts.Included())
191194
}
192195

196+
func (fk *flowKit) numAccounts() int {
197+
return initialAccounts
198+
}
199+
193200
func (fk *flowKit) getFlowJson() (string, error) {
194201
state, err := fk.blockchain.State()
195202
if err != nil {

blockchain/projects.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ func (p *Projects) rebuildState(projectID uuid.UUID) (*flowKit, error) {
344344
// This can happen if project was cleared but on another replica, this replica gets the request after
345345
// and will get cleared 0 executions from database but has a stale emulator in its own cache
346346
// This also occurs when a rollback is required due to contract redeployment
347-
if height > len(executions) {
347+
if height > len(executions)+len(deployments)+fk.numAccounts() {
348348
p.flowKitCache.reset(projectID)
349349
fk, err = p.flowKitPool.new()
350350
if err != nil {

resolver.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package playground
2020

2121
import (
2222
"context"
23+
"fmt"
2324
"github.com/Masterminds/semver"
2425
"github.com/dapperlabs/flow-playground-api/adapter"
2526
"github.com/dapperlabs/flow-playground-api/auth"
@@ -208,6 +209,7 @@ func (r *mutationResolver) CreateTransactionExecution(
208209
ctx context.Context,
209210
input model.NewTransactionExecution,
210211
) (*model.TransactionExecution, error) {
212+
fmt.Println("CreateTransactionExecution()")
211213
err := r.authorize(ctx, input.ProjectID)
212214
if err != nil {
213215
return nil, err
@@ -218,6 +220,8 @@ func (r *mutationResolver) CreateTransactionExecution(
218220
return nil, err
219221
}
220222

223+
fmt.Println("TX: ", exe.Logs)
224+
221225
return adapter.TransactionToAPI(exe), nil
222226
}
223227

0 commit comments

Comments
 (0)