-
Notifications
You must be signed in to change notification settings - Fork 202
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
refactor: general code style cleanups on precompile and statedb journal #2100
Changes from 20 commits
295a2d9
80dd2d7
c624912
7f904a0
08a73ee
717ce1c
04a6897
7c34423
4e3bf3c
576cf6c
90fecf7
5fcb361
c1bb21a
10885f1
f04b1e5
78c835a
5b38ec5
d7db81b
7236e22
f6cccc7
2dc5646
5bae79e
94121a7
6dc3c9b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -3,13 +3,11 @@ | |||||
import ( | ||||||
"fmt" | ||||||
"math/big" | ||||||
"sync" | ||||||
|
||||||
"cosmossdk.io/math" | ||||||
sdk "github.com/cosmos/cosmos-sdk/types" | ||||||
auth "github.com/cosmos/cosmos-sdk/x/auth/types" | ||||||
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" | ||||||
gethabi "github.com/ethereum/go-ethereum/accounts/abi" | ||||||
gethcommon "github.com/ethereum/go-ethereum/common" | ||||||
"github.com/ethereum/go-ethereum/core/vm" | ||||||
|
||||||
|
@@ -32,29 +30,23 @@ | |||||
return PrecompileAddr_FunToken | ||||||
} | ||||||
|
||||||
func (p precompileFunToken) ABI() *gethabi.ABI { | ||||||
return embeds.SmartContract_FunToken.ABI | ||||||
} | ||||||
|
||||||
// RequiredGas calculates the cost of calling the precompile in gas units. | ||||||
func (p precompileFunToken) RequiredGas(input []byte) (gasCost uint64) { | ||||||
return RequiredGas(input, p.ABI()) | ||||||
k-yang marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
return requiredGas(input, embeds.SmartContract_FunToken.ABI) | ||||||
} | ||||||
|
||||||
const ( | ||||||
FunTokenMethod_BankSend PrecompileMethod = "bankSend" | ||||||
) | ||||||
|
||||||
type PrecompileMethod string | ||||||
|
||||||
// Run runs the precompiled contract | ||||||
func (p precompileFunToken) Run( | ||||||
evm *vm.EVM, contract *vm.Contract, readonly bool, | ||||||
) (bz []byte, err error) { | ||||||
defer func() { | ||||||
err = ErrPrecompileRun(err, p) | ||||||
}() | ||||||
start, err := OnRunStart(evm, contract, p.ABI()) | ||||||
start, err := OnRunStart(evm, contract.Input, embeds.SmartContract_FunToken.ABI) | ||||||
if err != nil { | ||||||
return nil, err | ||||||
} | ||||||
|
@@ -87,8 +79,6 @@ | |||||
evmKeeper evmkeeper.Keeper | ||||||
} | ||||||
|
||||||
var executionGuard sync.Mutex | ||||||
|
||||||
// bankSend: Implements "IFunToken.bankSend" | ||||||
// | ||||||
// The "args" populate the following function signature in Solidity: | ||||||
|
@@ -105,15 +95,10 @@ | |||||
caller gethcommon.Address, | ||||||
readOnly bool, | ||||||
) (bz []byte, err error) { | ||||||
ctx, method, args := start.Ctx, start.Method, start.Args | ||||||
if e := assertNotReadonlyTx(readOnly, true); e != nil { | ||||||
err = e | ||||||
return | ||||||
} | ||||||
if !executionGuard.TryLock() { | ||||||
return nil, fmt.Errorf("bankSend is already in progress") | ||||||
ctx, method, args := start.CacheCtx, start.Method, start.Args | ||||||
if readOnly { | ||||||
return nil, fmt.Errorf("bankSend cannot be called in read-only mode") | ||||||
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. Add test coverage for readOnly mode check The readOnly check is a critical safety measure, but static analysis indicates it lacks test coverage. Please add test cases to verify this behavior. Would you like me to help generate test cases for the readOnly mode check? 🧰 Tools🪛 GitHub Check: codecov/patch[warning] 100-100: x/evm/precompile/funtoken.go#L100 |
||||||
} | ||||||
defer executionGuard.Unlock() | ||||||
|
||||||
erc20, amount, to, err := p.decomposeBankSendArgs(args) | ||||||
if err != nil { | ||||||
|
@@ -242,7 +227,7 @@ | |||||
return nil | ||||||
} | ||||||
|
||||||
func (p precompileFunToken) decomposeBankSendArgs(args []any) ( | ||||||
func (p precompileFunToken) decomposeBankSendArgs(args []interface{}) ( | ||||||
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. 🛠️ Refactor suggestion Consider using modern Go type syntax The method signature uses -func (p precompileFunToken) decomposeBankSendArgs(args []interface{}) (
+func (p precompileFunToken) decomposeBankSendArgs(args []any) ( 📝 Committable suggestion
Suggested change
|
||||||
erc20 gethcommon.Address, | ||||||
amount *big.Int, | ||||||
to string, | ||||||
|
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.
You can add the method name as an argument to keep the error messages consistent across each tx method using the same function
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 originally got rid of
assertNotReadonlyTx
because whenever it was invoked, theisTx
argument was alwaystrue
, which made that parameter redundant becauseassertNotReadonlyTx
in a mutating precompile. I've replaced it and added thegethabi.Method
as a parameter to extract the method name into the error string.