Skip to content

Commit

Permalink
Merge branch 'feat/chain-go-sdk' into MX-16271-indexing-incoming-tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
axenteoctavian authored Feb 7, 2025
2 parents 723364c + 1b50045 commit 7fe8b76
Show file tree
Hide file tree
Showing 58 changed files with 592 additions and 478 deletions.
2 changes: 1 addition & 1 deletion cmd/sovereignnode/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ go 1.20

require (
github.com/google/gops v0.3.18
github.com/multiversx/mx-chain-core-go v1.2.25-0.20250131122047-725dd68e256f
github.com/multiversx/mx-chain-core-go v1.2.25-0.20250206111825-25fbb1b4851c
github.com/multiversx/mx-chain-go v1.8.4
github.com/multiversx/mx-chain-logger-go v1.0.15
github.com/multiversx/mx-chain-sovereign-bridge-go v0.0.0-20240116102202-4cf6fbbd95a3
Expand Down
4 changes: 2 additions & 2 deletions cmd/sovereignnode/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,8 @@ github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUY
github.com/multiversx/concurrent-map v0.1.4/go.mod h1:8cWFRJDOrWHOTNSqgYCUvwT7c7eFQ4U2vKMOp4A/9+o=
github.com/multiversx/mx-chain-communication-go v1.1.1 h1:y4DoQeQOJTaSUsRzczQFazf8JYQmInddypApqA3AkwM=
github.com/multiversx/mx-chain-communication-go v1.1.1/go.mod h1:WK6bP4pGEHGDDna/AYRIMtl6G9OA0NByI1Lw8PmOnRM=
github.com/multiversx/mx-chain-core-go v1.2.25-0.20250131122047-725dd68e256f h1:iyDk0Zk0n4pHZnrdX30SxevTy+xg9GcEyAmBss45Nfs=
github.com/multiversx/mx-chain-core-go v1.2.25-0.20250131122047-725dd68e256f/go.mod h1:P/YBoFnt25XUaCQ7Q/SD15vhnc9yV5JDhHxyFO9P8Z0=
github.com/multiversx/mx-chain-core-go v1.2.25-0.20250206111825-25fbb1b4851c h1:Cz5b0xd9lbSWGIwmfuPuHqL0e5kTun/PW5NpkVRIAXQ=
github.com/multiversx/mx-chain-core-go v1.2.25-0.20250206111825-25fbb1b4851c/go.mod h1:P/YBoFnt25XUaCQ7Q/SD15vhnc9yV5JDhHxyFO9P8Z0=
github.com/multiversx/mx-chain-crypto-go v1.2.12 h1:zWip7rpUS4CGthJxfKn5MZfMfYPjVjIiCID6uX5BSOk=
github.com/multiversx/mx-chain-crypto-go v1.2.12/go.mod h1:HzcPpCm1zanNct/6h2rIh+MFrlXbjA5C8+uMyXj3LI4=
github.com/multiversx/mx-chain-es-indexer-go v1.7.15-0.20250131125841-73868f5ca49c h1:Qm84hhybDLTeS+BLebFYgmGJpkX+AUnzZsUC+u9KzBU=
Expand Down
15 changes: 2 additions & 13 deletions epochStart/bootstrap/sovereignEpochStartBootstrapperFactory.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
package bootstrap

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

// sovereignEpochStartBootstrapperFactory defines the epoch start bootstrapper factory for chain run sovereign
type sovereignEpochStartBootstrapperFactory struct {
epochStartBootstrapperFactory EpochStartBootstrapperCreator
}

// NewSovereignEpochStartBootstrapperFactory creates a new epoch start bootstrapper factory for chain run sovereign
func NewSovereignEpochStartBootstrapperFactory(esbf EpochStartBootstrapperCreator) (EpochStartBootstrapperCreator, error) {
if check.IfNil(esbf) {
return nil, errors.ErrNilEpochStartBootstrapperFactory
}
return &sovereignEpochStartBootstrapperFactory{
epochStartBootstrapperFactory: esbf,
}, nil
func NewSovereignEpochStartBootstrapperFactory() EpochStartBootstrapperCreator {
return &sovereignEpochStartBootstrapperFactory{}
}

// CreateEpochStartBootstrapper creates a new epoch start bootstrapper for sovereign chain operations
Expand Down
Original file line number Diff line number Diff line change
@@ -1,69 +1,43 @@
package bootstrap

import (
"fmt"
"testing"

"github.com/multiversx/mx-chain-go/config"
"github.com/multiversx/mx-chain-go/errors"

"github.com/multiversx/mx-chain-core-go/data/endProcess"
"github.com/stretchr/testify/require"

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

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

sebf, err := NewSovereignEpochStartBootstrapperFactory(nil)

require.Nil(t, sebf)
require.Equal(t, errors.ErrNilEpochStartBootstrapperFactory, err)

esbf := NewEpochStartBootstrapperFactory()
sebf, err = NewSovereignEpochStartBootstrapperFactory(esbf)

require.Nil(t, err)
require.NotNil(t, sebf)
sebf := NewSovereignEpochStartBootstrapperFactory()
require.False(t, sebf.IsInterfaceNil())
}

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

esbf := NewEpochStartBootstrapperFactory()
sebf, _ := NewSovereignEpochStartBootstrapperFactory(esbf)

sebf := NewSovereignEpochStartBootstrapperFactory()
seb, err := sebf.CreateEpochStartBootstrapper(getDefaultArgs())

require.Nil(t, err)
require.NotNil(t, seb)
require.Equal(t, "*bootstrap.sovereignChainEpochStartBootstrap", fmt.Sprintf("%T", seb))
}

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

esbf := NewEpochStartBootstrapperFactory()
sebf, _ := NewSovereignEpochStartBootstrapperFactory(esbf)

sebf := NewSovereignEpochStartBootstrapperFactory()
arg := ArgsStorageEpochStartBootstrap{
ArgsEpochStartBootstrap: getDefaultArgs(),
ImportDbConfig: config.ImportDbConfig{},
ChanGracefullyClose: make(chan endProcess.ArgEndProcess, 1),
TimeToWaitForRequestedData: 1,
}
esb, err := sebf.CreateStorageEpochStartBootstrapper(arg)

require.Nil(t, err)
require.NotNil(t, esb)

}

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

esbf := NewEpochStartBootstrapperFactory()
sebf, _ := NewSovereignEpochStartBootstrapperFactory(esbf)

require.False(t, sebf.IsInterfaceNil())
require.Equal(t, "*bootstrap.storageEpochStartBootstrap", fmt.Sprintf("%T", esb))

sebf = (*sovereignEpochStartBootstrapperFactory)(nil)
require.True(t, sebf.IsInterfaceNil())
}
3 changes: 3 additions & 0 deletions errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -874,3 +874,6 @@ var ErrNilAPIRewardsHandler = errors.New("nil api rewards handler has been provi

// ErrNilOutportDataProviderFactory signals that a nil outport data provider factory has been provided
var ErrNilOutportDataProviderFactory = errors.New("nil outport data provider factory has been provided")

// ErrReceivedSovereignEpochStartBlockWithExtendedHeaders signals that an invalid epoch start sovereign block has been received
var ErrReceivedSovereignEpochStartBlockWithExtendedHeaders = errors.New("received invalid epoch start sovereign block, should not contain any extended headers")
38 changes: 38 additions & 0 deletions factory/epochStartTrigger/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package epochStartTrigger

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

"github.com/multiversx/mx-chain-go/dataRetriever"
"github.com/multiversx/mx-chain-go/factory"
"github.com/multiversx/mx-chain-go/process"
)

func checkNilArgs(args factory.ArgsEpochStartTrigger) error {
if check.IfNil(args.DataComps) {
return process.ErrNilDataComponentsHolder
}
if check.IfNil(args.DataComps.Datapool()) {
return process.ErrNilDataPoolHolder
}
if check.IfNil(args.DataComps.Blockchain()) {
return process.ErrNilBlockChain
}
if check.IfNil(args.DataComps.Datapool().MiniBlocks()) {
return dataRetriever.ErrNilMiniblocksPool
}
if check.IfNil(args.DataComps.Datapool().ValidatorsInfo()) {
return process.ErrNilValidatorInfoPool
}
if check.IfNil(args.BootstrapComponents) {
return process.ErrNilBootstrapComponentsHolder
}
if check.IfNil(args.BootstrapComponents.ShardCoordinator()) {
return process.ErrNilShardCoordinator
}
if check.IfNil(args.RequestHandler) {
return process.ErrNilRequestHandler
}

return nil
}
82 changes: 82 additions & 0 deletions factory/epochStartTrigger/common_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package epochStartTrigger

