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

[sovereign] Trie sync #6393

Draft
wants to merge 38 commits into
base: MX-15871-sov-sync-epoch-start-block
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
f8e21f8
FEAT: Ugly change files for sovereign
mariusmihaic Aug 16, 2024
30380f7
FEAT: Ugly code to start node from bootstrapped epoch
mariusmihaic Aug 19, 2024
fd20b8d
FEAT: Ugly version sync until epoch 1
mariusmihaic Aug 20, 2024
486a743
FEAT: Ugly version start syncing from epoch 0 to current epoch
mariusmihaic Aug 21, 2024
ba77f40
Merge branch 'feat/sovereign-epoch-change' into MX-15586-sovereign-tr…
mariusmihaic Aug 23, 2024
be44fbd
FEAT: Super ugly version to resync network after restart
mariusmihaic Aug 23, 2024
ed7883d
Merge branch 'feat/chain-go-sdk' into MX-15586-sovereign-trie-sync
mariusmihaic Aug 27, 2024
056edb4
FIX: Revert unnecessary changes
mariusmihaic Aug 27, 2024
b4d4363
CLN: Extra clean + fixes to sync blocks
mariusmihaic Aug 27, 2024
7aba540
CLN: Extra clean + fixes to sync blocks
mariusmihaic Aug 27, 2024
9620310
Merge branch 'MX-15802-request-epoch-start-meta-block' into MX-15586-…
mariusmihaic Sep 2, 2024
2624828
Merge branch 'MX-15802-request-epoch-start-meta-block' into MX-15586-…
mariusmihaic Sep 2, 2024
0a2e91e
FEAT: Unit tests sovereignRequestHandler_test.go
mariusmihaic Sep 2, 2024
8a0c0ab
Merge branch 'MX-15817-set-epoch-handlers-requesters' into MX-15586-s…
mariusmihaic Sep 2, 2024
d936aab
FIX: Load from storage
mariusmihaic Sep 2, 2024
05cfbb6
DOC: Add comm to refactor
mariusmihaic Sep 2, 2024
041a309
Merge branch 'MX-15823-sov-shard-interceptor-container-factory' into …
mariusmihaic Sep 3, 2024
6598c87
DOC: Add comm to refactor
mariusmihaic Sep 3, 2024
61fc6cf
FEAT: Super ugly version to sync from epoch 0
mariusmihaic Sep 4, 2024
7a84263
FIX: Revert change
mariusmihaic Sep 4, 2024
87cddfd
Merge branch 'MX-15830-fix-broadcast-sov-header' into MX-15586-sovere…
mariusmihaic Sep 5, 2024
c24e10a
CLN: Revert changes
mariusmihaic Sep 5, 2024
aad05cb
Merge branch 'MX-15830-fix-broadcast-sov-header' into MX-15586-sovere…
mariusmihaic Sep 9, 2024
9426cfa
Merge branch 'MX-15830-fix-broadcast-sov-header' into MX-15586-sovere…
mariusmihaic Sep 9, 2024
c93fc86
FIX: Revert changes, disable createExportFactoryHandler
mariusmihaic Sep 11, 2024
730f750
Merge branch 'MX-15840-sov-full-sync' into MX-15586-sovereign-trie-sync
mariusmihaic Sep 11, 2024
7950ea2
FIX: Revert changes
mariusmihaic Sep 11, 2024
81c7beb
Merge branch 'MX-15840-sov-full-sync' into MX-15586-sovereign-trie-sync
mariusmihaic Sep 11, 2024
92a179a
FEAT: Extend sovereign trigger to finally trigger epoch start prepare…
mariusmihaic Sep 12, 2024
3c56ec7
FIX: No need to create useless resolver container
mariusmihaic Sep 13, 2024
3b9475c
Merge branch 'MX-15850-bootstrap-request-and-process-for-sovereign' i…
mariusmihaic Sep 13, 2024
2cacd2d
Merge branch 'MX-15850-bootstrap-request-and-process-for-sovereign' i…
mariusmihaic Sep 16, 2024
51ad3d9
Merge branch 'MX-15864-sovereign-shard-storage-handler' into MX-15586…
mariusmihaic Sep 18, 2024
52f6c42
CLN: Revert changes
mariusmihaic Sep 18, 2024
9f21186
Merge branch 'MX-15869-sov-epoch-start-block-processor' into MX-15586…
mariusmihaic Sep 19, 2024
d7e907e
FEAT: Tests epoch start sov block processor
mariusmihaic Sep 19, 2024
ae81470
Merge branch 'MX-15871-sov-sync-epoch-start-block' into MX-15586-sove…
mariusmihaic Sep 20, 2024
15b2f52
Merge branch 'MX-15871-sov-sync-epoch-start-block' into MX-15586-sove…
mariusmihaic Sep 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions dataRetriever/factory/containers/requestersContainer.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ func NewRequestersContainer() *requestersContainer {
}
}

