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

Data components and process components #5625

Merged
merged 8 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
94 changes: 94 additions & 0 deletions node/chainSimulator/dataComponents.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package chainSimulator

import (
"github.com/multiversx/mx-chain-core-go/data"
"github.com/multiversx/mx-chain-core-go/marshal"
"github.com/multiversx/mx-chain-go/dataRetriever"
"github.com/multiversx/mx-chain-go/dataRetriever/provider"
"github.com/multiversx/mx-chain-go/factory"
)

// ArgsDataComponentsHolder will hold the components needed for data components
type ArgsDataComponentsHolder struct {
Chain data.ChainHandler
StorageService dataRetriever.StorageService
DataPool dataRetriever.PoolsHolder
InternalMarshaller marshal.Marshalizer
}

type dataComponentsHolder struct {
chain data.ChainHandler
storageService dataRetriever.StorageService
dataPool dataRetriever.PoolsHolder
miniBlockProvider factory.MiniBlockProvider
}

// CreateDataComponentsHolder will create the data components holder
func CreateDataComponentsHolder(args ArgsDataComponentsHolder) (factory.DataComponentsHolder, error) {
miniBlockStorer, err := args.StorageService.GetStorer(dataRetriever.MiniBlockUnit)
if err != nil {
return nil, err
}

arg := provider.ArgMiniBlockProvider{
MiniBlockPool: args.DataPool.MiniBlocks(),
MiniBlockStorage: miniBlockStorer,
Marshalizer: args.InternalMarshaller,
}

miniBlocksProvider, err := provider.NewMiniBlockProvider(arg)
if err != nil {
return nil, err
}

instance := &dataComponentsHolder{
chain: args.Chain,
storageService: args.StorageService,
dataPool: args.DataPool,
miniBlockProvider: miniBlocksProvider,
}

return instance, nil
}

// Blockchain will return the blockchain handler
func (d *dataComponentsHolder) Blockchain() data.ChainHandler {
return d.chain
}

// SetBlockchain will set the blockchain handler
func (d *dataComponentsHolder) SetBlockchain(chain data.ChainHandler) error {
d.chain = chain

return nil
}

// StorageService will return the storage service
func (d *dataComponentsHolder) StorageService() dataRetriever.StorageService {
return d.storageService
}

// Datapool will return the data pool
func (d *dataComponentsHolder) Datapool() dataRetriever.PoolsHolder {
return d.dataPool
}

// MiniBlocksProvider will return the mini blocks provider
func (d *dataComponentsHolder) MiniBlocksProvider() factory.MiniBlockProvider {
return d.miniBlockProvider
}

// Clone will clone the data components holder
func (d *dataComponentsHolder) Clone() interface{} {
return &dataComponentsHolder{
chain: d.chain,
storageService: d.storageService,
dataPool: d.dataPool,
miniBlockProvider: d.miniBlockProvider,
}
}

// IsInterfaceNil returns true if there is no value under the interface
func (d *dataComponentsHolder) IsInterfaceNil() bool {
return d == nil
}