aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDeterminant <[email protected]>2020-08-19 23:48:47 -0400
committerDeterminant <[email protected]>2020-08-19 23:48:47 -0400
commit2d409cb9790e55fd014546222f448786bbefa46b (patch)
tree4b6906f93b546f7911ac23bf3665c6fe823f2c5c
parentc6fbdb0dc9453bf4dbf43490d7d83b7a4de2f182 (diff)
...
-rw-r--r--plugin/evm/export_tx.go7
-rw-r--r--plugin/evm/factory.go8
-rw-r--r--plugin/evm/import_tx.go26
-rw-r--r--plugin/evm/vm.go33
4 files changed, 29 insertions, 45 deletions
diff --git a/plugin/evm/export_tx.go b/plugin/evm/export_tx.go
index 0314f0c..249b7cf 100644
--- a/plugin/evm/export_tx.go
+++ b/plugin/evm/export_tx.go
@@ -4,7 +4,6 @@
package evm
import (
- "errors"
"fmt"
"github.com/ava-labs/gecko/database"
@@ -17,12 +16,6 @@ import (
safemath "github.com/ava-labs/gecko/utils/math"
)
-var (
- errNoExportOutputs = errors.New("no export outputs")
- errOutputsNotSorted = errors.New("outputs not sorted")
- errOverflowExport = errors.New("overflow when computing export amount + txFee")
-)
-
// UnsignedExportTx is an unsigned ExportTx
type UnsignedExportTx struct {
avax.Metadata
diff --git a/plugin/evm/factory.go b/plugin/evm/factory.go
index ae2ea27..6ae62ae 100644
--- a/plugin/evm/factory.go
+++ b/plugin/evm/factory.go
@@ -14,16 +14,12 @@ var (
// Factory ...
type Factory struct {
- AVAX ids.ID
- AVM ids.ID
- Fee uint64
+ Fee uint64
}
// New ...
func (f *Factory) New() interface{} {
return &VM{
- avaxAssetID: f.AVAX,
- avm: f.AVM,
- txFee: f.Fee,
+ txFee: f.Fee,
}
}
diff --git a/plugin/evm/import_tx.go b/plugin/evm/import_tx.go
index d6e03dc..995e488 100644
--- a/plugin/evm/import_tx.go
+++ b/plugin/evm/import_tx.go
@@ -4,7 +4,6 @@
package evm
import (
- "errors"
"fmt"
"math/big"
@@ -13,26 +12,13 @@ import (
"github.com/ava-labs/gecko/database"
"github.com/ava-labs/gecko/ids"
"github.com/ava-labs/gecko/snow"
- crypto "github.com/ava-labs/gecko/utils/crypto"
+ "github.com/ava-labs/gecko/utils/crypto"
"github.com/ava-labs/gecko/utils/math"
"github.com/ava-labs/gecko/vms/components/avax"
"github.com/ava-labs/gecko/vms/secp256k1fx"
"github.com/ava-labs/go-ethereum/common"
)
-var (
- errAssetIDMismatch = errors.New("asset IDs in the input don't match the utxo")
- errWrongNumberOfCredentials = errors.New("should have the same number of credentials as inputs")
- errNoInputs = errors.New("tx has no inputs")
- errNoImportInputs = errors.New("tx has no imported inputs")
- errInputsNotSortedUnique = errors.New("inputs not sorted and unique")
- errPublicKeySignatureMismatch = errors.New("signature doesn't match public key")
- errUnknownAsset = errors.New("unknown asset ID")
- errNoFunds = errors.New("no spendable funds were found")
- errWrongChainID = errors.New("tx has wrong chain ID")
- errInsufficientFunds = errors.New("insufficient funds")
-)
-
// UnsignedImportTx is an unsigned ImportTx
type UnsignedImportTx struct {
avax.Metadata
@@ -109,16 +95,16 @@ func (tx *UnsignedImportTx) SemanticVerify(
vm *VM,
stx *Tx,
) TxError {
- if err := tx.Verify(vm.avm, vm.ctx, vm.txFee, vm.avaxAssetID); err != nil {
+ if err := tx.Verify(vm.ctx.XChainID, vm.ctx, vm.txFee, vm.ctx.AVAXAssetID); err != nil {
return permError{err}
}
// do flow-checking
fc := avax.NewFlowChecker()
- fc.Produce(vm.avaxAssetID, vm.txFee)
+ fc.Produce(vm.ctx.AVAXAssetID, vm.txFee)
for _, out := range tx.Outs {
- fc.Produce(vm.avaxAssetID, out.Amount)
+ fc.Produce(vm.ctx.AVAXAssetID, out.Amount)
}
for _, in := range tx.ImportedInputs {
@@ -168,7 +154,7 @@ func (vm *VM) newImportTx(
importedAmount := uint64(0)
now := vm.clock.Unix()
for _, utxo := range atomicUTXOs {
- if !utxo.AssetID().Equals(vm.avaxAssetID) {
+ if !utxo.AssetID().Equals(vm.ctx.AVAXAssetID) {
continue
}
inputIntf, utxoSigners, err := kc.Spend(utxo.Out, now)
@@ -219,7 +205,7 @@ func (vm *VM) newImportTx(
if err := tx.Sign(vm.codec, signers); err != nil {
return nil, err
}
- return tx, utx.Verify(vm.avm, vm.ctx, vm.txFee, vm.avaxAssetID)
+ return tx, utx.Verify(vm.ctx.XChainID, vm.ctx, vm.txFee, vm.ctx.AVAXAssetID)
}
func (tx *UnsignedImportTx) EVMStateTransfer(state *state.StateDB) {
diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go
index 292e383..53810ee 100644
--- a/plugin/evm/vm.go
+++ b/plugin/evm/vm.go
@@ -74,14 +74,27 @@ const (
)
var (
- errEmptyBlock = errors.New("empty block")
- errCreateBlock = errors.New("couldn't create block")
- errUnknownBlock = errors.New("unknown block")
- errBlockFrequency = errors.New("too frequent block issuance")
- errUnsupportedFXs = errors.New("unsupported feature extensions")
- errInvalidBlock = errors.New("invalid block")
- errInvalidAddr = errors.New("invalid hex address")
- errTooManyAtomicTx = errors.New("too many pending atomix txs")
+ errEmptyBlock = errors.New("empty block")
+ errCreateBlock = errors.New("couldn't create block")
+ errUnknownBlock = errors.New("unknown block")
+ errBlockFrequency = errors.New("too frequent block issuance")
+ errUnsupportedFXs = errors.New("unsupported feature extensions")
+ errInvalidBlock = errors.New("invalid block")
+ errInvalidAddr = errors.New("invalid hex address")
+ errTooManyAtomicTx = errors.New("too many pending atomix txs")
+ errAssetIDMismatch = errors.New("asset IDs in the input don't match the utxo")
+ errWrongNumberOfCredentials = errors.New("should have the same number of credentials as inputs")
+ errNoInputs = errors.New("tx has no inputs")
+ errNoImportInputs = errors.New("tx has no imported inputs")
+ errInputsNotSortedUnique = errors.New("inputs not sorted and unique")
+ errPublicKeySignatureMismatch = errors.New("signature doesn't match public key")
+ errUnknownAsset = errors.New("unknown asset ID")
+ errNoFunds = errors.New("no spendable funds were found")
+ errWrongChainID = errors.New("tx has wrong chain ID")
+ errInsufficientFunds = errors.New("insufficient funds")
+ errNoExportOutputs = errors.New("no export outputs")
+ errOutputsNotSorted = errors.New("outputs not sorted")
+ errOverflowExport = errors.New("overflow when computing export amount + txFee")
)
func maxDuration(x, y time.Duration) time.Duration {
@@ -146,8 +159,6 @@ type VM struct {
atomicTxSubmitChan chan struct{}
codec codec.Codec
clock timer.Clock
- avaxAssetID ids.ID
- avm ids.ID
txFee uint64
pendingAtomicTxs chan *Tx
blockAtomicInputCache cache.LRU
@@ -182,8 +193,6 @@ func (vm *VM) Initialize(
}
vm.ctx = ctx
- vm.avaxAssetID = ctx.AVAXAssetID
- vm.avm = ctx.XChainID
vm.chaindb = Database{db}
g := new(core.Genesis)
err := json.Unmarshal(b, g)