-
Notifications
You must be signed in to change notification settings - Fork 175
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
Conversation
Codecov ReportAttention:
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
Flags with carried forward coverage won't be shown. Click here to find out more.
☔ View full report in Codecov by Sentry. |
fvm/evm/handler/handler.go
Outdated
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), | ||
} | ||
} |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
fvm/evm/handler/handler.go
Outdated
res, | ||
), | ||
) | ||
newBalance := a.fch.getBlockDraftTotalSupply() + v.Balance().ToAttoFlow().Uint64() |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uint64 captures overflows.
fvm/evm/handler/handler.go
Outdated
func (h *ContractHandler) commitBlockDraft() { | ||
err := h.blockchain.AppendBlock(h.newBlockDraft) | ||
handleError(err) | ||
h.emitEvent(types.NewBlockExecutedEvent(h.newBlockDraft)) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧡
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some comments
…to ramtin/evm-add-handler
This PR adds the EVM handler, and here are the responsibilities of the handler