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

Commit

Permalink
clean
Browse files Browse the repository at this point in the history
  • Loading branch information
calbera committed Jun 29, 2023
1 parent b86a014 commit de58a5c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions cosmos/x/evm/plugins/precompile/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func (p *plugin) enableReentrancy(sdb vm.PolarisStateDB) {

// end precompile execution => stop emitting Cosmos event as Eth logs for now
cem := utils.MustGetAs[state.ControllableEventManager](sdkCtx.EventManager())
cem.DisableEthLogging()
cem.EndPrecompileExecution()

// remove Cosmos gas consumption so gas is consumed only per OPCODE
p.sp.SetGasConfig(storetypes.GasConfig{}, storetypes.GasConfig{})
Expand All @@ -197,7 +197,7 @@ func (p *plugin) disableReentrancy(sdb vm.PolarisStateDB) {

// resume precompile execution => begin emitting Cosmos event as Eth logs again
cem := utils.MustGetAs[state.ControllableEventManager](sdkCtx.EventManager())
cem.EnableEthLogging(sdb)
cem.BeginPrecompileExecution(sdb)

// restore ctx gas configs for continuing precompile execution
p.sp.SetGasConfig(p.kvGasConfig, p.transientKVGasConfig)
Expand Down
2 changes: 1 addition & 1 deletion cosmos/x/evm/plugins/precompile/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func (msf *mockStateful) RegistryKey() common.Address {
// panics if modifying state on read-only.
func (msf *mockStateful) Run(
ctx context.Context, _ precompile.EVM, input []byte,
caller common.Address, _ *big.Int,
_ common.Address, _ *big.Int,
) ([]byte, error) {
if input[0] == byte(2) {
panic(vm.ErrWriteProtection)
Expand Down
16 changes: 8 additions & 8 deletions cosmos/x/evm/plugins/state/events/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,17 @@ func (m *manager) SetReadOnly(readOnly bool) {
m.readOnly = readOnly
}

// EnableEthLogging is called when Cosmos events from precompiles should be emitted as Eth logs.
// This function sets the `LogsDB` to the given `ldb` so that the `EmitEvent` and `EmitEvents`
// methods can add logs to the journal.
func (m *manager) EnableEthLogging(ldb LogsDB) {
// BeginPrecompileExecution is called when a precompile is about to be executed. This function
// sets the `LogsDB` to the given `ldb` so that the `EmitEvent` and `EmitEvents` methods can
// add logs to the journal.
func (m *manager) BeginPrecompileExecution(ldb LogsDB) {
m.ldb = ldb
}

// DisableEthLogging is called when Cosmos events from precompiles should be emitted as Eth logs.
// This function sets the `LogsDB` to nil so that the `EmitEvent` and `EmitEvents` methods don't
// add logs to the journal.
func (m *manager) DisableEthLogging() {
// EndPrecompileExecution is called when a precompile has finished executing. This function
// sets the `LogsDB` to nil so that the `EmitEvent` and `EmitEvents` methods don't add logs
// to the journal.
func (m *manager) EndPrecompileExecution() {
m.ldb = nil
}

Expand Down
6 changes: 3 additions & 3 deletions cosmos/x/evm/plugins/state/events/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ var _ = Describe("Manager", func() {
})

It("should panic when building eth logs fails", func() {
cem.EnableEthLogging(ldb)
cem.BeginPrecompileExecution(ldb)

Expect(func() {
ctx.EventManager().EmitEvent(sdk.NewEvent("non-eth-event"))
}).To(Panic())
})

It("should build eth logs from cosmos events during precompile", func() {
cem.EnableEthLogging(ldb)
cem.BeginPrecompileExecution(ldb)

ctx.EventManager().EmitEvent(sdk.NewEvent("2"))
Expect(ctx.EventManager().Events()).To(HaveLen(2))
Expand All @@ -96,7 +96,7 @@ var _ = Describe("Manager", func() {
Expect(ctx.EventManager().Events()).To(HaveLen(4))
Expect(ldb.AddLogCalls()).To(HaveLen(3))

cem.DisableEthLogging()
cem.EndPrecompileExecution()

Expect(func() { cem.Finalize() }).ToNot(Panic())
})
Expand Down
8 changes: 4 additions & 4 deletions cosmos/x/evm/plugins/state/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ type ControllableEventManager interface {
libtypes.Controllable[string]
sdk.EventManagerI

// EnableEthLogging sets the logs DB to begin emitting Cosmos events as Eth logs.
EnableEthLogging(events.LogsDB)
// DisableEthLogging resets the logs DB to nil to stop emitting Cosmos events as Eth logs.
DisableEthLogging()
// BeginPrecompileExecution begins a precompile execution by setting the logs DB.
BeginPrecompileExecution(events.LogsDB)
// EndPrecompileExecution ends a precompile execution by resetting the logs DB to nil.
EndPrecompileExecution()

// IsReadOnly returns true if the EventManager is read-only.
IsReadOnly() bool
Expand Down

0 comments on commit de58a5c

Please sign in to comment.