Skip to content

Commit

Permalink
refactor with fixed block hashes
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangchiqing committed Nov 22, 2024
1 parent 36042e8 commit 2fd43ac
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 55 deletions.
52 changes: 0 additions & 52 deletions fvm/evm/offchain/blocks/block_context.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion fvm/evm/offchain/blocks/blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (b *Blocks) BlockContext() (types.BlockContext, error) {
if err != nil {
panic(err)
}
return hash
return UseFixedHashList(b.chainID, bm.Height, n, hash)
},
bm.Random,
nil,
Expand Down
64 changes: 64 additions & 0 deletions fvm/evm/offchain/blocks/fixed_block_hashes.go

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions fvm/evm/offchain/blocks/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
// a OnBlockReceived call before block execution and
// a follow up OnBlockExecuted call after block execution.
type BasicProvider struct {
chainID flow.ChainID,
blks *Blocks
latestBlockPayload *events.BlockEventPayload
}
Expand All @@ -28,7 +29,7 @@ func NewBasicProvider(
if err != nil {
return nil, err
}
return &BasicProvider{blks: blks}, nil
return &BasicProvider{chainID: chainID, blks: blks}, nil
}

// GetSnapshotAt returns a block snapshot at the given height
Expand Down Expand Up @@ -67,8 +68,12 @@ func (p *BasicProvider) OnBlockExecuted(
if p.latestBlockPayload.Height != height {
return fmt.Errorf("active block height doesn't match expected: %d, got: %d", p.latestBlockPayload.Height, height)
}

correctHash := p.latestBlockPayload.Hash
storedBlockHash := UseFixedHashList(b.chainID, height, height, correctHash)

return p.blks.PushBlockHash(
p.latestBlockPayload.Height,
p.latestBlockPayload.Hash,
storedBlockHash,
)
}

0 comments on commit 2fd43ac

Please sign in to comment.