Skip to content

A better abstraction is required in order to access the chain state #166

Open
@gustavo-grieco

Description

@gustavo-grieco

One of the objectives of medusa is to allow easy extensions of the code. I recently created a PR to optimize the gas usage instead of a call to a particular function. While it was not very complicated, the API to query the TestChain object should be improved. For instance, in order to access to the receipt of the last transaction, I had to check the pending block. If there is no transactions pending, I had to look at the last block:

		pending := worker.Chain().PendingBlock()
		var gasUsed uint64 = 0
		if pending != nil {
			messagesLen := len(pending.MessageResults)
			if messagesLen > 0 {
				gasUsed = pending.MessageResults[messagesLen-1].Receipt.GasUsed
			}
		} else {
			blocks := worker.Chain().CommittedBlocks()
			blocksLen := len(blocks)
			lastBlock := blocks[blocksLen-1]
			messagesLen := len(lastBlock.MessageResults)
			gasUsed = lastBlock.MessageResults[messagesLen-1].Receipt.GasUsed
		}

I believe this is inherited from geth and it is not clear for me how to improve it to allow a more uniform access to the latest transactions, but it could be a good idea to improve for future extensions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    on holdThis issue was marked as not desirable to complete for nowvery-low-priority

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions