diff options
Diffstat (limited to 'plugin')
-rw-r--r-- | plugin/evm/block.go | 4 | ||||
-rw-r--r-- | plugin/evm/database.go | 2 | ||||
-rw-r--r-- | plugin/evm/export_tx.go | 24 | ||||
-rw-r--r-- | plugin/evm/export_tx_test.go | 2 | ||||
-rw-r--r-- | plugin/evm/factory.go | 6 | ||||
-rw-r--r-- | plugin/evm/import_tx.go | 26 | ||||
-rw-r--r-- | plugin/evm/import_tx_test.go | 22 | ||||
-rw-r--r-- | plugin/evm/service.go | 2 | ||||
-rw-r--r-- | plugin/evm/tx.go | 8 | ||||
-rw-r--r-- | plugin/evm/user.go | 7 | ||||
-rw-r--r-- | plugin/evm/vm.go | 61 | ||||
-rw-r--r-- | plugin/evm/vm_test.go | 24 |
12 files changed, 77 insertions, 111 deletions
diff --git a/plugin/evm/block.go b/plugin/evm/block.go index 77a85b3..7c23c17 100644 --- a/plugin/evm/block.go +++ b/plugin/evm/block.go @@ -34,7 +34,7 @@ func (b *Block) Accept() error { log.Trace(fmt.Sprintf("Block %s is accepted", b.ID())) vm.updateStatus(b.id, choices.Accepted) - if err := vm.acceptedDB.Put(b.ethBlock.Number().Bytes(), b.id.Bytes()); err != nil { + if err := vm.acceptedDB.Put(b.ethBlock.Number().Bytes(), b.id[:]); err != nil { return err } @@ -68,7 +68,7 @@ func (b *Block) Status() choices.Status { // Parent implements the snowman.Block interface func (b *Block) Parent() snowman.Block { - parentID := ids.NewID(b.ethBlock.ParentHash()) + parentID := ids.ID(b.ethBlock.ParentHash()) if block := b.vm.getBlock(parentID); block != nil { return block } diff --git a/plugin/evm/database.go b/plugin/evm/database.go index 18890fa..fff18cb 100644 --- a/plugin/evm/database.go +++ b/plugin/evm/database.go @@ -53,7 +53,7 @@ func (db Database) NewIterator(prefix []byte, start []byte) ethdb.Iterator { // NewIteratorWithStart implements ethdb.Database func (db Database) NewIteratorWithStart(start []byte) ethdb.Iterator { - return db.NewIteratorWithStart(start) + return db.Database.NewIteratorWithStart(start) } // Batch implements ethdb.Batch diff --git a/plugin/evm/export_tx.go b/plugin/evm/export_tx.go index d099eb2..0778d0a 100644 --- a/plugin/evm/export_tx.go +++ b/plugin/evm/export_tx.go @@ -17,6 +17,7 @@ import ( safemath "github.com/ava-labs/avalanchego/utils/math" "github.com/ava-labs/avalanchego/vms/components/avax" "github.com/ava-labs/avalanchego/vms/secp256k1fx" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/log" ) @@ -52,15 +53,15 @@ func (tx *UnsignedExportTx) Verify( return errNilTx case tx.syntacticallyVerified: // already passed syntactic verification return nil - case tx.DestinationChain.IsZero(): + case tx.DestinationChain == ids.Empty: return errWrongChainID - case !tx.DestinationChain.Equals(avmID): + case tx.DestinationChain != avmID: return errWrongChainID case len(tx.ExportedOutputs) == 0: return errNoExportOutputs case tx.NetworkID != ctx.NetworkID: return errWrongNetworkID - case !ctx.ChainID.Equals(tx.BlockchainID): + case ctx.ChainID != tx.BlockchainID: return errWrongBlockchainID } @@ -154,9 +155,9 @@ func (tx *UnsignedExportTx) Accept(ctx *snow.Context, _ database.Batch) error { if err != nil { return err } - + utxoID := utxo.InputID() elem := &atomic.Element{ - Key: utxo.InputID().Bytes(), + Key: utxoID[:], Value: utxoBytes, } if out, ok := utxo.Out.(avax.Addressable); ok { @@ -177,13 +178,13 @@ func (vm *VM) newExportTx( to ids.ShortID, // Address of chain recipient keys []*crypto.PrivateKeySECP256K1R, // Pay the fee and provide the tokens ) (*Tx, error) { - if !vm.ctx.XChainID.Equals(chainID) { + if vm.ctx.XChainID != chainID { return nil, errWrongChainID } var toBurn uint64 var err error - if assetID.Equals(vm.ctx.AVAXAssetID) { + if assetID == vm.ctx.AVAXAssetID { toBurn, err = safemath.Add64(amount, vm.txFee) if err != nil { return nil, errOverflowExport @@ -198,7 +199,7 @@ func (vm *VM) newExportTx( } // burn non-AVAX - if !assetID.Equals(vm.ctx.AVAXAssetID) { + if assetID != vm.ctx.AVAXAssetID { ins2, signers2, err := vm.GetSpendableFunds(keys, assetID, amount) if err != nil { return nil, fmt.Errorf("couldn't generate tx inputs/outputs: %w", err) @@ -242,7 +243,7 @@ func (tx *UnsignedExportTx) EVMStateTransfer(vm *VM, state *state.StateDB) error addrs := map[[20]byte]uint64{} for _, from := range tx.Ins { log.Info("crosschain C->X", "addr", from.Address, "amount", from.Amount) - if from.AssetID.Equals(vm.ctx.AVAXAssetID) { + if from.AssetID == vm.ctx.AVAXAssetID { amount := new(big.Int).Mul( new(big.Int).SetUint64(from.Amount), x2cRate) if state.GetBalance(from.Address).Cmp(amount) < 0 { @@ -251,11 +252,10 @@ func (tx *UnsignedExportTx) EVMStateTransfer(vm *VM, state *state.StateDB) error state.SubBalance(from.Address, amount) } else { amount := new(big.Int).SetUint64(from.Amount) - assetID := from.AssetID.Key() - if state.GetBalanceMultiCoin(from.Address, assetID).Cmp(amount) < 0 { + if state.GetBalanceMultiCoin(from.Address, common.Hash(from.AssetID)).Cmp(amount) < 0 { return errInsufficientFunds } - state.SubBalanceMultiCoin(from.Address, assetID, amount) + state.SubBalanceMultiCoin(from.Address, common.Hash(from.AssetID), amount) } if state.GetNonce(from.Address) != from.Nonce { return errInvalidNonce diff --git a/plugin/evm/export_tx_test.go b/plugin/evm/export_tx_test.go index 319c6dd..6fdf3a2 100644 --- a/plugin/evm/export_tx_test.go +++ b/plugin/evm/export_tx_test.go @@ -76,7 +76,7 @@ func TestExportTxVerify(t *testing.T) { // Test Valid Export Tx if err := exportTx.Verify(testXChainID, ctx, testTxFee, testAvaxAssetID); err != nil { - t.Fatalf("Failed to verify valid ExportTx: %w", err) + t.Fatalf("Failed to verify valid ExportTx: %s", err) } exportTx.syntacticallyVerified = false diff --git a/plugin/evm/factory.go b/plugin/evm/factory.go index 593d85b..b977117 100644 --- a/plugin/evm/factory.go +++ b/plugin/evm/factory.go @@ -3,13 +3,11 @@ package evm -import ( - "github.com/ava-labs/avalanchego/ids" -) +import "github.com/ava-labs/avalanchego/ids" // ID this VM should be referenced by var ( - ID = ids.NewID([32]byte{'e', 'v', 'm'}) + ID = ids.ID([32]byte{'e', 'v', 'm'}) ) // Factory ... diff --git a/plugin/evm/import_tx.go b/plugin/evm/import_tx.go index ae6b540..2ce8f6f 100644 --- a/plugin/evm/import_tx.go +++ b/plugin/evm/import_tx.go @@ -58,15 +58,15 @@ func (tx *UnsignedImportTx) Verify( return errNilTx case tx.syntacticallyVerified: // already passed syntactic verification return nil - case tx.SourceChain.IsZero(): + case tx.SourceChain == ids.Empty: return errWrongChainID - case !tx.SourceChain.Equals(avmID): + case tx.SourceChain != avmID: return errWrongChainID case len(tx.ImportedInputs) == 0: return errNoImportInputs case tx.NetworkID != ctx.NetworkID: return errWrongNetworkID - case !ctx.ChainID.Equals(tx.BlockchainID): + case ctx.ChainID != tx.BlockchainID: return errWrongBlockchainID } @@ -124,7 +124,8 @@ func (tx *UnsignedImportTx) SemanticVerify( utxoIDs := make([][]byte, len(tx.ImportedInputs)) for i, in := range tx.ImportedInputs { - utxoIDs[i] = in.UTXOID.InputID().Bytes() + inputID := in.UTXOID.InputID() + utxoIDs[i] = inputID[:] } // allUTXOBytes is guaranteed to be the same length as utxoIDs allUTXOBytes, err := vm.ctx.SharedMemory.Get(tx.SourceChain, utxoIDs) @@ -144,7 +145,7 @@ func (tx *UnsignedImportTx) SemanticVerify( utxoAssetID := utxo.AssetID() inAssetID := in.AssetID() - if !utxoAssetID.Equals(inAssetID) { + if utxoAssetID != inAssetID { return permError{errAssetIDMismatch} } @@ -164,7 +165,8 @@ func (tx *UnsignedImportTx) Accept(ctx *snow.Context, _ database.Batch) error { // TODO: Is any batch passed in here? utxoIDs := make([][]byte, len(tx.ImportedInputs)) for i, in := range tx.ImportedInputs { - utxoIDs[i] = in.InputID().Bytes() + inputID := in.InputID() + utxoIDs[i] = inputID[:] } return ctx.SharedMemory.Remove(tx.SourceChain, utxoIDs) } @@ -175,7 +177,7 @@ func (vm *VM) newImportTx( to common.Address, // Address of recipient keys []*crypto.PrivateKeySECP256K1R, // Keys to import the funds ) (*Tx, error) { - if !vm.ctx.XChainID.Equals(chainID) { + if vm.ctx.XChainID != chainID { return nil, errWrongChainID } @@ -204,8 +206,7 @@ func (vm *VM) newImportTx( continue } aid := utxo.AssetID() - aidKey := aid.Key() - importedAmount[aidKey], err = math.Add64(importedAmount[aidKey], input.Amount()) + importedAmount[aid], err = math.Add64(importedAmount[aid], input.Amount()) if err != nil { return nil, err } @@ -238,8 +239,7 @@ func (vm *VM) newImportTx( // This will create unique outputs (in the context of sorting) // since each output will have a unique assetID - for assetKey, amount := range importedAmount { - assetID := ids.NewID(assetKey) + for assetID, amount := range importedAmount { //if assetID.Equals(vm.ctx.AVAXAssetID) || amount == 0 { if amount == 0 { continue @@ -273,13 +273,13 @@ func (vm *VM) newImportTx( func (tx *UnsignedImportTx) EVMStateTransfer(vm *VM, state *state.StateDB) error { for _, to := range tx.Outs { log.Info("crosschain X->C", "addr", to.Address, "amount", to.Amount) - if to.AssetID.Equals(vm.ctx.AVAXAssetID) { + if to.AssetID == vm.ctx.AVAXAssetID { amount := new(big.Int).Mul( new(big.Int).SetUint64(to.Amount), x2cRate) state.AddBalance(to.Address, amount) } else { amount := new(big.Int).SetUint64(to.Amount) - state.AddBalanceMultiCoin(to.Address, to.AssetID.Key(), amount) + state.AddBalanceMultiCoin(to.Address, common.Hash(to.AssetID), amount) } } return nil diff --git a/plugin/evm/import_tx_test.go b/plugin/evm/import_tx_test.go index fcd18ac..b0f2875 100644 --- a/plugin/evm/import_tx_test.go +++ b/plugin/evm/import_tx_test.go @@ -22,7 +22,7 @@ func TestImportTxVerifyNil(t *testing.T) { func TestImportTxVerify(t *testing.T) { var importAmount uint64 = 10000000 - txID := ids.NewID([32]byte{0xff}) + txID := [32]byte{0xff} importTx := &UnsignedImportTx{ NetworkID: testNetworkID, BlockchainID: testCChainID, @@ -77,7 +77,7 @@ func TestImportTxVerify(t *testing.T) { // Test Valid ImportTx if err := importTx.Verify(testXChainID, ctx, testTxFee, testAvaxAssetID); err != nil { - t.Fatalf("Failed to verify ImportTx: %w", err) + t.Fatalf("Failed to verify ImportTx: %s", err) } importTx.syntacticallyVerified = false @@ -134,12 +134,12 @@ func TestImportTxSemanticVerify(t *testing.T) { importAmount := uint64(1000000) utxoID := avax.UTXOID{ - TxID: ids.NewID([32]byte{ + TxID: [32]byte{ 0x0f, 0x2f, 0x4f, 0x6f, 0x8e, 0xae, 0xce, 0xee, 0x0d, 0x2d, 0x4d, 0x6d, 0x8c, 0xac, 0xcc, 0xec, 0x0b, 0x2b, 0x4b, 0x6b, 0x8a, 0xaa, 0xca, 0xea, 0x09, 0x29, 0x49, 0x69, 0x88, 0xa8, 0xc8, 0xe8, - }), + }, } utxo := &avax.UTXO{ @@ -203,9 +203,9 @@ func TestImportTxSemanticVerify(t *testing.T) { if err := unsignedImportTx.SemanticVerify(vm, tx); err != nil { t.Fatal("Should have failed to import non-existent UTXO") } - + inputID := utxo.InputID() if err := xChainSharedMemory.Put(vm.ctx.ChainID, []*atomic.Element{{ - Key: utxo.InputID().Bytes(), + Key: inputID[:], Value: utxoBytes, Traits: [][]byte{ testKeys[0].PublicKey().Address().Bytes(), @@ -268,7 +268,7 @@ func TestImportTxSemanticVerify(t *testing.T) { } if err := unsignedImportTx.Accept(vm.ctx, nil); err != nil { - t.Fatalf("Accept failed due to: %w", err) + t.Fatalf("Accept failed due to: %s", err) } if err := unsignedImportTx.EVMStateTransfer(vm, state); err != nil { @@ -293,12 +293,12 @@ func TestNewImportTx(t *testing.T) { importAmount := uint64(1000000) utxoID := avax.UTXOID{ - TxID: ids.NewID([32]byte{ + TxID: [32]byte{ 0x0f, 0x2f, 0x4f, 0x6f, 0x8e, 0xae, 0xce, 0xee, 0x0d, 0x2d, 0x4d, 0x6d, 0x8c, 0xac, 0xcc, 0xec, 0x0b, 0x2b, 0x4b, 0x6b, 0x8a, 0xaa, 0xca, 0xea, 0x09, 0x29, 0x49, 0x69, 0x88, 0xa8, 0xc8, 0xe8, - }), + }, } utxo := &avax.UTXO{ @@ -318,9 +318,9 @@ func TestNewImportTx(t *testing.T) { } xChainSharedMemory := sharedMemory.NewSharedMemory(vm.ctx.XChainID) - + inputID := utxo.InputID() if err := xChainSharedMemory.Put(vm.ctx.ChainID, []*atomic.Element{{ - Key: utxo.InputID().Bytes(), + Key: inputID[:], Value: utxoBytes, Traits: [][]byte{ testKeys[0].PublicKey().Address().Bytes(), diff --git a/plugin/evm/service.go b/plugin/evm/service.go index a934941..0ec7620 100644 --- a/plugin/evm/service.go +++ b/plugin/evm/service.go @@ -244,7 +244,7 @@ type ExportArgs struct { // It must be imported on the X-Chain to complete the transfer func (service *AvaxAPI) Export(_ *http.Request, args *ExportArgs, response *api.JSONTxID) error { log.Info("EVM: Export called") - if args.AssetID.IsZero() { + if args.AssetID == ids.Empty { return fmt.Errorf("assetID is required") } diff --git a/plugin/evm/tx.go b/plugin/evm/tx.go index 7c2ebf1..e44eefe 100644 --- a/plugin/evm/tx.go +++ b/plugin/evm/tx.go @@ -23,10 +23,6 @@ import ( "github.com/ethereum/go-ethereum/common" ) -// Max size of memo field -// Don't change without also changing avm.maxMemoSize -const maxMemoSize = 256 - var ( errWrongBlockchainID = errors.New("wrong blockchain ID provided") errWrongNetworkID = errors.New("tx was issued with a different network ID") @@ -134,7 +130,7 @@ func (ins *innerSortInputsAndSigners) Less(i, j int) bool { if addrComp != 0 { return addrComp < 0 } - return bytes.Compare(ins.inputs[i].AssetID.Bytes(), ins.inputs[j].AssetID.Bytes()) < 0 + return bytes.Compare(ins.inputs[i].AssetID[:], ins.inputs[j].AssetID[:]) < 0 } func (ins *innerSortInputsAndSigners) Len() int { return len(ins.inputs) } @@ -165,7 +161,7 @@ func (outs *innerSortEVMOutputs) Less(i, j int) bool { if addrComp != 0 { return addrComp < 0 } - return bytes.Compare(outs.outputs[i].AssetID.Bytes(), outs.outputs[j].AssetID.Bytes()) < 0 + return bytes.Compare(outs.outputs[i].AssetID[:], outs.outputs[j].AssetID[:]) < 0 } func (outs *innerSortEVMOutputs) Len() int { return len(outs.outputs) } diff --git a/plugin/evm/user.go b/plugin/evm/user.go index b751634..0ab1863 100644 --- a/plugin/evm/user.go +++ b/plugin/evm/user.go @@ -15,12 +15,11 @@ import ( // Key in the database whose corresponding value is the list of // addresses this user controls -var addressesKey = ids.Empty.Bytes() +var addressesKey = ids.Empty[:] var ( - errDBNil = errors.New("db uninitialized") - errKeyNil = errors.New("key uninitialized") - errEmptyAddress = errors.New("address is empty") + errDBNil = errors.New("db uninitialized") + errKeyNil = errors.New("key uninitialized") ) type user struct { diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index c902f85..53dc349 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -57,10 +57,6 @@ import ( ) var ( - zeroAddr = common.Address{ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - } x2cRate = big.NewInt(1000000000) ) @@ -83,10 +79,6 @@ const ( bdTimerStateLong ) -const ( - addressSep = "-" -) - var ( txFee = units.MilliAvax @@ -99,21 +91,14 @@ var ( errInvalidAddr = errors.New("invalid hex address") errTooManyAtomicTx = errors.New("too many pending atomic 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") errSignatureInputsMismatch = errors.New("number of inputs does not match number of signatures") - 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("tx has no export outputs") errOutputsNotSorted = errors.New("tx outputs not sorted") - errNoImportOutputs = errors.New("tx has no outputs to import") - errNoExportInputs = errors.New("tx has no inputs to export") - errInputsNotSortedAndUnique = errors.New("inputs not sorted and unique") errOverflowExport = errors.New("overflow when computing export amount + txFee") errInvalidNonce = errors.New("invalid nonce") ) @@ -309,7 +294,7 @@ func (vm *VM) Initialize( log.Trace("EVM sealed a block") blk := &Block{ - id: ids.NewID(block.Hash()), + id: ids.ID(block.Hash()), ethBlock: block, vm: vm, } @@ -318,7 +303,7 @@ func (vm *VM) Initialize( return errInvalidBlock } vm.newBlockChan <- blk - vm.updateStatus(ids.NewID(block.Hash()), choices.Processing) + vm.updateStatus(ids.ID(block.Hash()), choices.Processing) vm.txPoolStabilizedLock.Lock() vm.txPoolStabilizedHead = block.Hash() vm.txPoolStabilizedLock.Unlock() @@ -385,7 +370,7 @@ func (vm *VM) Initialize( lastAccepted = chain.GetGenesisBlock() } vm.lastAccepted = &Block{ - id: ids.NewID(lastAccepted.Hash()), + id: ids.ID(lastAccepted.Hash()), ethBlock: lastAccepted, vm: vm, } @@ -437,7 +422,7 @@ func (vm *VM) BuildBlock() (snowman.Block, error) { vm.blockDelayTimer.SetTimeoutIn(minBlockTime) vm.bdlock.Unlock() - log.Debug(fmt.Sprintf("built block 0x%x", block.ID().Bytes())) + log.Debug(fmt.Sprintf("built block %s", block.ID())) // make sure Tx Pool is updated <-vm.txPoolStabilizedOk return block, nil @@ -457,12 +442,12 @@ func (vm *VM) ParseBlock(b []byte) (snowman.Block, error) { } blockHash := ethBlock.Hash() // Coinbase must be zero on C-Chain - if bytes.Compare(blockHash.Bytes(), vm.genesisHash.Bytes()) != 0 && - bytes.Compare(ethBlock.Coinbase().Bytes(), coreth.BlackholeAddr.Bytes()) != 0 { + if !bytes.Equal(blockHash.Bytes(), vm.genesisHash.Bytes()) && + !bytes.Equal(ethBlock.Coinbase().Bytes(), coreth.BlackholeAddr.Bytes()) { return nil, errInvalidBlock } block := &Block{ - id: ids.NewID(blockHash), + id: ids.ID(blockHash), ethBlock: ethBlock, vm: vm, } @@ -484,7 +469,7 @@ func (vm *VM) GetBlock(id ids.ID) (snowman.Block, error) { // SetPreference sets what the current tail of the chain is func (vm *VM) SetPreference(blkID ids.ID) { - err := vm.chain.SetTail(blkID.Key()) + err := vm.chain.SetTail(common.Hash(blkID)) vm.ctx.Log.AssertNoError(err) } @@ -634,7 +619,7 @@ func (vm *VM) getCachedStatus(blockID ids.ID) choices.Status { if acceptedID, err := ids.ToID(acceptedIDBytes); err != nil { log.Error(fmt.Sprintf("snowman-eth: acceptedID bytes didn't match expected value: %s", err)) } else { - if acceptedID.Equals(blockID) { + if acceptedID == blockID { vm.blockStatusCache.Put(blockID, choices.Accepted) return choices.Accepted } @@ -645,14 +630,14 @@ func (vm *VM) getCachedStatus(blockID ids.ID) choices.Status { status := vm.getUncachedStatus(blk) if status == choices.Accepted { - err := vm.acceptedDB.Put(heightKey, blockID.Bytes()) + err := vm.acceptedDB.Put(heightKey, blockID[:]) if err != nil { log.Error(fmt.Sprintf("snowman-eth: failed to write back acceptedID bytes: %s", err)) } tempBlock := wrappedBlk for tempBlock.ethBlock != nil { - parentID := ids.NewID(tempBlock.ethBlock.ParentHash()) + parentID := ids.ID(tempBlock.ethBlock.ParentHash()) tempBlock = vm.getBlock(parentID) if tempBlock == nil || tempBlock.ethBlock == nil { break @@ -664,7 +649,7 @@ func (vm *VM) getCachedStatus(blockID ids.ID) choices.Status { break } - if err := vm.acceptedDB.Put(heightKey, parentID.Bytes()); err != nil { + if err := vm.acceptedDB.Put(heightKey, parentID[:]); err != nil { log.Error(fmt.Sprintf("snowman-eth: failed to write back acceptedID bytes: %s", err)) } } @@ -685,7 +670,7 @@ func (vm *VM) getUncachedStatus(blk *types.Block) choices.Status { highBlock, lowBlock = lowBlock, highBlock } for highBlock.Number().Cmp(lowBlock.Number()) > 0 { - parentBlock := vm.getBlock(ids.NewID(highBlock.ParentHash())) + parentBlock := vm.getBlock(ids.ID(highBlock.ParentHash())) if parentBlock == nil { return choices.Processing } @@ -706,12 +691,12 @@ func (vm *VM) getBlock(id ids.ID) *Block { if blockIntf, ok := vm.blockCache.Get(id); ok { return blockIntf.(*Block) } - ethBlock := vm.chain.GetBlockByHash(id.Key()) + ethBlock := vm.chain.GetBlockByHash(common.Hash(id)) if ethBlock == nil { return nil } block := &Block{ - id: ids.NewID(ethBlock.Hash()), + id: ids.ID(ethBlock.Hash()), ethBlock: ethBlock, vm: vm, } @@ -719,16 +704,6 @@ func (vm *VM) getBlock(id ids.ID) *Block { return block } -func (vm *VM) issueRemoteTxs(txs []*types.Transaction) error { - errs := vm.chain.AddRemoteTxs(txs) - for _, err := range errs { - if err != nil { - return err - } - } - return vm.tryBlockGen() -} - func (vm *VM) writeBackMetadata() { vm.metalock.Lock() defer vm.metalock.Unlock() @@ -855,7 +830,7 @@ func (vm *VM) GetAtomicUTXOs( chainID, addrsList, startAddr.Bytes(), - startUTXOID.Bytes(), + startUTXOID[:], limit, ) if err != nil { @@ -902,10 +877,10 @@ func (vm *VM) GetSpendableFunds(keys []*crypto.PrivateKeySECP256K1R, assetID ids } addr := GetEthAddress(key) var balance uint64 - if assetID.Equals(vm.ctx.AVAXAssetID) { + if assetID == vm.ctx.AVAXAssetID { balance = new(big.Int).Div(state.GetBalance(addr), x2cRate).Uint64() } else { - balance = state.GetBalanceMultiCoin(addr, assetID.Key()).Uint64() + balance = state.GetBalanceMultiCoin(addr, common.Hash(assetID)).Uint64() } if balance == 0 { continue diff --git a/plugin/evm/vm_test.go b/plugin/evm/vm_test.go index 8ce7825..d58fdda 100644 --- a/plugin/evm/vm_test.go +++ b/plugin/evm/vm_test.go @@ -23,18 +23,16 @@ import ( var ( testNetworkID uint32 = 10 - testCChainID = ids.NewID([32]byte{'c', 'c', 'h', 'a', 'i', 'n', 't', 'e', 's', 't'}) - testXChainID = ids.NewID([32]byte{'t', 'e', 's', 't', 'x'}) - nonExistentID = ids.NewID([32]byte{'F'}) + testCChainID = ids.ID([32]byte{'c', 'c', 'h', 'a', 'i', 'n', 't', 'e', 's', 't'}) + testXChainID = ids.ID([32]byte{'t', 'e', 's', 't', 'x'}) + nonExistentID = ids.ID([32]byte{'F'}) testTxFee = uint64(1000) - startBalance = uint64(50000) testKeys []*crypto.PrivateKeySECP256K1R testEthAddrs []common.Address // testEthAddrs[i] corresponds to testKeys[i] testShortIDAddrs []ids.ShortID - testAvaxAssetID = ids.NewID([32]byte{1, 2, 3}) - username = "Johns" - password = "CjasdjhiPeirbSenfeI13" // #nosec G101 - ethChainID uint32 = 43112 + testAvaxAssetID = [32]byte{1, 2, 3} + username = "Johns" + password = "CjasdjhiPeirbSenfeI13" // #nosec G101 ) func init() { @@ -63,7 +61,7 @@ func BuildGenesisTest(t *testing.T) []byte { genesis := &core.Genesis{} if err := json.Unmarshal([]byte(genesisJSON), genesis); err != nil { - t.Fatalf("Problem unmarshaling genesis JSON: %w", err) + t.Fatalf("Problem unmarshaling genesis JSON: %s", err) } genesisReply, err := ss.BuildGenesis(nil, genesis) if err != nil { @@ -79,10 +77,10 @@ func NewContext() *snow.Context { ctx.AVAXAssetID = testAvaxAssetID ctx.XChainID = ids.Empty.Prefix(0) aliaser := ctx.BCLookup.(*ids.Aliaser) - aliaser.Alias(testCChainID, "C") - aliaser.Alias(testCChainID, testCChainID.String()) - aliaser.Alias(testXChainID, "X") - aliaser.Alias(testXChainID, testXChainID.String()) + _ = aliaser.Alias(testCChainID, "C") + _ = aliaser.Alias(testCChainID, testCChainID.String()) + _ = aliaser.Alias(testXChainID, "X") + _ = aliaser.Alias(testXChainID, testXChainID.String()) // SNLookup might be required here??? return ctx |