Skip to content

Commit b316e10

Browse files
Fix transaction index ordering on rollback (#264)
* Test on staging * Test on staging * fix order by index * Remove testing output * Update Makefile
1 parent 0c5bcc7 commit b316e10

File tree

5 files changed

+59
-12
lines changed

5 files changed

+59
-12
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ run:
3030
.PHONY: run-pg
3131
run-pg:
3232
FLOW_DB_USER=postgres \
33+
FLOW_DB_PASSWORD=password \
3334
FLOW_DB_PORT=5432 \
3435
FLOW_DB_NAME=dapper \
3536
FLOW_DB_HOST=localhost \

blockchain/projects.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -242,13 +242,8 @@ func (p *Projects) DeployContract(
242242
return nil, err
243243
}
244244

245-
var exesB []*model.TransactionExecution
246-
err = p.store.GetTransactionExecutionsForProject(projectID, &exesB)
247-
if err != nil {
248-
return nil, err
249-
}
250-
251245
// Reload emulator after block height rollback
246+
p.emulatorCache.reset(projectID)
252247
em, err = p.load(projectID)
253248
if err != nil {
254249
return nil, err
@@ -351,7 +346,6 @@ func (p *Projects) load(projectID uuid.UUID) (blockchain, error) {
351346

352347
func (p *Projects) rebuildState(projectID uuid.UUID) (*emulator, error) {
353348
var executions []*model.TransactionExecution
354-
355349
err := p.store.GetTransactionExecutionsForProject(projectID, &executions)
356350
if err != nil {
357351
return nil, err
@@ -375,7 +369,7 @@ func (p *Projects) rebuildState(projectID uuid.UUID) (*emulator, error) {
375369
// This also occurs when a rollback is required due to contract redeployment
376370
if height > len(executions) {
377371
p.emulatorCache.reset(projectID)
378-
em, err = newEmulator()
372+
em, err = p.emulatorPool.new()
379373
if err != nil {
380374
return nil, err
381375
}

e2eTest/constants.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,33 @@ type GetAccountResponse struct {
117117
Account Account
118118
}
119119

120+
const QueryGetProjectStorage = `
121+
query($projectId: UUID!) {
122+
project(id: $projectId) {
123+
accounts {
124+
address
125+
deployedContracts
126+
state
127+
}
128+
transactionTemplates {
129+
id
130+
script
131+
index
132+
}
133+
scriptTemplates {
134+
id
135+
script
136+
index
137+
}
138+
contractTemplates {
139+
id
140+
script
141+
index
142+
}
143+
}
144+
}
145+
`
146+
120147
const QueryGetProject = `
121148
query($projectId: UUID!) {
122149
project(id: $projectId) {

e2eTest/contract_deployments_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,15 @@ func TestContractRedeployment(t *testing.T) {
299299
require.NoError(t, err)
300300
require.Equal(t, 10, createContractResp.CreateContractDeployment.BlockHeight)
301301

302+
var projStorage GetProjectResponse
303+
err = c.Post(
304+
QueryGetProjectStorage,
305+
&projStorage,
306+
client.Var("projectId", project.ID),
307+
client.AddCookie(c.SessionCookie()),
308+
)
309+
require.NoError(t, err)
310+
302311
// Rollback block height
303312
err = c.Post(
304313
MutationCreateContractDeployment,
@@ -311,6 +320,14 @@ func TestContractRedeployment(t *testing.T) {
311320
require.NoError(t, err)
312321
require.Equal(t, 8, createContractResp.CreateContractDeployment.BlockHeight)
313322

323+
err = c.Post(
324+
QueryGetProjectStorage,
325+
&projStorage,
326+
client.Var("projectId", project.ID),
327+
client.AddCookie(c.SessionCookie()),
328+
)
329+
require.NoError(t, err)
330+
314331
// Rollback block height
315332
err = c.Post(
316333
MutationCreateContractDeployment,
@@ -322,6 +339,14 @@ func TestContractRedeployment(t *testing.T) {
322339
)
323340
require.NoError(t, err)
324341
require.Equal(t, 6, createContractResp.CreateContractDeployment.BlockHeight)
342+
343+
err = c.Post(
344+
QueryGetProjectStorage,
345+
&projStorage,
346+
client.Var("projectId", project.ID),
347+
client.AddCookie(c.SessionCookie()),
348+
)
349+
require.NoError(t, err)
325350
})
326351

327352
}

storage/sql.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -387,8 +387,8 @@ func (s *SQL) GetFile(id uuid.UUID, pID uuid.UUID, file *model.File) error {
387387
func (s *SQL) GetFilesForProject(pID uuid.UUID, files *[]*model.File, fileType model.FileType) error {
388388
// Note: use map to include zero entries for fileType
389389
return s.db.Where(map[string]interface{}{"project_id": pID.String(), "type": fileType}).
390-
Find(files).
391390
Order("\"index\" asc").
391+
Find(files).
392392
Error
393393
}
394394

@@ -402,8 +402,8 @@ func (s *SQL) InsertScriptExecution(exe *model.ScriptExecution) error {
402402

403403
func (s *SQL) GetScriptExecutionsForProject(projectID uuid.UUID, exes *[]*model.ScriptExecution) error {
404404
return s.db.Where(&model.ScriptExecution{File: model.File{ProjectID: projectID}}).
405-
Find(exes).
406405
Order("\"index\" asc").
406+
Find(exes).
407407
Error
408408
}
409409

@@ -466,8 +466,8 @@ func (s *SQL) DeleteContractDeploymentByName(
466466

467467
func (s *SQL) GetContractDeploymentsForProject(projectID uuid.UUID, deployments *[]*model.ContractDeployment) error {
468468
return s.db.Where(&model.ContractDeployment{File: model.File{ProjectID: projectID}}).
469-
Find(deployments).
470469
Order("\"index\" asc").
470+
Find(deployments).
471471
Error
472472
}
473473

@@ -504,8 +504,8 @@ func (s *SQL) InsertTransactionExecution(exe *model.TransactionExecution) error
504504

505505
func (s *SQL) GetTransactionExecutionsForProject(projectID uuid.UUID, exes *[]*model.TransactionExecution) error {
506506
return s.db.Where(&model.TransactionExecution{File: model.File{ProjectID: projectID}}).
507-
Find(exes).
508507
Order("\"index\" asc").
508+
Find(exes).
509509
Error
510510
}
511511

0 commit comments

Comments
 (0)