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

Deep VM Queries (for older epochs, as well) #5801

Merged
merged 22 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
a189c1d
Sandbox for vm queries.
andreibancioiu Jan 4, 2024
92323bf
Recreate trie from epoch.
andreibancioiu Jan 4, 2024
94f6572
Fix epoch.
andreibancioiu Jan 4, 2024
94a2d47
- fixes
iulianpascalau Feb 6, 2024
6865acb
Merge branch 'master' into sandbox-queries
andreibancioiu Feb 6, 2024
f31383f
- more fixes
iulianpascalau Feb 6, 2024
26621d2
Merge remote-tracking branch 'origin/sandbox-queries' into sandbox-qu…
iulianpascalau Feb 6, 2024
a6b9d47
Add integration test for deep queries.
andreibancioiu Feb 8, 2024
2574f71
Merge pull request #5935 from multiversx/deep-query-test-01
iulianpascalau Feb 9, 2024
50937b8
Attempt fix for deep queries on metachain.
andreibancioiu Feb 13, 2024
0630e26
Fix after review.
andreibancioiu Feb 13, 2024
2e255a3
Undo changed within one node network.
andreibancioiu Feb 13, 2024
dc797c7
Merge branch 'rc/v1.6.next1' into sandbox-queries
gabi-vuls Feb 13, 2024
20eab64
Add integration test.
andreibancioiu Feb 13, 2024
752b58a
Add unit test.
andreibancioiu Feb 13, 2024
7eac8b7
Add some comments.
andreibancioiu Feb 13, 2024
8019dec
Merge pull request #5958 from multiversx/deep-query-metachain
iulianpascalau Feb 14, 2024
83f496b
Merge branch 'rc/v1.6.next1' into sandbox-queries
iulianpascalau Feb 14, 2024
54869fa
Merge branch 'rc/v1.6.next1' into sandbox-queries
iulianpascalau Feb 14, 2024
5a3ec4d
- fixed linter issues
iulianpascalau Feb 14, 2024
d7339ec
Merge branch 'rc/v1.6.next1' into sandbox-queries
gabi-vuls Feb 14, 2024
624413b
Merge branch 'rc/v1.6.next1' into sandbox-queries
iulianpascalau Feb 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
71 changes: 28 additions & 43 deletions factory/api/apiResolverFactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@
list := make([]process.SCQueryService, 0, numConcurrentVms)
for i := 0; i < numConcurrentVms; i++ {
argsQueryElem.index = i
scQueryService, err = createScQueryElement(argsQueryElem)
scQueryService, err = createScQueryElement(*argsQueryElem)
if err != nil {
return nil, err
}
Expand All @@ -339,7 +339,7 @@
}

func createScQueryElement(
args *scQueryElementArgs,
args scQueryElementArgs,
) (process.SCQueryService, error) {
var err error

Expand All @@ -356,10 +356,20 @@
return nil, errDecode
}

apiBlockchain, err := blockchain.NewBlockChain(disabled.NewAppStatusHandler())
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we should handle metachain, as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in #5958.

if err != nil {
return nil, err

Check warning on line 361 in factory/api/apiResolverFactory.go

View check run for this annotation

Codecov / codecov/patch

factory/api/apiResolverFactory.go#L361

Added line #L361 was not covered by tests
}

accountsAdapterApi, err := createNewAccountsAdapterApi(args, apiBlockchain)
if err != nil {
return nil, err
}

builtInFuncFactory, err := createBuiltinFuncs(
args.gasScheduleNotifier,
args.coreComponents.InternalMarshalizer(),
args.stateComponents.AccountsAdapterAPI(),
accountsAdapterApi,
args.processComponents.ShardCoordinator(),
args.coreComponents.EpochNotifier(),
args.coreComponents.EnableEpochsHandler(),
Expand Down Expand Up @@ -399,16 +409,17 @@
GasSchedule: args.gasScheduleNotifier,
Counter: counters.NewDisabledCounter(),
MissingTrieNodesNotifier: syncer.NewMissingTrieNodesNotifier(),
Accounts: accountsAdapterApi,
BlockChain: apiBlockchain,
}

