Skip to content

Commit

Permalink
Blockchain's vmCtx should always be updated to point to the latest He…
Browse files Browse the repository at this point in the history
…ader

We also rename Blockchain's newFVMContextFromHeader() to setFVMContextFromHeader()
  • Loading branch information
m-Peter committed Sep 27, 2023
1 parent 8c6c483 commit 6e8d85b
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions emulator/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -774,11 +774,13 @@ func configureTransactionValidator(conf config, blocks *blocks) *access.Transact
)
}

func (b *Blockchain) newFVMContextFromHeader(header *flowgo.Header) fvm.Context {
return fvm.NewContextFromParent(
func (b *Blockchain) setFVMContextFromHeader(header *flowgo.Header) fvm.Context {
b.vmCtx = fvm.NewContextFromParent(
b.vmCtx,
fvm.WithBlockHeader(header),
)

return b.vmCtx
}

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

header := b.pendingBlock.Block().Header
blockContext := b.newFVMContextFromHeader(header)
blockContext := b.setFVMContextFromHeader(header)

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

header := b.pendingBlock.Block().Header
blockContext := b.newFVMContextFromHeader(header)
blockContext := b.setFVMContextFromHeader(header)
return b.executeNextTransaction(blockContext)
}

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

header := requestedBlock.Header
blockContext := b.newFVMContextFromHeader(header)
blockContext := fvm.NewContextFromParent(
b.vmCtx,
fvm.WithBlockHeader(requestedBlock.Header),
)

scriptProc := fvm.Script(script).WithArguments(arguments...)
b.currentCode = string(script)
Expand Down

0 comments on commit 6e8d85b

Please sign in to comment.