// TODO: THIS STILL CONTAINS META STUFF FOR SOVEREIGN

// Get returns the object stored at a certain key.
// Returns an error if the element does not exist
func (rc *requestersContainer) Get(key string) (dataRetriever.Requester, error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ func (brcf *baseRequestersContainerFactory) createTrieNodesRequester(
}

func (brcf *baseRequestersContainerFactory) generateValidatorInfoRequester() error {
identifierValidatorInfo := common.ValidatorInfoTopic
identifierValidatorInfo := common.ValidatorInfoTopic + brcf.shardCoordinator.CommunicationIdentifier(core.SovereignChainShardId)
shardC := brcf.shardCoordinator
requestSender, err := brcf.createOneRequestSenderWithSpecifiedNumRequests(identifierValidatorInfo, EmptyExcludePeersOnTopic, shardC.SelfId(), brcf.numCrossShardPeers, brcf.numIntraShardPeers)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ func (brcf *baseResolversContainerFactory) createTrieNodesResolver(
}

func (brcf *baseResolversContainerFactory) generateValidatorInfoResolver() error {
identifierValidatorInfo := common.ValidatorInfoTopic
identifierValidatorInfo := common.ValidatorInfoTopic + brcf.shardCoordinator.CommunicationIdentifier(core.SovereignChainShardId)
shardC := brcf.shardCoordinator
resolverSender, err := brcf.createOneResolverSenderWithSpecifiedNumRequests(identifierValidatorInfo, EmptyExcludePeersOnTopic, shardC.SelfId())
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/multiversx/mx-chain-go/dataRetriever/factory/containers"
storagerequesters "github.com/multiversx/mx-chain-go/dataRetriever/storageRequesters"
"github.com/multiversx/mx-chain-go/process/factory"
logger "github.com/multiversx/mx-chain-logger-go"
)

var _ dataRetriever.RequestersContainerFactory = (*shardRequestersContainerFactory)(nil)
Expand All @@ -14,10 +15,14 @@ type shardRequestersContainerFactory struct {
*baseRequestersContainerFactory
}

// THIS SHOULD BE CHANGED FOR SOVEREIGN
var log = logger.GetOrCreate("dsada")

// NewShardRequestersContainerFactory creates a new container filled with topic requesters for shards
func NewShardRequestersContainerFactory(
args FactoryArgs,
) (*shardRequestersContainerFactory, error) {
log.Error("#########################################NewShardRequestersContainerFactory")
container := containers.NewRequestersContainer()
base := &baseRequestersContainerFactory{
container: container,
Expand Down
6 changes: 3 additions & 3 deletions dataRetriever/requestHandlers/requestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ func (rrh *resolverRequestHandler) RequestMiniBlocks(destShardID uint32, miniblo
"num mbs", len(unrequestedHashes),
)

requester, err := rrh.requestersFinder.CrossShardRequester(factory.MiniBlocksTopic, destShardID)
requester, err := rrh.requestersFinder.IntraShardRequester(factory.MiniBlocksTopic)
if err != nil {
log.Error("RequestMiniBlocks.CrossShardRequester",
"error", err.Error(),
Expand Down Expand Up @@ -574,7 +574,7 @@ func (rrh *resolverRequestHandler) RequestValidatorInfo(hash []byte) {
"epoch", rrh.epoch,
)

requester, err := rrh.requestersFinder.MetaChainRequester(common.ValidatorInfoTopic)
requester, err := rrh.requestersFinder.IntraShardRequester(common.ValidatorInfoTopic)
if err != nil {
log.Error("RequestValidatorInfo.MetaChainRequester",
"error", err.Error(),
Expand Down Expand Up @@ -614,7 +614,7 @@ func (rrh *resolverRequestHandler) RequestValidatorsInfo(hashes [][]byte) {
"epoch", rrh.epoch,
)

requester, err := rrh.requestersFinder.MetaChainRequester(common.ValidatorInfoTopic)
requester, err := rrh.requestersFinder.IntraShardRequester(common.ValidatorInfoTopic)
if err != nil {
log.Error("RequestValidatorInfo.MetaChainRequester",
"error", err.Error(),
Expand Down
8 changes: 6 additions & 2 deletions dataRetriever/resolvers/headerResolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,16 @@ func (hdrRes *HeaderResolver) ProcessReceivedMessage(message p2p.MessageP2P, fro

var buff []byte

log.Error("HeaderResolver", "TYPE", rd.Type)

switch rd.Type {
case dataRetriever.HashType:
buff, err = hdrRes.resolveHeaderFromHash(rd)
case dataRetriever.NonceType:
buff, err = hdrRes.resolveHeaderFromNonce(rd)
case dataRetriever.EpochType:
buff, err = hdrRes.resolveHeaderFromEpoch(rd.Value)
log.Error("REST", "buff", string(buff), "err", err)
default:
return dataRetriever.ErrResolveTypeUnknown
}
Expand Down Expand Up @@ -228,10 +231,11 @@ func (hdrRes *HeaderResolver) resolveHeaderFromEpoch(key []byte) ([]byte, error)
return nil, err
}
if isUnknownEpoch {

hdrRes.mutEpochHandler.RLock()
metaEpoch := hdrRes.epochHandler.MetaEpoch()
metaEpoch := hdrRes.epochHandler.MetaEpoch() // DISABLED?????
hdrRes.mutEpochHandler.RUnlock()

log.Error("UNKNOWN EPOCH", "epoch", hdrRes.epochHandler.MetaEpoch())
actualKey = []byte(core.EpochStartIdentifier(metaEpoch))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/multiversx/mx-chain-go/process/factory/interceptorscontainer"
"github.com/multiversx/mx-chain-go/sharding"
"github.com/multiversx/mx-chain-go/storage/cache"
"github.com/multiversx/mx-chain-go/testscommon/sovereign"
"github.com/multiversx/mx-chain-go/update"
)

Expand Down Expand Up @@ -110,27 +111,37 @@ func NewEpochStartInterceptorsContainer(args ArgsEpochStartInterceptorContainer)
NodeOperationMode: args.NodeOperationMode,
}

interceptorsContainerFactory, err := interceptorscontainer.NewMetaInterceptorsContainerFactory(containerFactoryArgs)
// WHY META ??????????????????????????????????

sp, err := interceptorscontainer.NewShardInterceptorsContainerFactory(containerFactoryArgs)
if err != nil {
return nil, nil, err
}

mainContainer, fullArchiveContainer, err := interceptorsContainerFactory.Create()
interceptorsContainerFactory, err := interceptorscontainer.NewSovereignShardInterceptorsContainerFactory(interceptorscontainer.ArgsSovereignShardInterceptorsContainerFactory{
ShardContainer: sp,
IncomingHeaderSubscriber: &sovereign.IncomingHeaderSubscriberStub{}, // definetely this needs help
})
if err != nil {
return nil, nil, err
}

err = interceptorsContainerFactory.AddShardTrieNodeInterceptors(mainContainer)
mainContainer, fullArchiveContainer, err := interceptorsContainerFactory.Create()
if err != nil {
return nil, nil, err
}

if args.NodeOperationMode == common.FullArchiveMode {
err = interceptorsContainerFactory.AddShardTrieNodeInterceptors(fullArchiveContainer)
if err != nil {
return nil, nil, err
}
}
//err = interceptorsContainerFactory.AddShardTrieNodeInterceptors(mainContainer)
//if err != nil {
// return nil, nil, err
//}
//
//if args.NodeOperationMode == common.FullArchiveMode {
// err = interceptorsContainerFactory.AddShardTrieNodeInterceptors(fullArchiveContainer)
// if err != nil {
// return nil, nil, err
// }
//}

return mainContainer, fullArchiveContainer, nil
}
68 changes: 64 additions & 4 deletions epochStart/metachain/sovereignTrigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,31 @@ import (
"github.com/multiversx/mx-chain-core-go/data/block"
"github.com/multiversx/mx-chain-go/dataRetriever"
"github.com/multiversx/mx-chain-go/epochStart"
"github.com/multiversx/mx-chain-go/process"
)

type sovereignTrigger struct {
*trigger
currentEpochValidatorInfoPool epochStart.ValidatorInfoCacher
PeerMiniBlocksSyncer process.ValidatorInfoSyncer
}

// NewSovereignTrigger creates a new sovereign epoch start trigger
func NewSovereignTrigger(args *ArgsNewMetaEpochStartTrigger) (*sovereignTrigger, error) {
func NewSovereignTrigger(args *ArgsNewMetaEpochStartTrigger, PeerMiniBlocksSyncer process.ValidatorInfoSyncer) (*sovereignTrigger, error) {
metaTrigger, err := newTrigger(args, &block.SovereignChainHeader{}, &sovereignTriggerRegistryCreator{}, dataRetriever.BlockHeaderUnit)
if err != nil {
return nil, err
}

return &sovereignTrigger{
trigger: metaTrigger,
}, nil
st := &sovereignTrigger{
trigger: metaTrigger,
currentEpochValidatorInfoPool: args.DataPool.CurrentEpochValidatorInfo(),
PeerMiniBlocksSyncer: PeerMiniBlocksSyncer,
}

args.DataPool.Headers().RegisterHandler(st.receivedMetaBlock)

return st, nil
}

// SetProcessed sets start of epoch to false and cleans underlying structure
Expand Down Expand Up @@ -112,6 +121,57 @@ func (st *sovereignTrigger) revert(header data.HeaderHandler) error {
return nil
}

// receivedMetaBlock is a callback function when a new metablock was received
// upon receiving checks if trigger can be updated
func (t *sovereignTrigger) receivedMetaBlock(headerHandler data.HeaderHandler, metaBlockHash []byte) {
t.mutTrigger.Lock()
defer t.mutTrigger.Unlock()

metaHdr, ok := headerHandler.(*block.SovereignChainHeader)
if !ok {
return
}

if !metaHdr.IsStartOfEpochBlock() {
return
}

log.Error("##############################receivedMetaBlock", "epoch", headerHandler.GetEpoch())

isMetaStartOfEpochForCurrentEpoch := metaHdr.GetEpoch() == t.epoch && metaHdr.IsStartOfEpochBlock()
if isMetaStartOfEpochForCurrentEpoch {
log.Error("##############################isMetaStartOfEpochForCurrentEpoch")
return
}

var err error
defer func() {
log.LogIfError(err)
}()

missingMiniBlocksHashes, blockBody, err := t.PeerMiniBlocksSyncer.SyncMiniBlocks(metaHdr)
if err != nil {
// t.addMissingMiniBlocks(metaHdr.GetEpoch(), missingMiniBlocksHashes)
log.Debug("checkIfTriggerCanBeActivated.SyncMiniBlocks", "num missing mini blocks", len(missingMiniBlocksHashes), "error", err)
return
}

missingValidatorsInfoHashes, validatorsInfo, err := t.PeerMiniBlocksSyncer.SyncValidatorsInfo(blockBody)
if err != nil {
//t.addMissingValidatorsInfo(metaHdr.GetEpoch(), missingValidatorsInfoHashes)
log.Debug("checkIfTriggerCanBeActivated.SyncValidatorsInfo", "num missing validators info", len(missingValidatorsInfoHashes), "error", err)
return
}

for validatorInfoHash, validatorInfo := range validatorsInfo {
t.currentEpochValidatorInfoPool.AddValidatorInfo([]byte(validatorInfoHash), validatorInfo)
}

log.Error("##############################receivedMetaBlock", "NotifyAllPrepare", "true")

t.epochStartNotifier.NotifyAllPrepare(metaHdr, blockBody)
}

// IsInterfaceNil checks if the underlying pointer is nil
func (st *sovereignTrigger) IsInterfaceNil() bool {
return st == nil
Expand Down
2 changes: 1 addition & 1 deletion epochStart/metachain/stakingDataProvider.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ func (sdp *stakingDataProvider) GetBlsKeyOwner(blsKey []byte) (string, error) {
return "", err
}
if vmOutput.ReturnCode != vmcommon.Ok {
return "", fmt.Errorf("%w, error: %v", epochStart.ErrExecutingSystemScCode, vmOutput.ReturnCode)
return "", fmt.Errorf("%w, error: %v, message: %s", epochStart.ErrExecutingSystemScCode, vmOutput.ReturnCode, vmOutput.ReturnMessage)
}
data := vmOutput.ReturnData
if len(data) != 1 {
Expand Down
6 changes: 6 additions & 0 deletions factory/consensus/consensusComponents.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,11 @@ func (ccf *consensusComponentsFactory) createShardStorageAndSyncBootstrapper() (
return nil, err
}

validatorDBSyncer, err := ccf.createValidatorAccountsSyncer()
if err != nil {
return nil, err
}

stateNodesNotifierSubscriber, ok := accountsDBSyncer.(common.StateSyncNotifierSubscriber)
if !ok {
return nil, fmt.Errorf("wrong type conversion for accountsDBSyncer, type: %T", accountsDBSyncer)
Expand Down Expand Up @@ -508,6 +513,7 @@ func (ccf *consensusComponentsFactory) createShardStorageAndSyncBootstrapper() (
ScheduledTxsExecutionHandler: ccf.processComponents.ScheduledTxsExecutionHandler(),
ProcessWaitTime: time.Duration(ccf.config.GeneralSettings.SyncProcessTimeInMillis) * time.Millisecond,
RepopulateTokensSupplies: ccf.flagsConfig.RepopulateTokensSupplies,
ValidatorDBSyncer: validatorDBSyncer,
}

argsShardBootstrapper := sync.ArgShardBootstrapper{
Expand Down
13 changes: 12 additions & 1 deletion factory/epochStartTrigger/sovereignEpochStartTriggerFactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package epochStartTrigger
import (
"github.com/multiversx/mx-chain-go/epochStart"
"github.com/multiversx/mx-chain-go/epochStart/metachain"
"github.com/multiversx/mx-chain-go/epochStart/shardchain"
"github.com/multiversx/mx-chain-go/factory"
)

Expand All @@ -24,7 +25,17 @@ func (f *sovereignEpochStartTriggerFactory) CreateEpochStartTrigger(args factory
return nil, err
}

return metachain.NewSovereignTrigger(metaTriggerArgs)
argsPeerMiniBlockSyncer := shardchain.ArgPeerMiniBlockSyncer{
MiniBlocksPool: args.DataComps.Datapool().MiniBlocks(),
ValidatorsInfoPool: args.DataComps.Datapool().ValidatorsInfo(),
RequestHandler: args.RequestHandler,
}
peerMiniBlockSyncer, err := shardchain.NewPeerMiniBlockSyncer(argsPeerMiniBlockSyncer)
if err != nil {
return nil, err
}

return metachain.NewSovereignTrigger(metaTriggerArgs, peerMiniBlockSyncer)
}

// IsInterfaceNil checks if the underlying pointer is nil
Expand Down
13 changes: 7 additions & 6 deletions process/block/interceptedBlocks/interceptedMetaBlockHeader.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ func NewInterceptedMetaHeader(arg *ArgInterceptedBlockHeader) (*InterceptedMetaH
return inHdr, nil
}

func createMetaHdr(marshalizer marshal.Marshalizer, hdrBuff []byte) (*block.MetaBlock, error) {
hdr := &block.MetaBlock{
ShardInfo: make([]block.ShardData, 0),
func createMetaHdr(marshalizer marshal.Marshalizer, hdrBuff []byte) (data.MetaHeaderHandler, error) {
hdr := &block.SovereignChainHeader{
//ShardInfo: make([]block.ShardData, 0),
Header: &block.Header{},
}
err := marshalizer.Unmarshal(hdr, hdrBuff)
if err != nil {
Expand Down Expand Up @@ -128,9 +129,9 @@ func (imh *InterceptedMetaHeader) isMetaHeaderEpochOutOfRange() bool {
return false
}

if imh.hdr.GetEpoch() > imh.epochStartTrigger.Epoch()+1 {
return true
}
//if imh.hdr.GetEpoch() > imh.epochStartTrigger.Epoch()+1 {
// return true
//}

return false
}
Expand Down
Loading
Loading