Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Add adr-002 evm hooks proposal #429

Merged
merged 10 commits into from
Sep 1, 2021
Merged

Add adr-002 evm hooks proposal #429

merged 10 commits into from
Sep 1, 2021

Conversation

yihuang
Copy link
Contributor

@yihuang yihuang commented Aug 11, 2021

Description

ref impl: #417


For contributor use:

  • Targeted PR against correct branch (see CONTRIBUTING.md)
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards.
  • Wrote unit and integration tests
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/)
  • Added relevant godoc comments.
  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer

For admin use:

  • Added appropriate labels to PR (ex. WIP, R4R, docs, etc)
  • Reviewers assigned
  • Squashed all commits, uses message "Merge pull request #XYZ: [title]" (coding standards)

}
```

- `PostTxProcessing` is called after EVM transaction finished, executed with the same cache context as the EVM
Copy link
Contributor

Choose a reason for hiding this comment

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

This ADR doesn't explain why we need the PostTxProcessing hook. Can you explain in here how it will

enable EVM contract to communicate with cosmos native modules

Copy link
Contributor

Choose a reason for hiding this comment

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

perhaps adding some examples from: #394 (comment) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done, added the bank send example.

@orijbot
Copy link

orijbot commented Aug 30, 2021

@codecov
Copy link

codecov bot commented Aug 30, 2021

Codecov Report

Merging #429 (082d60e) into main (516ffe2) will increase coverage by 0.36%.
The diff coverage is n/a.

❗ Current head 082d60e differs from pull request most recent head c38957a. Consider uploading reports for the commit c38957a to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##             main     #429      +/-   ##
==========================================
+ Coverage   50.35%   50.71%   +0.36%     
==========================================
  Files          57       49       -8     
  Lines        5459     4874     -585     
==========================================
- Hits         2749     2472     -277     
+ Misses       2594     2297     -297     
+ Partials      116      105      -11     
Impacted Files Coverage Δ
types/chain_id.go 57.89% <0.00%> (-26.32%) ⬇️
x/evm/types/chain_config.go 76.61% <0.00%> (-20.85%) ⬇️
x/evm/keeper/state_transition.go 58.10% <0.00%> (-16.17%) ⬇️
server/config/config.go 17.85% <0.00%> (-3.42%) ⬇️
x/evm/keeper/statedb.go 84.76% <0.00%> (-1.49%) ⬇️
x/evm/types/utils.go 60.00% <0.00%> (-1.12%) ⬇️
x/evm/genesis.go 44.26% <0.00%> (-0.74%) ⬇️
app/app.go 83.37% <0.00%> (-0.43%) ⬇️
x/evm/keeper/grpc_query.go 70.88% <0.00%> (-0.33%) ⬇️
types/codec.go 0.00% <0.00%> (ø)
... and 17 more

Copy link
Contributor

@fedekunze fedekunze left a comment

Choose a reason for hiding this comment

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

The ADR is good, but it doesn't follow the ADR template and a lot of context and details are missing if you compare it with the implementation. For example, the following decision is not documented on the ADR:

if !res.Failed() {
	err = k.PostTxProcessing(txHash, logs)
	if err != nil {
		k.RevertToSnapshot(revision)
		res.VmError = "failed to process native logs"
		res.Ret = []byte(err.Error())
	}
}

Some questions that need to be documented:

  • why do we revert the state to the snapshot prior to the tx execution? (i.e why did you choose this approach over just performing a no-op on PostTxProcessing)
  • give a reference implementation for a Hook implementation
  • explain the MultiHook design for adding multiple hooks
  • explain how to add the Hook to the app.go

docs/architecture/adr-002-evm-hooks.md Show resolved Hide resolved
docs/architecture/adr-002-evm-hooks.md Outdated Show resolved Hide resolved
docs/architecture/adr-002-evm-hooks.md Outdated Show resolved Hide resolved
docs/architecture/adr-002-evm-hooks.md Outdated Show resolved Hide resolved
docs/architecture/adr-002-evm-hooks.md Show resolved Hide resolved
docs/architecture/adr-002-evm-hooks.md Show resolved Hide resolved
@yihuang
Copy link
Contributor Author

yihuang commented Aug 31, 2021

The ADR is good, but it doesn't follow the ADR template and a lot of context and details are missing if you compare it with the implementation. For example, the following decision is not documented on the ADR:

if !res.Failed() {
	err = k.PostTxProcessing(txHash, logs)
	if err != nil {
		k.RevertToSnapshot(revision)
		res.VmError = "failed to process native logs"
		res.Ret = []byte(err.Error())
	}
}

added a little bit more explanation to this:

  • hooks are called only when tx executed successfully
  • errors returned by hooks get translated to vm error, and cause the whole tx to revert.

Some questions that need to be documented:

  • why do we revert the state to the snapshot prior to the tx execution? (i.e why did you choose this approach over just performing a no-op on PostTxProcessing)

added, with this approach, the implementor is still free to swallow any error.

  • give a reference implementation for a Hook implementation

add the BankSendHook to adr.

  • explain the MultiHook design for adding multiple hooks

I think this is not essential for the proposal?

  • explain how to add the Hook to the app.go

added.

Copy link
Contributor

@fedekunze fedekunze left a comment

Choose a reason for hiding this comment

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

Looks better now, although there are some details and code snippet are missing about the integration with the state_transition.go.

I will also recommend you use Grammarly to fix some of the wording.

docs/architecture/adr-002-evm-hooks.md Show resolved Hide resolved
docs/architecture/adr-002-evm-hooks.md Outdated Show resolved Hide resolved
docs/architecture/adr-002-evm-hooks.md Outdated Show resolved Hide resolved
@yihuang
Copy link
Contributor Author

yihuang commented Aug 31, 2021

Looks better now, although there are some details and code snippet are missing about the integration with the state_transition.go.

done, added some ApplyTransaction code snippet.

I will also recommend you use Grammarly to fix some of the wording.

done

@yihuang yihuang requested a review from fedekunze August 31, 2021 16:47
Copy link
Contributor

@fedekunze fedekunze left a comment

Choose a reason for hiding this comment

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

ACK 👍

@fedekunze fedekunze merged commit 7f70429 into evmos:main Sep 1, 2021
@yihuang yihuang deleted the hook-adr branch September 1, 2021 10:28
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants