Skip to content

Commit 6e8d85b

Browse files
committed
Blockchain's vmCtx should always be updated to point to the latest Header
We also rename Blockchain's newFVMContextFromHeader() to setFVMContextFromHeader()
1 parent 8c6c483 commit 6e8d85b

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

emulator/blockchain.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -774,11 +774,13 @@ func configureTransactionValidator(conf config, blocks *blocks) *access.Transact
774774
)
775775
}
776776

777-
func (b *Blockchain) newFVMContextFromHeader(header *flowgo.Header) fvm.Context {
778-
return fvm.NewContextFromParent(
777+
func (b *Blockchain) setFVMContextFromHeader(header *flowgo.Header) fvm.Context {
778+
b.vmCtx = fvm.NewContextFromParent(
779779
b.vmCtx,
780780
fvm.WithBlockHeader(header),
781781
)
782+
783+
return b.vmCtx
782784
}
783785

784786
func (b *Blockchain) CurrentScript() (string, string) {
@@ -1165,7 +1167,7 @@ func (b *Blockchain) executeBlock() ([]*types.TransactionResult, error) {
11651167
}
11661168

11671169
header := b.pendingBlock.Block().Header
1168-
blockContext := b.newFVMContextFromHeader(header)
1170+
blockContext := b.setFVMContextFromHeader(header)
11691171

11701172
// cannot execute a block that has already executed
11711173
if b.pendingBlock.ExecutionComplete() {
@@ -1193,7 +1195,7 @@ func (b *Blockchain) ExecuteNextTransaction() (*types.TransactionResult, error)
11931195
defer b.mu.Unlock()
11941196

11951197
header := b.pendingBlock.Block().Header
1196-
blockContext := b.newFVMContextFromHeader(header)
1198+
blockContext := b.setFVMContextFromHeader(header)
11971199
return b.executeNextTransaction(blockContext)
11981200
}
11991201

@@ -1405,8 +1407,10 @@ func (b *Blockchain) executeScriptAtBlockID(script []byte, arguments [][]byte, i
14051407
return nil, err
14061408
}
14071409

1408-
header := requestedBlock.Header
1409-
blockContext := b.newFVMContextFromHeader(header)
1410+
blockContext := fvm.NewContextFromParent(
1411+
b.vmCtx,
1412+
fvm.WithBlockHeader(requestedBlock.Header),
1413+
)
14101414

14111415
scriptProc := fvm.Script(script).WithArguments(arguments...)
14121416
b.currentCode = string(script)

0 commit comments

Comments
 (0)