forked from cerc-io/laconicd-deprecated
bump Cosmos SDK version to v0.38.2 (#183)
* evm: move Keeper and Querier to /keeper package * keeper: update keeper_test.go * fix format * evm: use aliased types * bump SDK version to v0.38.1 * app: updates from new version * errors: switch sdk.Error -> error * errors: switch sdk.Error -> error. Continuation * more fixes * update app/ * update keys and client pkgs * build * fix tests * lint * minor changes * changelog * address @austinbell comments * Fix keyring usage in rpc API and CLI * fix keyring * break line * Misc cleanup (#188) * evm: move Begin and EndBlock to abci.go * evm: use expected keeper interfaces * app: use EthermintApp for integration and unit test setup * evm: remove count type; update codec * go mod verify * evm: rename msgs for consistency * evm: events * minor cleanup * lint * ante: update tests * changelog * nolint * evm: update statedb to create ethermint Account instead of BaseAccount * fix importer test * address @austinabell comments * update README * changelog * evm: update codec * fix event sender * store logs in keeper after transition (#210) * add some comments * begin log handler test * update TransitionCSDB to return ReturnData * use rlp for result data encode/decode * update tests * implement SetBlockLogs * implement GetBlockLogs * test log set/get * update keeper get/set logs to use hash as key * fix test * move logsKey to csdb * attempt to fix test * attempt to fix test * attempt to fix test * lint * lint * lint * save logs after handling msg * update k.Logs * cleanup * remove unused * fix issues * comment out handler test * address comments * lint * fix handler test * address comments * use amino * lint * address comments * merge * fix encoding bug * minor fix * rpc: error handling * rpc: simulate only returns gasConsumed * rpc: error ineffassign * go: bump version to 1.14 and SDK version to latest master * rpc: fix simulation return value * breaking changes from SDK * sdk: breaking changes; build * tests: fixes * minor fix * proto: ethermint types attempt * proto: define EthAccount proto type and extend sdk std.Codec * evm: fix panic on handler test * evm: minor state object changes * cleanup * tests: update test-importer * fix pubkey registration * lint * cleanup * more test checks for importer * minor change * codec fixes * rm init func * fix importer test build * fix marshaling for TxDecoder * use amino codec for evm * fix marshaling for SimulationResponse * use jsonpb for unmarshaling * fix method handler crashed * return err on VerifySig * switch stateObject balance to sdk.Int * fixes to codec and encoding * cleanup * set tmhash -> ethhash in state transition * add tmhash->ethereumhash to csdb.GetLogs * attempt to fix tests * update GetLogs to switch with Has * ante panic * diff changes * update SetLogs * evm/cli: use ethermint codec * use LengthPrefixed for encoding * add check for nil *big.Int * add balance to UpdateAccounts * fix previous balance * fix balance bug * prevent panic on make test-import Co-authored-by: austinabell <austinabell8@gmail.com> Co-authored-by: noot <36753753+noot@users.noreply.github.com> Co-authored-by: noot <elizabethjbinks@gmail.com>
This commit is contained in:
co-authored by
austinabell
noot
noot
parent
2693718662
commit
4d609b2a22
@@ -58,18 +58,14 @@ func (msg MsgEthermint) GetSignBytes() []byte {
|
||||
}
|
||||
|
||||
// ValidateBasic runs stateless checks on the message
|
||||
func (msg MsgEthermint) ValidateBasic() sdk.Error {
|
||||
func (msg MsgEthermint) ValidateBasic() error {
|
||||
if msg.Price.Sign() != 1 {
|
||||
return sdk.ConvertError(
|
||||
sdkerrors.Wrapf(types.ErrInvalidValue, "price must be positive %s", msg.Price),
|
||||
)
|
||||
return sdkerrors.Wrapf(types.ErrInvalidValue, "price must be positive %s", msg.Price)
|
||||
}
|
||||
|
||||
// Amount can be 0
|
||||
if msg.Amount.Sign() == -1 {
|
||||
return sdk.ConvertError(
|
||||
sdkerrors.Wrapf(types.ErrInvalidValue, "amount cannot be negative %s", msg.Amount),
|
||||
)
|
||||
return sdkerrors.Wrapf(types.ErrInvalidValue, "amount cannot be negative %s", msg.Amount)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -12,3 +12,9 @@ type AccountKeeper interface {
|
||||
SetAccount(ctx sdk.Context, account authexported.Account)
|
||||
RemoveAccount(ctx sdk.Context, account authexported.Account)
|
||||
}
|
||||
|
||||
// BankKeeper defines the expected interface needed to retrieve account balances.
|
||||
type BankKeeper interface {
|
||||
GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin
|
||||
SetBalance(ctx sdk.Context, addr sdk.AccAddress, balance sdk.Coin) error
|
||||
}
|
||||
|
||||
+7
-15
@@ -125,18 +125,14 @@ func (msg MsgEthereumTx) Type() string { return TypeMsgEthereumTx }
|
||||
|
||||
// ValidateBasic implements the sdk.Msg interface. It performs basic validation
|
||||
// checks of a Transaction. If returns an error if validation fails.
|
||||
func (msg MsgEthereumTx) ValidateBasic() sdk.Error {
|
||||
func (msg MsgEthereumTx) ValidateBasic() error {
|
||||
if msg.Data.Price.Sign() != 1 {
|
||||
return sdk.ConvertError(
|
||||
sdkerrors.Wrapf(types.ErrInvalidValue, "price must be positive %s", msg.Data.Price),
|
||||
)
|
||||
return sdkerrors.Wrapf(types.ErrInvalidValue, "price must be positive %s", msg.Data.Price)
|
||||
}
|
||||
|
||||
// Amount can be 0
|
||||
if msg.Data.Amount.Sign() == -1 {
|
||||
return sdk.ConvertError(
|
||||
sdkerrors.Wrapf(types.ErrInvalidValue, "amount cannot be negative %s", msg.Data.Amount),
|
||||
)
|
||||
return sdkerrors.Wrapf(types.ErrInvalidValue, "amount cannot be negative %s", msg.Data.Amount)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -331,22 +327,18 @@ func deriveChainID(v *big.Int) *big.Int {
|
||||
// TxDecoder returns an sdk.TxDecoder that can decode both auth.StdTx and
|
||||
// MsgEthereumTx transactions.
|
||||
func TxDecoder(cdc *codec.Codec) sdk.TxDecoder {
|
||||
return func(txBytes []byte) (sdk.Tx, sdk.Error) {
|
||||
return func(txBytes []byte) (sdk.Tx, error) {
|
||||
var tx sdk.Tx
|
||||
|
||||
if len(txBytes) == 0 {
|
||||
return nil, sdk.ConvertError(
|
||||
sdkerrors.Wrap(sdkerrors.ErrTxDecode, "tx bytes are empty"),
|
||||
)
|
||||
return nil, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "tx bytes are empty")
|
||||
}
|
||||
|
||||
// sdk.Tx is an interface. The concrete message types
|
||||
// are registered by MakeTxCodec
|
||||
err := cdc.UnmarshalBinaryLengthPrefixed(txBytes, &tx)
|
||||
err := cdc.UnmarshalBinaryBare(txBytes, &tx)
|
||||
if err != nil {
|
||||
return nil, sdk.ConvertError(
|
||||
sdkerrors.Wrap(sdkerrors.ErrTxDecode, err.Error()),
|
||||
)
|
||||
return nil, sdkerrors.Wrap(sdkerrors.ErrTxDecode, err.Error())
|
||||
}
|
||||
|
||||
return tx, nil
|
||||
|
||||
+16
-16
@@ -59,7 +59,8 @@ type (
|
||||
// by StateDB.Commit.
|
||||
dbErr error
|
||||
stateDB *CommitStateDB
|
||||
account *types.Account
|
||||
account *types.EthAccount
|
||||
balance sdk.Int
|
||||
originStorage types.Storage // Storage cache of original entries to dedup rewrites
|
||||
dirtyStorage types.Storage // Storage entries that need to be flushed to disk
|
||||
address ethcmn.Address
|
||||
@@ -73,8 +74,8 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
func newStateObject(db *CommitStateDB, accProto authexported.Account) *stateObject {
|
||||
ethermintAccount, ok := accProto.(*types.Account)
|
||||
func newStateObject(db *CommitStateDB, accProto authexported.Account, balance sdk.Int) *stateObject {
|
||||
ethermintAccount, ok := accProto.(*types.EthAccount)
|
||||
if !ok {
|
||||
panic(fmt.Sprintf("invalid account type for state object: %T", accProto))
|
||||
}
|
||||
@@ -87,6 +88,7 @@ func newStateObject(db *CommitStateDB, accProto authexported.Account) *stateObje
|
||||
return &stateObject{
|
||||
stateDB: db,
|
||||
account: ethermintAccount,
|
||||
balance: balance,
|
||||
address: ethcmn.BytesToAddress(ethermintAccount.GetAddress().Bytes()),
|
||||
originStorage: make(types.Storage),
|
||||
dirtyStorage: make(types.Storage),
|
||||
@@ -145,18 +147,18 @@ func (so *stateObject) setCode(codeHash ethcmn.Hash, code []byte) {
|
||||
// funds to the destination account of a transfer.
|
||||
func (so *stateObject) AddBalance(amount *big.Int) {
|
||||
amt := sdk.NewIntFromBigInt(amount)
|
||||
|
||||
// EIP158: We must check emptiness for the objects such that the account
|
||||
// clearing (0,0,0 objects) can take effect.
|
||||
if amt.Sign() == 0 {
|
||||
|
||||
// NOTE: this will panic if amount is nil
|
||||
if amt.IsZero() {
|
||||
if so.empty() {
|
||||
so.touch()
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
newBalance := so.account.Balance().Add(amt)
|
||||
newBalance := so.balance.Add(amt)
|
||||
so.SetBalance(newBalance.BigInt())
|
||||
}
|
||||
|
||||
@@ -164,12 +166,10 @@ func (so *stateObject) AddBalance(amount *big.Int) {
|
||||
// remove funds from the origin account of a transfer.
|
||||
func (so *stateObject) SubBalance(amount *big.Int) {
|
||||
amt := sdk.NewIntFromBigInt(amount)
|
||||
|
||||
if amt.Sign() == 0 {
|
||||
if amt.IsZero() {
|
||||
return
|
||||
}
|
||||
|
||||
newBalance := so.account.Balance().Sub(amt)
|
||||
newBalance := so.balance.Sub(amt)
|
||||
so.SetBalance(newBalance.BigInt())
|
||||
}
|
||||
|
||||
@@ -179,14 +179,14 @@ func (so *stateObject) SetBalance(amount *big.Int) {
|
||||
|
||||
so.stateDB.journal.append(balanceChange{
|
||||
account: &so.address,
|
||||
prev: so.account.Balance(),
|
||||
prev: so.balance,
|
||||
})
|
||||
|
||||
so.setBalance(amt)
|
||||
}
|
||||
|
||||
func (so *stateObject) setBalance(amount sdk.Int) {
|
||||
so.account.SetBalance(amount)
|
||||
so.balance = amount
|
||||
}
|
||||
|
||||
// SetNonce sets the state object's nonce (i.e sequence number of the account).
|
||||
@@ -262,7 +262,7 @@ func (so stateObject) Address() ethcmn.Address {
|
||||
|
||||
// Balance returns the state object's current balance.
|
||||
func (so *stateObject) Balance() *big.Int {
|
||||
balance := so.account.Balance().BigInt()
|
||||
balance := so.balance.BigInt()
|
||||
if balance == nil {
|
||||
return zeroBalance
|
||||
}
|
||||
@@ -354,7 +354,7 @@ func (so *stateObject) GetCommittedState(_ ethstate.Database, key ethcmn.Hash) e
|
||||
func (so *stateObject) ReturnGas(gas *big.Int) {}
|
||||
|
||||
func (so *stateObject) deepCopy(db *CommitStateDB) *stateObject {
|
||||
newStateObj := newStateObject(db, so.account)
|
||||
newStateObj := newStateObject(db, so.account, so.balance)
|
||||
|
||||
newStateObj.code = so.code
|
||||
newStateObj.dirtyStorage = so.dirtyStorage.Copy()
|
||||
@@ -371,7 +371,7 @@ func (so *stateObject) empty() bool {
|
||||
return so.account == nil ||
|
||||
(so.account != nil &&
|
||||
so.account.Sequence == 0 &&
|
||||
so.account.Balance().Sign() == 0 &&
|
||||
(so.balance.BigInt() == nil || so.balance.IsZero()) &&
|
||||
bytes.Equal(so.account.CodeHash, emptyCodeHash))
|
||||
}
|
||||
|
||||
|
||||
@@ -88,7 +88,7 @@ func (st StateTransition) TransitionCSDB(ctx sdk.Context) (*ReturnData, error) {
|
||||
Time: big.NewInt(ctx.BlockHeader().Time.Unix()),
|
||||
Difficulty: big.NewInt(0), // unused. Only required in PoW context
|
||||
GasLimit: gasLimit,
|
||||
GasPrice: gasPrice.Int,
|
||||
GasPrice: gasPrice.BigInt(),
|
||||
}
|
||||
|
||||
evm := vm.NewEVM(context, csdb, GenerateChainConfig(st.ChainID), vm.Config{})
|
||||
|
||||
+25
-10
@@ -43,6 +43,7 @@ type CommitStateDB struct {
|
||||
codeKey sdk.StoreKey
|
||||
storeKey sdk.StoreKey // i.e storage key
|
||||
accountKeeper AccountKeeper
|
||||
bankKeeper BankKeeper
|
||||
|
||||
// maps that hold 'live' objects, which will get modified while processing a
|
||||
// state transition
|
||||
@@ -84,13 +85,14 @@ type CommitStateDB struct {
|
||||
// CONTRACT: Stores used for state must be cache-wrapped as the ordering of the
|
||||
// key/value space matters in determining the merkle root.
|
||||
func NewCommitStateDB(
|
||||
ctx sdk.Context, codeKey, storeKey sdk.StoreKey, ak AccountKeeper,
|
||||
ctx sdk.Context, codeKey, storeKey sdk.StoreKey, ak AccountKeeper, bk BankKeeper,
|
||||
) *CommitStateDB {
|
||||
return &CommitStateDB{
|
||||
ctx: ctx,
|
||||
codeKey: codeKey,
|
||||
storeKey: storeKey,
|
||||
accountKeeper: ak,
|
||||
bankKeeper: bk,
|
||||
stateObjects: make(map[ethcmn.Address]*stateObject),
|
||||
stateObjectsDirty: make(map[ethcmn.Address]struct{}),
|
||||
logs: make(map[ethcmn.Hash][]*ethtypes.Log),
|
||||
@@ -463,7 +465,12 @@ func (csdb *CommitStateDB) IntermediateRoot(deleteEmptyObjects bool) (ethcmn.Has
|
||||
// updateStateObject writes the given state object to the store.
|
||||
func (csdb *CommitStateDB) updateStateObject(so *stateObject) error {
|
||||
csdb.accountKeeper.SetAccount(csdb.ctx, so.account)
|
||||
return nil
|
||||
// NOTE: we don't use sdk.NewCoin here to avoid panic on test importer's genesis
|
||||
newBalance := sdk.Coin{Denom: emint.DenomDefault, Amount: sdk.NewIntFromBigInt(so.Balance())}
|
||||
if !newBalance.IsValid() {
|
||||
return fmt.Errorf("invalid balance %s", newBalance)
|
||||
}
|
||||
return csdb.bankKeeper.SetBalance(csdb.ctx, so.account.Address, newBalance)
|
||||
}
|
||||
|
||||
// deleteStateObject removes the given state object from the state store.
|
||||
@@ -581,14 +588,19 @@ func (csdb *CommitStateDB) Reset(_ ethcmn.Hash) error {
|
||||
func (csdb *CommitStateDB) UpdateAccounts() {
|
||||
for addr, so := range csdb.stateObjects {
|
||||
currAcc := csdb.accountKeeper.GetAccount(csdb.ctx, sdk.AccAddress(addr.Bytes()))
|
||||
emintAcc, ok := currAcc.(*emint.Account)
|
||||
if ok {
|
||||
if so.Balance() != emintAcc.Balance().BigInt() || so.Nonce() != emintAcc.GetSequence() {
|
||||
// If queried account's balance or nonce are invalid, update the account pointer
|
||||
so.account = emintAcc
|
||||
}
|
||||
emintAcc, ok := currAcc.(*emint.EthAccount)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
balance := csdb.bankKeeper.GetBalance(csdb.ctx, emintAcc.GetAddress(), emint.DenomDefault)
|
||||
if so.Balance() != balance.Amount.BigInt() && balance.IsValid() {
|
||||
so.balance = balance.Amount
|
||||
}
|
||||
|
||||
if so.Nonce() != emintAcc.GetSequence() {
|
||||
so.account = emintAcc
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -642,6 +654,7 @@ func (csdb *CommitStateDB) Copy() *CommitStateDB {
|
||||
codeKey: csdb.codeKey,
|
||||
storeKey: csdb.storeKey,
|
||||
accountKeeper: csdb.accountKeeper,
|
||||
bankKeeper: csdb.bankKeeper,
|
||||
stateObjects: make(map[ethcmn.Address]*stateObject, len(csdb.journal.dirties)),
|
||||
stateObjectsDirty: make(map[ethcmn.Address]struct{}, len(csdb.journal.dirties)),
|
||||
refund: csdb.refund,
|
||||
@@ -737,7 +750,7 @@ func (csdb *CommitStateDB) createObject(addr ethcmn.Address) (newObj, prevObj *s
|
||||
|
||||
acc := csdb.accountKeeper.NewAccountWithAddress(csdb.ctx, sdk.AccAddress(addr.Bytes()))
|
||||
|
||||
newObj = newStateObject(csdb, acc)
|
||||
newObj = newStateObject(csdb, acc, sdk.ZeroInt())
|
||||
newObj.setNonce(0) // sets the object to dirty
|
||||
|
||||
if prevObj == nil {
|
||||
@@ -776,8 +789,10 @@ func (csdb *CommitStateDB) getStateObject(addr ethcmn.Address) (stateObject *sta
|
||||
return nil
|
||||
}
|
||||
|
||||
balance := csdb.bankKeeper.GetBalance(csdb.ctx, acc.GetAddress(), emint.DenomDefault)
|
||||
|
||||
// insert the state object into the live set
|
||||
so := newStateObject(csdb, acc)
|
||||
so := newStateObject(csdb, acc, balance.Amount)
|
||||
csdb.setStateObject(so)
|
||||
|
||||
return so
|
||||
|
||||
@@ -49,14 +49,14 @@ func rlpHash(x interface{}) (hash ethcmn.Hash) {
|
||||
|
||||
// ResultData represents the data returned in an sdk.Result
|
||||
type ResultData struct {
|
||||
Address ethcmn.Address
|
||||
Bloom ethtypes.Bloom
|
||||
Logs []*ethtypes.Log
|
||||
Ret []byte
|
||||
TxHash ethcmn.Hash
|
||||
Address ethcmn.Address `json:"address"`
|
||||
Bloom ethtypes.Bloom `json:"bloom"`
|
||||
Logs []*ethtypes.Log `json:"logs"`
|
||||
Ret []byte `json:"ret"`
|
||||
TxHash ethcmn.Hash `json:"tx_hash"`
|
||||
}
|
||||
|
||||
// EncodeReturnData takes all of the necessary data from the EVM execution
|
||||
// EncodeResultData takes all of the necessary data from the EVM execution
|
||||
// and returns the data as a byte slice encoded with amino
|
||||
func EncodeResultData(data *ResultData) ([]byte, error) {
|
||||
return ModuleCdc.MarshalBinaryLengthPrefixed(data)
|
||||
|
||||
Reference in New Issue
Block a user