-
Notifications
You must be signed in to change notification settings - Fork 195
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
fix(evm): proper eth tx logs emission for funtoken operations #2212
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,7 +102,7 @@ func (k *Keeper) deployERC20ForBankCoin( | |
k.Bank.StateDB = nil | ||
}() | ||
evmObj := k.NewEVM(ctx, evmMsg, evmCfg, nil /*tracer*/, stateDB) | ||
_, err = k.CallContractWithInput( | ||
evmResp, err := k.CallContractWithInput( | ||
ctx, evmObj, evm.EVM_MODULE_ADDRESS, nil, true /*commit*/, input, Erc20GasLimitDeploy, | ||
) | ||
if err != nil { | ||
|
@@ -114,5 +114,11 @@ func (k *Keeper) deployERC20ForBankCoin( | |
return gethcommon.Address{}, errors.Wrap(err, "failed to commit stateDB") | ||
} | ||
|
||
// Emit the logs from the EVM Contract deploy execution | ||
err = ctx.EventManager().EmitTypedEvent(&evm.EventTxLog{Logs: evmResp.Logs}) | ||
if err == nil { | ||
k.updateBlockBloom(ctx, evmResp, uint64(0)) | ||
} | ||
|
||
Comment on lines
+117
to
+122
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. emits |
||
return erc20Addr, nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -146,8 +146,6 @@ func (p precompileFunToken) sendToBank( | |
return nil, ErrInvalidArgs(err) | ||
} | ||
|
||
var evmResponses []*evm.MsgEthereumTxResponse | ||
|
||
// ERC20 must have FunToken mapping | ||
funtokens := p.evmKeeper.FunTokens.Collect( | ||
ctx, p.evmKeeper.FunTokens.Indexes.ERC20Addr.ExactMatch(ctx, erc20), | ||
|
@@ -170,7 +168,7 @@ func (p precompileFunToken) sendToBank( | |
} | ||
|
||
// Caller transfers ERC20 to the EVM module account | ||
gotAmount, transferResp, err := p.evmKeeper.ERC20().Transfer( | ||
gotAmount, _, err := p.evmKeeper.ERC20().Transfer( | ||
erc20, /*erc20*/ | ||
caller, /*from*/ | ||
evm.EVM_MODULE_ADDRESS, /*to*/ | ||
|
@@ -181,7 +179,6 @@ func (p precompileFunToken) sendToBank( | |
if err != nil { | ||
return nil, fmt.Errorf("error in ERC20.transfer from caller to EVM account: %w", err) | ||
} | ||
evmResponses = append(evmResponses, transferResp) | ||
|
||
// EVM account mints FunToken.BankDenom to module account | ||
coinToSend := sdk.NewCoin(funtoken.BankDenom, math.NewIntFromBigInt(gotAmount)) | ||
|
@@ -190,11 +187,10 @@ func (p precompileFunToken) sendToBank( | |
// owns the ERC20 contract and was the original minter of the ERC20 tokens. | ||
// Since we're sending them away and want accurate total supply tracking, the | ||
// tokens need to be burned. | ||
burnResp, err := p.evmKeeper.ERC20().Burn(erc20, evm.EVM_MODULE_ADDRESS, gotAmount, ctx, evmObj) | ||
_, err := p.evmKeeper.ERC20().Burn(erc20, evm.EVM_MODULE_ADDRESS, gotAmount, ctx, evmObj) | ||
if err != nil { | ||
return nil, fmt.Errorf("ERC20.Burn: %w", err) | ||
} | ||
evmResponses = append(evmResponses, burnResp) | ||
} else { | ||
// NOTE: The NibiruBankKeeper needs to reference the current [vm.StateDB] before | ||
// any operation that has the potential to use Bank send methods. This will | ||
|
@@ -225,11 +221,6 @@ func (p precompileFunToken) sendToBank( | |
evm.ModuleName, evm.EVM_MODULE_ADDRESS.Hex(), caller.Hex(), err, | ||
) | ||
} | ||
for _, resp := range evmResponses { | ||
for _, log := range resp.Logs { | ||
startResult.StateDB.AddLog(log.ToEthereum()) | ||
} | ||
} | ||
Comment on lines
-228
to
-232
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this produced duplicates. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought we added this in https://github.com/NibiruChain/nibiru/pull/2093/files#diff-199132a0cc4ad1df87325761675688436e1e9dc09d8b24908631937349e12f89 because we were missing logs, how did we end up with duplicates? |
||
|
||
// TODO: UD-DEBUG: feat: Emit EVM events | ||
// https://github.com/NibiruChain/nibiru/issues/2121 | ||
|
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.
TxLogs is now emitted properly at the end of the execution, not on each CallContract separately