onflow/flow-emulator

Remove headers.go

Closed this issue · 5 comments

Issue To Be Solved

This came up on recent PR #266

Do we really need headers in emulator? @janezpodhostnik @turbolent

I think it is only used for cadence getBlock functions, as we don't fork chain in emulator, returning block from storage seems to suffice. But I maybe missing something

in blocks.go maybe we can do something like:

func (b *blocks) ByHeightFrom(height uint64, header *flowgo.Header) (*flowgo.Header, error) {
       // bluesign: maybe some height check here needed 

       block, err := b.blockchain.storage.BlockByHeight(context.Background(), height)
	if err != nil {
		return nil, err
	}
	return block.Header, nil
}

I think this will make emulator - flow-go coupling looser.

Your proposal seems ok. Yet, I don't know when the emulator finalizes blocks. Does it do that immediately when the block is produced?

I think it is only used for cadence getBlock functions

That might be the case. In which case what you are proposing makes total sense. I'll take some time to look this over tomorrow.

thanks a lot both of you

Looks like the use of headers in headers.go is in the function you mentioned:

func (b *blocks) ByHeightFrom(height uint64, header *flowgo.Header) (*flowgo.Header, error) {
	return environment.NewBlockFinder(b.headers).
		ByHeightFrom(height, header)
}

Removing them and rewriting this function would get rid of a lot of code. Getting the block by height, is totally acceptable.

thank you very much @janezpodhostnik , I will make a PR tomorrow.