Skip to content

Commit

Permalink
Merge pull request #6153 from multiversx/feat/refactor-runtype-compon…
Browse files Browse the repository at this point in the history
…ents

Feat/refactor runtype components
  • Loading branch information
axenteoctavian committed May 16, 2024
2 parents 539ff94 + e9cfbac commit e17256f
Show file tree
Hide file tree
Showing 108 changed files with 3,570 additions and 1,830 deletions.
2 changes: 1 addition & 1 deletion cmd/sovereignnode/dataCodec/dataCodec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/stretchr/testify/require"
)

func createDataCodec() SovereignDataDecoder {
func createDataCodec() SovereignDataCodec {
codec := abi.NewDefaultCodec()
args := ArgsDataCodec{
Serializer: abi.NewSerializer(codec),
Expand Down
4 changes: 2 additions & 2 deletions cmd/sovereignnode/dataCodec/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ type OperationDataEncoder interface {
SerializeOperation(operation sovereign.Operation) ([]byte, error)
}

// SovereignDataDecoder is the interface for serializing/deserializing data
type SovereignDataDecoder interface {
// SovereignDataCodec is the interface for serializing/deserializing data
type SovereignDataCodec interface {
SerializeEventData(eventData sovereign.EventData) ([]byte, error)
DeserializeEventData(data []byte) (*sovereign.EventData, error)
SerializeTokenData(tokenData sovereign.EsdtTokenData) ([]byte, error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type eventsResult struct {
type incomingEventsProcessor struct {
marshaller marshal.Marshalizer
hasher hashing.Hasher
dataCodec dataCodec.SovereignDataDecoder
dataCodec dataCodec.SovereignDataCodec
topicsChecker TopicsChecker
}

Expand Down
8 changes: 4 additions & 4 deletions cmd/sovereignnode/incomingHeader/incomingHeaderProcessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package incomingHeader
import (
"encoding/hex"

sovereignBlock "github.com/multiversx/mx-chain-go/dataRetriever/dataPool/sovereign"
"github.com/multiversx/mx-chain-go/errors"
"github.com/multiversx/mx-chain-go/process"
"github.com/multiversx/mx-chain-go/process/block"
"github.com/multiversx/mx-chain-go/sovereignnode/dataCodec"

"github.com/multiversx/mx-chain-core-go/core"
Expand All @@ -22,12 +22,12 @@ var log = logger.GetOrCreate("headerSubscriber")
// ArgsIncomingHeaderProcessor is a struct placeholder for args needed to create a new incoming header processor
type ArgsIncomingHeaderProcessor struct {
HeadersPool HeadersPool
OutGoingOperationsPool block.OutGoingOperationsPool
OutGoingOperationsPool sovereignBlock.OutGoingOperationsPool
TxPool TransactionPool
Marshaller marshal.Marshalizer
Hasher hashing.Hasher
MainChainNotarizationStartRound uint64
DataCodec dataCodec.SovereignDataDecoder
DataCodec dataCodec.SovereignDataCodec
TopicsChecker TopicsChecker
}

Expand All @@ -36,7 +36,7 @@ type incomingHeaderProcessor struct {
extendedHeaderProc *extendedHeaderProcessor

txPool TransactionPool
outGoingPool block.OutGoingOperationsPool
outGoingPool sovereignBlock.OutGoingOperationsPool
mainChainNotarizationStartRound uint64
}

Expand Down
251 changes: 106 additions & 145 deletions cmd/sovereignnode/sovereignNodeRunner.go

Large diffs are not rendered by default.

39 changes: 39 additions & 0 deletions common/disabled/outGoingOperationPool.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package disabled

import (
"github.com/multiversx/mx-chain-core-go/data/sovereign"
)

type outGoingOperationsPool struct {
}

// NewDisabledOutGoingOperationPool -
func NewDisabledOutGoingOperationPool() *outGoingOperationsPool {
return &outGoingOperationsPool{}
}

// Add -
func (op *outGoingOperationsPool) Add(_ *sovereign.BridgeOutGoingData) {}

// Get -
func (op *outGoingOperationsPool) Get(_ []byte) *sovereign.BridgeOutGoingData {
return &sovereign.BridgeOutGoingData{}
}

// Delete -
func (op *outGoingOperationsPool) Delete(_ []byte) {}

// ConfirmOperation -
func (op *outGoingOperationsPool) ConfirmOperation(_ []byte, _ []byte) error {
return nil
}

// GetUnconfirmedOperations -
func (op *outGoingOperationsPool) GetUnconfirmedOperations() []*sovereign.BridgeOutGoingData {
return make([]*sovereign.BridgeOutGoingData, 0)
}

// IsInterfaceNil checks if the underlying pointer is nil
func (op *outGoingOperationsPool) IsInterfaceNil() bool {
return op == nil
}
24 changes: 24 additions & 0 deletions common/runType/runTypeComponentsHelper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package runType

import (
"github.com/multiversx/mx-chain-go/genesis"
"github.com/multiversx/mx-chain-go/genesis/data"

"github.com/multiversx/mx-chain-core-go/core"
)

// ReadInitialAccounts returns the genesis accounts from a file
func ReadInitialAccounts(filePath string) ([]genesis.InitialAccountHandler, error) {
initialAccounts := make([]*data.InitialAccount, 0)
err := core.LoadJsonFile(&initialAccounts, filePath)
if err != nil {
return nil, err
}

var accounts []genesis.InitialAccountHandler
for _, ia := range initialAccounts {
accounts = append(accounts, ia)
}

return accounts, nil
}
32 changes: 32 additions & 0 deletions common/runType/runTypeComponentsHelper_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package runType

import (
"math/big"
"testing"

"github.com/stretchr/testify/require"
)

func TestReadInitialAccounts(t *testing.T) {
t.Parallel()

t.Run("empty path should error", func(t *testing.T) {
accounts, err := ReadInitialAccounts("")
require.Nil(t, accounts)
require.Error(t, err)
})
t.Run("should work", func(t *testing.T) {
accounts, err := ReadInitialAccounts("../../genesis/process/testdata/genesisTest1.json")
require.Nil(t, err)
require.NotNil(t, accounts)
require.True(t, len(accounts) > 0)
require.Equal(t, "a00102030405060708090001020304050607080900010203040506070809000a", accounts[0].GetAddress())
require.Equal(t, "b00102030405060708090001020304050607080900010203040506070809000b", accounts[1].GetAddress())
require.Equal(t, "c00102030405060708090001020304050607080900010203040506070809000c", accounts[2].GetAddress())
require.Equal(t, big.NewInt(10000), accounts[2].GetSupply())
require.Equal(t, big.NewInt(0), accounts[2].GetBalanceValue())
require.Equal(t, big.NewInt(0), accounts[2].GetStakingValue())
require.Equal(t, "00000000000000000500f080f48551abf03e12e27e20d9f077abedffdccc0102", accounts[2].GetDelegationHandler().GetAddress())
require.Equal(t, big.NewInt(10000), accounts[2].GetDelegationHandler().GetValue())
})
}
14 changes: 12 additions & 2 deletions consensus/spos/bls/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package bls
import (
"context"

"github.com/multiversx/mx-chain-core-go/data"
"github.com/multiversx/mx-chain-core-go/data/sovereign"
"github.com/multiversx/mx-chain-go/consensus"
"github.com/multiversx/mx-chain-go/consensus/spos"

"github.com/multiversx/mx-chain-core-go/data"
"github.com/multiversx/mx-chain-core-go/data/sovereign"
)

// SubRoundStartExtraSignersHolder manages extra signers during start subround in a consensus process
Expand Down Expand Up @@ -60,3 +61,12 @@ type BridgeOperationsHandler interface {
Send(ctx context.Context, data *sovereign.BridgeOperations) (*sovereign.BridgeOperationsResponse, error)
IsInterfaceNil() bool
}

// OutGoingOperationsPool defines the behavior of a timed cache for outgoing operations
type OutGoingOperationsPool interface {
Add(data *sovereign.BridgeOutGoingData)
Get(hash []byte) *sovereign.BridgeOutGoingData
Delete(hash []byte)
GetUnconfirmedOperations() []*sovereign.BridgeOutGoingData
IsInterfaceNil() bool
}
10 changes: 5 additions & 5 deletions consensus/spos/bls/sovereignSubRoundEnd.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@ import (
"encoding/hex"
"fmt"

"github.com/multiversx/mx-chain-go/consensus/spos"
"github.com/multiversx/mx-chain-go/errors"

"github.com/multiversx/mx-chain-core-go/core/check"
"github.com/multiversx/mx-chain-core-go/data"
"github.com/multiversx/mx-chain-core-go/data/sovereign"
"github.com/multiversx/mx-chain-go/consensus/spos"
"github.com/multiversx/mx-chain-go/errors"
"github.com/multiversx/mx-chain-go/process/block"
)

type sovereignSubRoundEnd struct {
*subroundEndRoundV2
outGoingOperationsPool block.OutGoingOperationsPool
outGoingOperationsPool OutGoingOperationsPool
bridgeOpHandler BridgeOperationsHandler
}

// NewSovereignSubRoundEndRound creates a new sovereign end subround
func NewSovereignSubRoundEndRound(
subRoundEnd *subroundEndRoundV2,
outGoingOperationsPool block.OutGoingOperationsPool,
outGoingOperationsPool OutGoingOperationsPool,
bridgeOpHandler BridgeOperationsHandler,
) (*sovereignSubRoundEnd, error) {
if check.IfNil(subRoundEnd) {
Expand Down
6 changes: 3 additions & 3 deletions consensus/spos/bls/sovereignSubRoundEndCreator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ package bls

import (
"github.com/multiversx/mx-chain-core-go/core/check"

"github.com/multiversx/mx-chain-go/consensus/spos"
"github.com/multiversx/mx-chain-go/errors"
"github.com/multiversx/mx-chain-go/process/block"
)

type sovereignSubRoundEndCreator struct {
outGoingOperationsPool block.OutGoingOperationsPool
outGoingOperationsPool OutGoingOperationsPool
bridgeOpHandler BridgeOperationsHandler
}

// NewSovereignSubRoundEndCreator creates a new sovereign subround end factory
func NewSovereignSubRoundEndCreator(
outGoingOperationsPool block.OutGoingOperationsPool,
outGoingOperationsPool OutGoingOperationsPool,
bridgeOpHandler BridgeOperationsHandler,
) (*sovereignSubRoundEndCreator, error) {
if check.IfNil(outGoingOperationsPool) {
Expand Down
13 changes: 7 additions & 6 deletions consensus/spos/bls/sovereignSubRoundEnd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@ import (
"testing"
"time"

"github.com/multiversx/mx-chain-core-go/data"
"github.com/multiversx/mx-chain-core-go/data/block"
sovCore "github.com/multiversx/mx-chain-core-go/data/sovereign"
"github.com/multiversx/mx-chain-go/consensus"
"github.com/multiversx/mx-chain-go/consensus/mock"
"github.com/multiversx/mx-chain-go/consensus/spos"
"github.com/multiversx/mx-chain-go/consensus/spos/bls"
sovereignBlock "github.com/multiversx/mx-chain-go/dataRetriever/dataPool/sovereign"
"github.com/multiversx/mx-chain-go/errors"
sovBlock "github.com/multiversx/mx-chain-go/process/block"
"github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock"
"github.com/multiversx/mx-chain-go/testscommon/sovereign"
"github.com/multiversx/mx-chain-go/testscommon/statusHandler"

"github.com/multiversx/mx-chain-core-go/data"
"github.com/multiversx/mx-chain-core-go/data/block"
sovCore "github.com/multiversx/mx-chain-core-go/data/sovereign"
"github.com/stretchr/testify/require"
)

Expand All @@ -27,7 +28,7 @@ type sovEndRoundHandler interface {
}

func createSovSubRoundEndWithSelfLeader(
pool sovBlock.OutGoingOperationsPool,
pool sovereignBlock.OutGoingOperationsPool,
bridgeHandler bls.BridgeOperationsHandler,
header data.HeaderHandler,
) sovEndRoundHandler {
Expand All @@ -45,7 +46,7 @@ func createSovSubRoundEndWithSelfLeader(
}

func createSovSubRoundEndWithParticipant(
pool sovBlock.OutGoingOperationsPool,
pool sovereignBlock.OutGoingOperationsPool,
bridgeHandler bls.BridgeOperationsHandler,
header data.HeaderHandler,
) sovEndRoundHandler {
Expand Down
15 changes: 15 additions & 0 deletions dataRetriever/dataPool/sovereign/interface.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package sovereign

import (
sovereignCore "github.com/multiversx/mx-chain-core-go/data/sovereign"
)

// OutGoingOperationsPool defines the behavior of a timed cache for outgoing operations
type OutGoingOperationsPool interface {
Add(data *sovereignCore.BridgeOutGoingData)
Get(hash []byte) *sovereignCore.BridgeOutGoingData
Delete(hash []byte)
GetUnconfirmedOperations() []*sovereignCore.BridgeOutGoingData
ConfirmOperation(hashOfHashes []byte, hash []byte) error
IsInterfaceNil() bool
}
17 changes: 12 additions & 5 deletions epochStart/bootstrap/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package bootstrap
import (
"fmt"

"github.com/multiversx/mx-chain-core-go/core/check"
"github.com/multiversx/mx-chain-go/common/statistics"
"github.com/multiversx/mx-chain-go/epochStart"
"github.com/multiversx/mx-chain-go/errors"
"github.com/multiversx/mx-chain-go/sharding/nodesCoordinator"

"github.com/multiversx/mx-chain-core-go/core/check"
)

const baseErrorMessage = "error with epoch start bootstrapper arguments"
Expand Down Expand Up @@ -124,15 +125,21 @@ func checkArguments(args ArgsEpochStartBootstrap) error {
if check.IfNil(args.NodesCoordinatorRegistryFactory) {
return fmt.Errorf("%s: %w", baseErrorMessage, nodesCoordinator.ErrNilNodesCoordinatorRegistryFactory)
}
if check.IfNil(args.NodesCoordinatorWithRaterFactory) {
return fmt.Errorf("%s: %w", baseErrorMessage, errors.ErrNilNodesCoordinatorFactory)
if check.IfNil(args.RunTypeComponents) {
return fmt.Errorf("%s: %w", baseErrorMessage, errors.ErrNilRunTypeComponents)
}
if check.IfNil(args.ShardCoordinatorFactory) {
if check.IfNil(args.RunTypeComponents.ShardCoordinatorCreator()) {
return fmt.Errorf("%s: %w", baseErrorMessage, errors.ErrNilShardCoordinatorFactory)
}
if check.IfNil(args.AdditionalStorageServiceCreator) {
if check.IfNil(args.RunTypeComponents.AdditionalStorageServiceCreator()) {
return fmt.Errorf("%s: %w", baseErrorMessage, errors.ErrNilAdditionalStorageServiceCreator)
}
if check.IfNil(args.RunTypeComponents.NodesCoordinatorWithRaterCreator()) {
return fmt.Errorf("%s: %w", baseErrorMessage, errors.ErrNilNodesCoordinatorFactory)
}
if check.IfNil(args.RunTypeComponents.RequestHandlerCreator()) {
return fmt.Errorf("%s: %w", baseErrorMessage, errors.ErrNilRequestHandlerCreator)
}

return nil
}
21 changes: 10 additions & 11 deletions epochStart/bootstrap/epochStartBootstrapperFactory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,12 @@ package bootstrap
import (
"testing"

"github.com/multiversx/mx-chain-core-go/core"
"github.com/multiversx/mx-chain-core-go/core/versioning"
"github.com/multiversx/mx-chain-core-go/data"
"github.com/multiversx/mx-chain-core-go/data/block"
"github.com/multiversx/mx-chain-go/common/statistics/disabled"
"github.com/multiversx/mx-chain-go/config"
"github.com/multiversx/mx-chain-go/epochStart/bootstrap/types"
"github.com/multiversx/mx-chain-go/epochStart/mock"
processMocks "github.com/multiversx/mx-chain-go/process/mock"
"github.com/multiversx/mx-chain-go/sharding"
"github.com/multiversx/mx-chain-go/sharding/nodesCoordinator"
"github.com/multiversx/mx-chain-go/testscommon"
"github.com/multiversx/mx-chain-go/testscommon/cryptoMocks"
"github.com/multiversx/mx-chain-go/testscommon/economicsmocks"
Expand All @@ -26,6 +22,11 @@ import (
"github.com/multiversx/mx-chain-go/testscommon/shardingMocks"
statusHandlerMock "github.com/multiversx/mx-chain-go/testscommon/statusHandler"
storageMocks "github.com/multiversx/mx-chain-go/testscommon/storage"

"github.com/multiversx/mx-chain-core-go/core"
"github.com/multiversx/mx-chain-core-go/core/versioning"
"github.com/multiversx/mx-chain-core-go/data"
"github.com/multiversx/mx-chain-core-go/data/block"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -215,11 +216,9 @@ func getDefaultArgs() ArgsEpochStartBootstrap {
FlagsConfig: config.ContextFlagsConfig{
ForceStartFromNetwork: false,
},
TrieSyncStatisticsProvider: &testscommon.SizeSyncStatisticsHandlerStub{},
AdditionalStorageServiceCreator: &testscommon.AdditionalStorageServiceFactoryMock{},
NodesCoordinatorWithRaterFactory: nodesCoordinator.NewIndexHashedNodesCoordinatorWithRaterFactory(),
ShardCoordinatorFactory: sharding.NewMultiShardCoordinatorFactory(),
StateStatsHandler: disabled.NewStateStatistics(),
NodesCoordinatorRegistryFactory: &shardingMocks.NodesCoordinatorRegistryFactoryMock{},
TrieSyncStatisticsProvider: &testscommon.SizeSyncStatisticsHandlerStub{},
RunTypeComponents: processMocks.NewRunTypeComponentsStub(),
StateStatsHandler: disabled.NewStateStatistics(),
NodesCoordinatorRegistryFactory: &shardingMocks.NodesCoordinatorRegistryFactoryMock{},
}
}

0 comments on commit e17256f

Please sign in to comment.