var apiBlockchain data.ChainHandler
var vmFactory process.VirtualMachinesContainerFactory
maxGasForVmQueries := args.generalConfig.VirtualMachine.GasConfig.ShardMaxGasPerVmQuery
if args.processComponents.ShardCoordinator().SelfId() == core.MetachainShardId {
maxGasForVmQueries = args.generalConfig.VirtualMachine.GasConfig.MetaMaxGasPerVmQuery
apiBlockchain, vmFactory, err = createMetaVmContainerFactory(args, argsHook)
vmFactory, err = createMetaVmContainerFactory(args, argsHook)

Check warning on line 420 in factory/api/apiResolverFactory.go

View check run for this annotation

Codecov / codecov/patch

factory/api/apiResolverFactory.go#L420

Added line #L420 was not covered by tests
} else {
apiBlockchain, vmFactory, err = createShardVmContainerFactory(args, argsHook)
vmFactory, err = createShardVmContainerFactory(args, argsHook)
}
if err != nil {
return nil, err
Expand Down Expand Up @@ -452,23 +463,10 @@
return smartContract.NewSCQueryService(argsNewSCQueryService)
}

func createMetaVmContainerFactory(args *scQueryElementArgs, argsHook hooks.ArgBlockChainHook) (data.ChainHandler, process.VirtualMachinesContainerFactory, error) {
apiBlockchain, err := blockchain.NewMetaChain(disabled.NewAppStatusHandler())
if err != nil {
return nil, nil, err
}

accountsAdapterApi, err := createNewAccountsAdapterApi(args, apiBlockchain)
if err != nil {
return nil, nil, err
}

argsHook.BlockChain = apiBlockchain
argsHook.Accounts = accountsAdapterApi

func createMetaVmContainerFactory(args scQueryElementArgs, argsHook hooks.ArgBlockChainHook) (process.VirtualMachinesContainerFactory, error) {

Check warning on line 466 in factory/api/apiResolverFactory.go

View check run for this annotation

Codecov / codecov/patch

factory/api/apiResolverFactory.go#L466

Added line #L466 was not covered by tests
blockChainHookImpl, errBlockChainHook := hooks.NewBlockChainHookImpl(argsHook)
if errBlockChainHook != nil {
return nil, nil, errBlockChainHook
return nil, errBlockChainHook

Check warning on line 469 in factory/api/apiResolverFactory.go

View check run for this annotation

Codecov / codecov/patch

factory/api/apiResolverFactory.go#L469

Added line #L469 was not covered by tests
}

argsNewVmFactory := metachain.ArgsNewVMContainerFactory{
Expand All @@ -489,35 +487,22 @@
}
vmFactory, err := metachain.NewVMContainerFactory(argsNewVmFactory)
if err != nil {
return nil, nil, err
return nil, err

Check warning on line 490 in factory/api/apiResolverFactory.go

View check run for this annotation

Codecov / codecov/patch

factory/api/apiResolverFactory.go#L490

Added line #L490 was not covered by tests
}

return apiBlockchain, vmFactory, nil
return vmFactory, nil

Check warning on line 493 in factory/api/apiResolverFactory.go

View check run for this annotation

Codecov / codecov/patch

factory/api/apiResolverFactory.go#L493

Added line #L493 was not covered by tests
}

func createShardVmContainerFactory(args *scQueryElementArgs, argsHook hooks.ArgBlockChainHook) (data.ChainHandler, process.VirtualMachinesContainerFactory, error) {
apiBlockchain, err := blockchain.NewBlockChain(disabled.NewAppStatusHandler())
if err != nil {
return nil, nil, err
}

accountsAdapterApi, err := createNewAccountsAdapterApi(args, apiBlockchain)
if err != nil {
return nil, nil, err
}

argsHook.BlockChain = apiBlockchain
argsHook.Accounts = accountsAdapterApi

func createShardVmContainerFactory(args scQueryElementArgs, argsHook hooks.ArgBlockChainHook) (process.VirtualMachinesContainerFactory, error) {
queryVirtualMachineConfig := args.generalConfig.VirtualMachine.Querying.VirtualMachineConfig
esdtTransferParser, errParser := parsers.NewESDTTransferParser(args.coreComponents.InternalMarshalizer())
if errParser != nil {
return nil, nil, errParser
return nil, errParser
}

blockChainHookImpl, errBlockChainHook := hooks.NewBlockChainHookImpl(argsHook)
if errBlockChainHook != nil {
return nil, nil, errBlockChainHook
return nil, errBlockChainHook

Check warning on line 505 in factory/api/apiResolverFactory.go

View check run for this annotation

Codecov / codecov/patch

factory/api/apiResolverFactory.go#L505

Added line #L505 was not covered by tests
}

argsNewVMFactory := shard.ArgVMContainerFactory{
Expand All @@ -539,13 +524,13 @@

vmFactory, err := shard.NewVMContainerFactory(argsNewVMFactory)
if err != nil {
return nil, nil, err
return nil, err
}

return apiBlockchain, vmFactory, nil
return vmFactory, nil
}

func createNewAccountsAdapterApi(args *scQueryElementArgs, chainHandler data.ChainHandler) (state.AccountsAdapterAPI, error) {
func createNewAccountsAdapterApi(args scQueryElementArgs, chainHandler data.ChainHandler) (state.AccountsAdapterAPI, error) {
argsAccCreator := factoryState.ArgsAccountCreator{
Hasher: args.coreComponents.Hasher(),
Marshaller: args.coreComponents.InternalMarshalizer(),
Expand Down Expand Up @@ -622,7 +607,7 @@
return state.NewAccountsDBApi(accounts, provider)
}

func newStoragePruningManager(args *scQueryElementArgs) (state.StoragePruningManager, error) {
func newStoragePruningManager(args scQueryElementArgs) (state.StoragePruningManager, error) {
argsMemEviction := evictionWaitingList.MemoryEvictionWaitingListArgs{
RootHashesSize: args.generalConfig.EvictionWaitingList.RootHashesSize,
HashesSize: args.generalConfig.EvictionWaitingList.HashesSize,
Expand Down
2 changes: 1 addition & 1 deletion factory/api/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type SCQueryElementArgs struct {

// CreateScQueryElement -
func CreateScQueryElement(args SCQueryElementArgs) (process.SCQueryService, error) {
return createScQueryElement(&scQueryElementArgs{
return createScQueryElement(scQueryElementArgs{
generalConfig: args.GeneralConfig,
epochConfig: args.EpochConfig,
coreComponents: args.CoreComponents,
Expand Down
23 changes: 12 additions & 11 deletions integrationTests/oneNodeNetwork.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@ import (
"github.com/multiversx/mx-chain-go/process"
)

type oneNodeNetwork struct {
// OneNodeNetwork is a one-node network, useful for some integration tests
type OneNodeNetwork struct {
Round uint64
Nonce uint64

Node *TestProcessorNode
}

// NewOneNodeNetwork creates a one-node network, useful for some integration tests
func NewOneNodeNetwork() *oneNodeNetwork {
n := &oneNodeNetwork{}
// NewOneNodeNetwork creates a OneNodeNetwork
func NewOneNodeNetwork() *OneNodeNetwork {
n := &OneNodeNetwork{}

nodes := CreateNodes(
1,
Expand All @@ -31,38 +32,38 @@ func NewOneNodeNetwork() *oneNodeNetwork {
}

// Stop stops the test network
func (n *oneNodeNetwork) Stop() {
func (n *OneNodeNetwork) Stop() {
n.Node.Close()
}

// Mint mints the given address
func (n *oneNodeNetwork) Mint(address []byte, value *big.Int) {
func (n *OneNodeNetwork) Mint(address []byte, value *big.Int) {
MintAddress(n.Node.AccntState, address, value)
}

// GetMinGasPrice returns the min gas price
func (n *oneNodeNetwork) GetMinGasPrice() uint64 {
func (n *OneNodeNetwork) GetMinGasPrice() uint64 {
return n.Node.EconomicsData.GetMinGasPrice()
}

// MaxGasLimitPerBlock returns the max gas per block
func (n *oneNodeNetwork) MaxGasLimitPerBlock() uint64 {
func (n *OneNodeNetwork) MaxGasLimitPerBlock() uint64 {
return n.Node.EconomicsData.MaxGasLimitPerBlock(0) - 1
}

// GoToRoundOne advances processing to block and round 1
func (n *oneNodeNetwork) GoToRoundOne() {
func (n *OneNodeNetwork) GoToRoundOne() {
n.Round = IncrementAndPrintRound(n.Round)
n.Nonce++
}

// Continue advances processing with a number of rounds
func (n *oneNodeNetwork) Continue(t *testing.T, numRounds int) {
func (n *OneNodeNetwork) Continue(t *testing.T, numRounds int) {
n.Nonce, n.Round = WaitOperationToBeDone(t, []*TestProcessorNode{n.Node}, numRounds, n.Nonce, n.Round, []int{0})
}

// AddTxToPool adds a transaction to the pool (skips signature checks and interceptors)
func (n *oneNodeNetwork) AddTxToPool(tx *transaction.Transaction) {
func (n *OneNodeNetwork) AddTxToPool(tx *transaction.Transaction) {
txHash, _ := core.CalculateHash(TestMarshalizer, TestHasher, tx)
sourceShard := n.Node.ShardCoordinator.ComputeId(tx.SndAddr)
cacheIdentifier := process.ShardCacherIdentifier(sourceShard, sourceShard)
Expand Down