Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FVM] beyond EVM part 4 - adding EVM handler #4864

Merged
merged 33 commits into from
Nov 9, 2023
Merged

Conversation

ramtinms
Copy link
Member

@ramtinms ramtinms commented Oct 23, 2023

This PR adds the EVM handler, and here are the responsibilities of the handler

  • provides an interface to the stdlib
  • prepare block context
  • handle errors
  • emit events ( internal types to external)
  • handle the metering conversion
  • decode transactions

@ramtinms ramtinms changed the title [FVM] adding the evm handler (beyond EVM) [FVM] beyond EVM part 4 - adding EVM handler Oct 23, 2023
@ramtinms ramtinms marked this pull request as ready for review October 24, 2023 22:52
fvm/evm/handler/handler.go Outdated Show resolved Hide resolved
Base automatically changed from ramtin/evm-update-fvm-environment to master November 7, 2023 02:57
@codecov-commenter
Copy link

codecov-commenter commented Nov 7, 2023

Codecov Report

Attention: 58 lines in your changes are missing coverage. Please review.

Comparison is base (1990e2f) 55.75% compared to head (63b099f) 52.30%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4864      +/-   ##
==========================================
- Coverage   55.75%   52.30%   -3.46%     
==========================================
  Files         959      701     -258     
  Lines       89270    63793   -25477     
==========================================
- Hits        49773    33367   -16406     
+ Misses      35752    27839    -7913     
+ Partials     3745     2587    -1158     
Flag Coverage Δ
unittests 52.30% <81.64%> (-3.46%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
fvm/environment/meter.go 73.91% <ø> (ø)
fvm/evm/types/balance.go 71.42% <ø> (ø)
fvm/evm/types/events.go 0.00% <0.00%> (ø)
fvm/evm/handler/addressAllocator.go 77.77% <77.77%> (ø)
fvm/evm/types/block.go 0.00% <0.00%> (ø)
fvm/evm/handler/handler.go 91.55% <91.55%> (ø)
fvm/evm/handler/blockstore.go 57.40% <57.40%> (ø)

... and 266 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines 112 to 127
func (h *ContractHandler) setupNewBlockDraft() {
lastExecutedBlock, err := h.blockchain.LatestBlock()
handleError(err)

parentHash, err := lastExecutedBlock.Hash()
if err != nil {
// this is a fatal error
panic(err)
}
h.newBlockDraft = &types.Block{
Height: lastExecutedBlock.Height + 1,
ParentBlockHash: parentHash,
TotalSupply: lastExecutedBlock.TotalSupply,
TransactionHashes: make([]gethCommon.Hash, 0),
}
}
Copy link
Member

@sideninja sideninja Nov 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't this make sense to be part of the blockchain interface and implemented as part of the blocks? the block model could also implement all the methods below to update the defined below.

So basically changing this method to something like:

func (h *ContractHandler) blockDraft() {
    if h.newBlockDraft != nil {
        return h.newBlockDraft
    }

    h.newBlockDraft = h.blockchain.NewBlock()
}

And then removing all the methods below since you can just do:

h.blockDraft().AppendTxHash(hash)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also thinking about it again, it might even be useful for blockchain to handle that, so you could create a draft block using the blockchain like above, but then it would only allow you to create a new one after you commit it? That way you also don't have to check if nil here, but could just be a call to blockchain.DraftBlock

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refactored at 3677c74


// Balance returns the balance of this bridged account
func (a *Account) Balance() types.Balance {
ctx := a.fch.getBlockContext()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should accessing the balance be metered?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for read calls, currently we don't meter any computation and only check the storage interaction limits

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we might want to do it in the future, I'll add a TODO

res,
),
)
newBalance := a.fch.getBlockDraftTotalSupply() + v.Balance().ToAttoFlow().Uint64()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess overflow is not a real issue for us here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uint64 captures overflows.

func (h *ContractHandler) commitBlockDraft() {
err := h.blockchain.AppendBlock(h.newBlockDraft)
handleError(err)
h.emitEvent(types.NewBlockExecutedEvent(h.newBlockDraft))
Copy link
Member

@sideninja sideninja Nov 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this could cause exceeding computation limit. I might be nitpicking, but could there be a case where the tx gas limit is the same as computation limit, so the checkGasLimit passes, and tx actually uses all the gas, but then emitting the event adds computation usage and causes the transaction to fail. I guess it could be ok since it would revert the transaction, but I rather ask than not.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

emitting events are metered through the FVM backend, so they would fail similarly to how cadence transactions fail.

@@ -44,3 +43,9 @@ type Backend interface {
environment.Meter
environment.EventEmitter
}

// AddressAllocator allocates addresses, used by the handler
type AddressAllocator interface {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧡

Copy link
Member

@sideninja sideninja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some comments

@sideninja sideninja self-requested a review November 8, 2023 17:37
@ramtinms ramtinms added this pull request to the merge queue Nov 8, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 8, 2023
@ramtinms ramtinms added this pull request to the merge queue Nov 8, 2023
@ramtinms ramtinms removed this pull request from the merge queue due to a manual request Nov 9, 2023
@ramtinms ramtinms added this pull request to the merge queue Nov 9, 2023
Merged via the queue into master with commit 0c0fdab Nov 9, 2023
36 checks passed
@ramtinms ramtinms deleted the ramtin/evm-add-handler branch November 9, 2023 03:48
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants