Skip to content
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

Mg/debug evm state transfer #12

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions plugin/evm/export_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"context"
"errors"
"fmt"
"github.com/ava-labs/coreth/core/vm"

Check failure on line 10 in plugin/evm/export_tx.go

View workflow job for this annotation

GitHub Actions / Lint

File is not `goimports`-ed (goimports)
"math/big"

"github.com/ava-labs/coreth/core/state"
"github.com/ava-labs/coreth/params"

"github.com/ava-labs/avalanchego/chains/atomic"
Expand Down Expand Up @@ -369,7 +369,7 @@
}

// EVMStateTransfer executes the state update from the atomic export transaction
func (utx *UnsignedExportTx) EVMStateTransfer(ctx *snow.Context, state *state.StateDB) error {
func (utx *UnsignedExportTx) EVMStateTransfer(ctx *snow.Context, state vm.StateDB) error {
addrs := map[[20]byte]uint64{}
for _, from := range utx.Ins {
if from.AssetID == ctx.AVAXAssetID {
Expand All @@ -378,13 +378,17 @@
// denomination before export.
amount := new(big.Int).Mul(
new(big.Int).SetUint64(from.Amount), x2cRate)
addrBalance := state.GetBalance(from.Address)
log.Info("get address balance", "address", from.Address.String(), "balance", addrBalance.String(), "assetID", from.AssetID.String())
if state.GetBalance(from.Address).Cmp(amount) < 0 {
return errInsufficientFunds
}
state.SubBalance(from.Address, amount)
} else {
log.Debug("crosschain", "dest", utx.DestinationChain, "addr", from.Address, "amount", from.Amount, "assetID", from.AssetID)
amount := new(big.Int).SetUint64(from.Amount)
addrBalance := state.GetBalanceMultiCoin(from.Address, common.Hash(from.AssetID))
log.Info("get address balance multi coin", "address", from.Address.String(), "balance", addrBalance.String(), "assetID", from.AssetID.String())
if state.GetBalanceMultiCoin(from.Address, common.Hash(from.AssetID)).Cmp(amount) < 0 {
return errInsufficientFunds
}
Expand Down
4 changes: 2 additions & 2 deletions plugin/evm/import_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
"context"
"errors"
"fmt"
"github.com/ava-labs/coreth/core/vm"

Check failure on line 10 in plugin/evm/import_tx.go

View workflow job for this annotation

GitHub Actions / Lint

File is not `goimports`-ed (goimports)
"math/big"
"slices"

"github.com/ava-labs/coreth/core/state"
"github.com/ava-labs/coreth/params"

"github.com/ava-labs/avalanchego/chains/atomic"
Expand Down Expand Up @@ -428,7 +428,7 @@

// EVMStateTransfer performs the state transfer to increase the balances of
// accounts accordingly with the imported EVMOutputs
func (utx *UnsignedImportTx) EVMStateTransfer(ctx *snow.Context, state *state.StateDB) error {
func (utx *UnsignedImportTx) EVMStateTransfer(ctx *snow.Context, state vm.StateDB) error {
for _, to := range utx.Outs {
if to.AssetID == ctx.AVAXAssetID {
log.Debug("crosschain", "src", utx.SourceChain, "addr", to.Address, "amount", to.Amount, "assetID", "AVAX")
Expand Down
4 changes: 2 additions & 2 deletions plugin/evm/test_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package evm

import (
"github.com/ava-labs/coreth/core/vm"

Check failure on line 7 in plugin/evm/test_tx.go

View workflow job for this annotation

GitHub Actions / Lint

File is not `goimports`-ed (goimports)
"math/big"
"math/rand"

Expand All @@ -16,7 +17,6 @@
"github.com/ava-labs/avalanchego/snow"
"github.com/ava-labs/avalanchego/utils/set"
"github.com/ava-labs/avalanchego/utils/wrappers"
"github.com/ava-labs/coreth/core/state"
"github.com/ava-labs/coreth/params"
)

Expand Down Expand Up @@ -71,7 +71,7 @@
}

// EVMStateTransfer implements the UnsignedAtomicTx interface
func (t *TestUnsignedTx) EVMStateTransfer(ctx *snow.Context, state *state.StateDB) error {
func (t *TestUnsignedTx) EVMStateTransfer(ctx *snow.Context, state vm.StateDB) error {
return t.EVMStateTransferV
}

Expand Down
4 changes: 2 additions & 2 deletions plugin/evm/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import (
"bytes"
"errors"
"fmt"
"github.com/ava-labs/coreth/core/vm"
"math/big"
"sort"

"github.com/ethereum/go-ethereum/common"

"github.com/ava-labs/coreth/core/state"
"github.com/ava-labs/coreth/params"

"github.com/ava-labs/avalanchego/chains/atomic"
Expand Down Expand Up @@ -130,7 +130,7 @@ type UnsignedAtomicTx interface {
// The set of atomic requests must be returned in a consistent order.
AtomicOps() (ids.ID, *atomic.Requests, error)

EVMStateTransfer(ctx *snow.Context, state *state.StateDB) error
EVMStateTransfer(ctx *snow.Context, state vm.StateDB) error
}

// Tx is a signed transaction
Expand Down
Loading