Skip to content

Commit

Permalink
Merge pull request #465 from ElrondNetwork/EN-3934/integrate-arwen-vm…
Browse files Browse the repository at this point in the history
…-and-tests

Arwen WASM VM integration.
  • Loading branch information
sasurobert authored Sep 25, 2019
2 parents d9649a0 + 2f52ce8 commit cc06262
Show file tree
Hide file tree
Showing 22 changed files with 440 additions and 132 deletions.
29 changes: 14 additions & 15 deletions cmd/node/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,11 @@ import (
"github.com/ElrondNetwork/elrond-go/node"
"github.com/ElrondNetwork/elrond-go/node/external"
"github.com/ElrondNetwork/elrond-go/ntp"
factoryVM "github.com/ElrondNetwork/elrond-go/process/factory"
"github.com/ElrondNetwork/elrond-go/process/factory/shard"
"github.com/ElrondNetwork/elrond-go/process/smartContract"
"github.com/ElrondNetwork/elrond-go/process/smartContract/hooks"
"github.com/ElrondNetwork/elrond-go/sharding"
"github.com/ElrondNetwork/elrond-go/statusHandler"
factoryViews "github.com/ElrondNetwork/elrond-go/statusHandler/factory"
vmcommon "github.com/ElrondNetwork/elrond-vm-common"
"github.com/ElrondNetwork/elrond-vm/iele/elrond/node/endpoint"
"github.com/google/gops/agent"
"github.com/urfave/cli"
)
Expand Down Expand Up @@ -639,19 +636,15 @@ func startNode(ctx *cli.Context, log *logger.Logger, version string) error {
return err
}