import (
"testing"

"github.com/stretchr/testify/require"

"github.com/multiversx/mx-chain-go/dataRetriever"
"github.com/multiversx/mx-chain-go/process"
"github.com/multiversx/mx-chain-go/storage"
)

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

t.Run("nil data comps", func(t *testing.T) {
args := createArgs(0)
args.DataComps = nil
err := checkNilArgs(args)
require.Equal(t, process.ErrNilDataComponentsHolder, err)
})
t.Run("nil data pool", func(t *testing.T) {
args := createArgs(0)
dataComps := createDataCompsMock()
dataComps.DataPool = nil
args.DataComps = dataComps
err := checkNilArgs(args)
require.Equal(t, process.ErrNilDataPoolHolder, err)
})
t.Run("nil blockchain", func(t *testing.T) {
args := createArgs(0)
dataComps := createDataCompsMock()
dataComps.BlockChain = nil
args.DataComps = dataComps
err := checkNilArgs(args)
require.Equal(t, process.ErrNilBlockChain, err)
})
t.Run("nil mb pool", func(t *testing.T) {
args := createArgs(0)
dataComps := createDataCompsMock()
dataPool := createDataPoolMock()
dataPool.MiniBlocksCalled = func() storage.Cacher {
return nil
}
dataComps.DataPool = dataPool
args.DataComps = dataComps
err := checkNilArgs(args)
require.Equal(t, dataRetriever.ErrNilMiniblocksPool, err)
})
t.Run("nil validator pool", func(t *testing.T) {
args := createArgs(0)
dataComps := createDataCompsMock()
dataPool := createDataPoolMock()
dataPool.ValidatorsInfoCalled = func() dataRetriever.ShardedDataCacherNotifier {
return nil
}
dataComps.DataPool = dataPool
args.DataComps = dataComps
err := checkNilArgs(args)
require.Equal(t, process.ErrNilValidatorInfoPool, err)
})
t.Run("nil bootstrap comps", func(t *testing.T) {
args := createArgs(0)
args.BootstrapComponents = nil
err := checkNilArgs(args)
require.Equal(t, process.ErrNilBootstrapComponentsHolder, err)
})
t.Run("nil shard coordinator", func(t *testing.T) {
args := createArgs(0)
bootStrapComps := createBootstrapComps(0)
bootStrapComps.ShardCoordinatorCalled = nil
args.BootstrapComponents = bootStrapComps
err := checkNilArgs(args)
require.Equal(t, process.ErrNilShardCoordinator, err)
})
t.Run("nil request handler", func(t *testing.T) {
args := createArgs(0)
args.RequestHandler = nil
err := checkNilArgs(args)
require.Equal(t, process.ErrNilRequestHandler, err)
})
}
12 changes: 8 additions & 4 deletions factory/epochStartTrigger/epochStartTriggerFactory.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package epochStartTrigger

import (
"errors"
"fmt"
"time"

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

"github.com/multiversx/mx-chain-go/epochStart"
"github.com/multiversx/mx-chain-go/epochStart/metachain"
"github.com/multiversx/mx-chain-go/epochStart/shardchain"
Expand All @@ -15,8 +16,6 @@ import (
"github.com/multiversx/mx-chain-go/process/block"
)

// TODO: MX-15632 Unit tests + fix import cycle

type epochStartTriggerFactory struct {
}

Expand All @@ -29,6 +28,11 @@ func NewEpochStartTriggerFactory() *epochStartTriggerFactory {

// CreateEpochStartTrigger creates an epoch start trigger for normal run type
func (f *epochStartTriggerFactory) CreateEpochStartTrigger(args factory.ArgsEpochStartTrigger) (epochStart.TriggerHandler, error) {
err := checkNilArgs(args)
if err != nil {
return nil, err
}

shardCoordinator := args.BootstrapComponents.ShardCoordinator()

if shardCoordinator.SelfId() < shardCoordinator.NumberOfShards() {
Expand All @@ -38,7 +42,7 @@ func (f *epochStartTriggerFactory) CreateEpochStartTrigger(args factory.ArgsEpoc
return createMetaEpochStartTrigger(args)
}

return nil, errors.New("error creating new start of epoch trigger because of invalid shard id")
return nil, fmt.Errorf("error creating new start of epoch trigger, errror: %w", process.ErrInvalidShardId)
}

func createShardEpochStartTrigger(args factory.ArgsEpochStartTrigger) (epochStart.TriggerHandler, error) {
Expand Down
Loading

0 comments on commit 7fe8b76

Please sign in to comment.