vmAccountsDB, err := hooks.NewVMAccountsDB(
apiResolver, err := createApiResolver(
stateComponents.AccountsAdapter,
stateComponents.AddressConverter,
statusMetrics,
)
if err != nil {
return err
}

apiResolver, err := createApiResolver(vmAccountsDB, statusMetrics)
if err != nil {
return err
}

err = startStatusPolling(
currentNode.GetAppStatusHandler(),
generalConfig.GeneralSettings.StatusPollingIntervalSec,
Expand Down Expand Up @@ -1212,12 +1205,18 @@ func startStatisticsMonitor(file *os.File, config config.ResourceStatsConfig, lo
return nil
}

func createApiResolver(vmAccountsDB vmcommon.BlockchainHook, statusMetrics external.StatusMetricsHandler) (facade.ApiResolver, error) {
//TODO replace this with a vm factory
cryptoHook := hooks.NewVMCryptoHook()
ieleVM := endpoint.NewElrondIeleVM(factoryVM.IELEVirtualMachine, endpoint.ElrondTestnet, vmAccountsDB, cryptoHook)
func createApiResolver(accounts state.AccountsAdapter, converter state.AddressConverter, statusMetrics external.StatusMetricsHandler) (facade.ApiResolver, error) {
vmFactory, err := shard.NewVMContainerFactory(accounts, converter)
if err != nil {
return nil, err
}

vmContainer, err := vmFactory.Create()
if err != nil {
return nil, err
}

scDataGetter, err := smartContract.NewSCDataGetter(ieleVM)
scDataGetter, err := smartContract.NewSCDataGetter(vmContainer)
if err != nil {
return nil, err
}
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.12

require (
github.com/360EntSecGroup-Skylar/excelize v1.4.1
github.com/ElrondNetwork/arwen-wasm-vm v0.0.8
github.com/ElrondNetwork/concurrent-map v0.1.2
github.com/ElrondNetwork/elrond-vm v0.0.19
github.com/ElrondNetwork/elrond-vm-common v0.0.8
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9 h1:HD8gA2tkBy
github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8=
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/ElrondNetwork/arwen-wasm-vm v0.0.8 h1:Va5y2E3SD+SF+cOWxTpT6MJYNmrd+LE1qUs8VdEzXvU=
github.com/ElrondNetwork/arwen-wasm-vm v0.0.8/go.mod h1:uGYpcjg8Oa3tkdS7Yc9sHUgEIPSnmHoDFdodgiZ0iyU=
github.com/ElrondNetwork/concurrent-map v0.1.2 h1:mr2sVF2IPDsJO8DNGzCUiNQOJcadHuIRVZn+QFnCBlE=
github.com/ElrondNetwork/concurrent-map v0.1.2/go.mod h1:3XwSwn4JHI0lrKxWLZvtp53Emr8BXYTmNQGwcukHJEE=
github.com/ElrondNetwork/elrond-vm v0.0.19 h1:9E8spYj9K1DHdF0Osgj1dZUJfKhfBiLBx1xWWfE/HAM=
Expand All @@ -16,6 +18,8 @@ github.com/ElrondNetwork/elrond-vm-common v0.0.7/go.mod h1:VqCCN0cX0e4D/KDc7MGNV
github.com/ElrondNetwork/elrond-vm-common v0.0.8 h1:YyJ55gYeCL3e2v+06ZLJrwzkOXPvuSvLm7pBL1qD0Rk=
github.com/ElrondNetwork/elrond-vm-common v0.0.8/go.mod h1:VqCCN0cX0e4D/KDc7MGNV9ElrOsfnjuJnGvcODVjzbk=
github.com/ElrondNetwork/elrond-vm-util v0.0.3/go.mod h1:/gz1QHx7ndQnjQDAEEhpiiaezbyl/woTI6apOsWrN10=
github.com/ElrondNetwork/go-ext-wasm v0.0.0-20190923181727-2aed5e4238f5 h1:XUFbny/dhk55M2RCLTrwCFjcUUwufPvrejxN3The5Sg=
github.com/ElrondNetwork/go-ext-wasm v0.0.0-20190923181727-2aed5e4238f5/go.mod h1:+OQYLOaYAxbnkA5WWbiya03JsQng7wg8jKwlJNyQb68=
github.com/Kubuxu/go-os-helper v0.0.1/go.mod h1:N8B+I7vPCT80IcP58r50u4+gEEcsZETFUpAzWW2ep1Y=
github.com/StackExchange/wmi v0.0.0-20170410192909-ea383cf3ba6e h1:IHXQQIpxASe3m0Jtcd3XongL+lxHNd5nUmvHxJARUmg=
github.com/StackExchange/wmi v0.0.0-20170410192909-ea383cf3ba6e/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
Expand Down Expand Up @@ -476,8 +480,6 @@ golang.org/x/crypto v0.0.0-20190225124518-7f87c0fbb88b/go.mod h1:6SG95UA2DQfeDnf
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5 h1:58fnuSXlxZmFdJyvtTFVmVhcMLU6v5fEb/ok4wyqtNU=
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190618222545-ea8f1a30c443 h1:IcSOAf4PyMp3U3XbIEj1/xJ2BjNN2jWv7JoyOsMxXUU=
golang.org/x/crypto v0.0.0-20190618222545-ea8f1a30c443/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472 h1:Gv7RPwsi3eZ2Fgewe3CBsuOebPwO27PoXzRpJPsvSSM=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"time"

"github.com/ElrondNetwork/elrond-go/integrationTests"
"github.com/ElrondNetwork/elrond-go/process/factory"
"github.com/ElrondNetwork/elrond-go/sharding"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -39,7 +40,6 @@ func TestProcessWithScTxsTopUpAndWithdrawOnlyProposers(t *testing.T) {
nodeShard0 := integrationTests.NewTestProcessorNode(maxShards, 0, 0, advertiserAddr)
nodeShard1 := integrationTests.NewTestProcessorNode(maxShards, 1, 1, advertiserAddr)
hardCodedSk, _ := hex.DecodeString("5561d28b0d89fa425bbbf9e49a018b5d1e4a462c03d2efce60faf9ddece2af06")
hardCodedScResultingAddress, _ := hex.DecodeString("000000000000000001006c560111a94e434413c1cdaafbc3e1348947d1d5b3a1")
nodeShard1.LoadTxSignSkBytes(hardCodedSk)
nodeMeta := integrationTests.NewTestProcessorNode(maxShards, sharding.MetachainShardId, 0, advertiserAddr)

Expand Down Expand Up @@ -73,6 +73,11 @@ func TestProcessWithScTxsTopUpAndWithdrawOnlyProposers(t *testing.T) {
withdrawValue := big.NewInt(10)
integrationTests.MintAllNodes(nodes, initialVal)

hardCodedScResultingAddress, _ := nodeShard1.BlockchainHook.NewAddress(
nodes[idxNodeShard1].OwnAccount.Address.Bytes(),
nodes[idxNodeShard1].OwnAccount.Nonce,
factory.IELEVirtualMachine,
)
integrationTests.DeployScTx(nodes, idxNodeShard1, string(scCode))

integrationTests.ProposeBlock(nodes, idxProposers, round, nonce)
Expand Down
14 changes: 6 additions & 8 deletions integrationTests/testInitializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,13 @@ import (
"github.com/ElrondNetwork/elrond-go/p2p/loadBalancer"
"github.com/ElrondNetwork/elrond-go/process"
procFactory "github.com/ElrondNetwork/elrond-go/process/factory"
"github.com/ElrondNetwork/elrond-go/process/factory/shard"
"github.com/ElrondNetwork/elrond-go/process/smartContract/hooks"
txProc "github.com/ElrondNetwork/elrond-go/process/transaction"
"github.com/ElrondNetwork/elrond-go/sharding"
"github.com/ElrondNetwork/elrond-go/storage"
"github.com/ElrondNetwork/elrond-go/storage/memorydb"
"github.com/ElrondNetwork/elrond-go/storage/storageUnit"
vmcommon "github.com/ElrondNetwork/elrond-vm-common"
"github.com/ElrondNetwork/elrond-vm/iele/elrond/node/endpoint"
"github.com/btcsuite/btcd/btcec"
libp2pCrypto "github.com/libp2p/go-libp2p-core/crypto"
"github.com/pkg/errors"
Expand Down Expand Up @@ -278,14 +277,13 @@ func CreateGenesisMetaBlock() *dataBlock.MetaBlock {
}

// CreateIeleVMAndBlockchainHook creates a new instance of a iele VM
func CreateIeleVMAndBlockchainHook(
func CreateVMContainerAndBlockchainHook(
accnts state.AccountsAdapter,
) (vmcommon.VMExecutionHandler, *hooks.VMAccountsDB) {
blockChainHook, _ := hooks.NewVMAccountsDB(accnts, TestAddressConverter)
cryptoHook := hooks.NewVMCryptoHook()
vm := endpoint.NewElrondIeleVM(procFactory.IELEVirtualMachine, endpoint.ElrondTestnet, blockChainHook, cryptoHook)
) (process.VirtualMachinesContainer, *hooks.VMAccountsDB) {
vmFactory, _ := shard.NewVMContainerFactory(accnts, TestAddressConverter)
vmContainer, _ := vmFactory.Create()

return vm, blockChainHook
return vmContainer, vmFactory.VMAccountsDB()
}

// CreateAddressFromAddrBytes creates an address container object from address bytes provided
Expand Down
20 changes: 7 additions & 13 deletions integrationTests/testProcessorNode.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import (
"github.com/ElrondNetwork/elrond-go/process/smartContract/hooks"
"github.com/ElrondNetwork/elrond-go/process/transaction"
"github.com/ElrondNetwork/elrond-go/sharding"
vmcommon "github.com/ElrondNetwork/elrond-vm-common"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -81,9 +80,9 @@ type TestProcessorNode struct {
TxProcessor process.TransactionProcessor
TxCoordinator process.TransactionCoordinator
ScrForwarder process.IntermediateTransactionHandler
VmProcessor vmcommon.VMExecutionHandler
VmDataGetter vmcommon.VMExecutionHandler
BlockchainHook vmcommon.BlockchainHook
VmProcessors process.VirtualMachinesContainer
VmDataGetter process.VirtualMachinesContainer
BlockchainHook *hooks.VMAccountsDB
ArgsParser process.ArgumentsParser
ScProcessor process.SmartContractProcessor
PreProcessorsContainer process.PreProcessorsContainer
Expand Down Expand Up @@ -295,22 +294,17 @@ func (tpn *TestProcessorNode) initInnerProcessors() {
tpn.InterimProcContainer, _ = interimProcFactory.Create()
tpn.ScrForwarder, _ = tpn.InterimProcContainer.Get(dataBlock.SmartContractResultBlock)

tpn.VmProcessor, tpn.BlockchainHook = CreateIeleVMAndBlockchainHook(tpn.AccntState)
tpn.VmDataGetter, _ = CreateIeleVMAndBlockchainHook(tpn.AccntState)

vmContainer := &mock.VMContainerMock{
GetCalled: func(key []byte) (handler vmcommon.VMExecutionHandler, e error) {
return tpn.VmProcessor, nil
}}
tpn.VmProcessors, tpn.BlockchainHook = CreateVMContainerAndBlockchainHook(tpn.AccntState)
tpn.VmDataGetter, _ = CreateVMContainerAndBlockchainHook(tpn.AccntState)

tpn.ArgsParser, _ = smartContract.NewAtArgumentParser()
tpn.ScProcessor, _ = smartContract.NewSmartContractProcessor(
vmContainer,
tpn.VmProcessors,
tpn.ArgsParser,
TestHasher,
TestMarshalizer,
tpn.AccntState,
tpn.BlockchainHook.(*hooks.VMAccountsDB),
tpn.BlockchainHook,
TestAddressConverter,
tpn.ShardCoordinator,
tpn.ScrForwarder,
Expand Down
Loading

0 comments on commit cc06262

Please sign in to comment.