From f8e5e9e047cf393ff2925f05e832c84aa8629ef7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Rebonato?= Date: Wed, 15 Jan 2025 13:24:33 -0300 Subject: [PATCH] fix usage --- .../prospective-parachains.go | 53 ++++++------------- .../prospective_parachains_test.go | 27 +++++----- 2 files changed, 27 insertions(+), 53 deletions(-) diff --git a/dot/parachain/prospective-parachains/prospective-parachains.go b/dot/parachain/prospective-parachains/prospective-parachains.go index d9012db029..2804c7c132 100644 --- a/dot/parachain/prospective-parachains/prospective-parachains.go +++ b/dot/parachain/prospective-parachains/prospective-parachains.go @@ -5,7 +5,6 @@ import ( "errors" "github.com/ChainSafe/gossamer/dot/parachain/backing" - fragmentchain "github.com/ChainSafe/gossamer/dot/parachain/prospective-parachains/fragment-chain" parachaintypes "github.com/ChainSafe/gossamer/dot/parachain/types" "github.com/ChainSafe/gossamer/internal/log" "github.com/ChainSafe/gossamer/lib/common" @@ -13,38 +12,15 @@ import ( var logger = log.NewFromGlobal(log.AddContext("pkg", "prospective_parachains"), log.SetLevel(log.Debug)) -type RelayBlockViewData struct { - // The fragment chains for current and upcoming scheduled paras. - FragmentChains map[parachaintypes.ParaID]fragmentchain.FragmentChain -} - -type View struct { - // Per relay parent fragment chains. These includes all relay parents under the implicit view. - PerRelayParent map[common.Hash]RelayBlockViewData - // The hashes of the currently active leaves. This is a subset of the keys in - // `per_relay_parent`. - ActiveLeaves map[common.Hash]struct{} - // The backing implicit view. - ImplicitView backing.ImplicitView -} - // Initialize with empty values. -func NewView() *View { - return &View{ - PerRelayParent: make(map[common.Hash]RelayBlockViewData), - ActiveLeaves: make(map[common.Hash]struct{}), - ImplicitView: nil, // TODO: currently there's no implementation for ImplicitView, reference is: https://github.com/paritytech/polkadot-sdk/blob/028e61be43f05f6f6c88c5cca94160f8db075585/polkadot/node/subsystem-util/src/backing_implicit_view.rs#L40 +func NewView() *view { + return &view{ + perRelayParent: make(map[common.Hash]*relayParentData), + activeLeaves: make(map[common.Hash]bool), + implicitView: nil, // TODO: currently there's no implementation for ImplicitView, reference is: https://github.com/paritytech/polkadot-sdk/blob/028e61be43f05f6f6c88c5cca94160f8db075585/polkadot/node/subsystem-util/src/backing_implicit_view.rs#L40 } } -// Get the fragment chains of this leaf. -func (v *View) GetFragmentChains(leaf common.Hash) map[parachaintypes.ParaID]fragmentchain.FragmentChain { - if viewData, ok := v.PerRelayParent[leaf]; ok { - return viewData.FragmentChains - } - return nil -} - type ProspectiveParachains struct { SubsystemToOverseer chan<- any View *view @@ -53,6 +29,7 @@ type ProspectiveParachains struct { type view struct { activeLeaves map[common.Hash]bool perRelayParent map[common.Hash]*relayParentData + implicitView backing.ImplicitView } type relayParentData struct { @@ -122,7 +99,7 @@ func (pp *ProspectiveParachains) processMessage(msg any) { } func (pp *ProspectiveParachains) introduceSecondedCandidate( - view *View, + view *view, request IntroduceSecondedCandidateRequest, response chan bool, ) { @@ -140,11 +117,11 @@ func (pp *ProspectiveParachains) introduceSecondedCandidate( candidateHash := parachaintypes.CandidateHash{Value: hash} - entry, err := fragmentchain.NewCandidateEntry( + entry, err := newCandidateEntry( candidateHash, candidate, pvd, - fragmentchain.Seconded, + seconded, ) if err != nil { @@ -153,24 +130,24 @@ func (pp *ProspectiveParachains) introduceSecondedCandidate( return } - added := make([]common.Hash, 0, len(view.PerRelayParent)) + added := make([]common.Hash, 0, len(view.perRelayParent)) paraScheduled := false - for relayParent, rpData := range view.PerRelayParent { - chain, exists := rpData.FragmentChains[para] + for relayParent, rpData := range view.perRelayParent { + chain, exists := rpData.fragmentChains[para] if !exists { continue } - _, isActiveLeaf := view.ActiveLeaves[relayParent] + _, isActiveLeaf := view.activeLeaves[relayParent] paraScheduled = true - err = chain.TryAddingSecondedCandidate(entry) + err = chain.tryAddingSecondedCandidate(entry) if err != nil { - if errors.Is(err, fragmentchain.ErrCandidateAlradyKnown) { + if errors.Is(err, errCandidateAlreadyKnown) { logger.Tracef( "attempting to introduce an already known candidate with hash: %s, para: %v relayParent: %v isActiveLeaf: %v", candidateHash, diff --git a/dot/parachain/prospective-parachains/prospective_parachains_test.go b/dot/parachain/prospective-parachains/prospective_parachains_test.go index bee135ae93..3a588e829b 100644 --- a/dot/parachain/prospective-parachains/prospective_parachains_test.go +++ b/dot/parachain/prospective-parachains/prospective_parachains_test.go @@ -5,9 +5,7 @@ import ( "context" "testing" - fragmentchain "github.com/ChainSafe/gossamer/dot/parachain/prospective-parachains/fragment-chain" parachaintypes "github.com/ChainSafe/gossamer/dot/parachain/types" - inclusionemulator "github.com/ChainSafe/gossamer/dot/parachain/util/inclusion-emulator" "github.com/ChainSafe/gossamer/lib/common" "github.com/stretchr/testify/assert" ) @@ -125,24 +123,23 @@ func TestFailedIntroduceSecondedCandidateWhenParentHeadAndHeadDataEquals( prospectiveParachains := NewProspectiveParachains(subsystemToOverseer) - relayParent := inclusionemulator.RelayChainBlockInfo{ + relayParent := relayChainBlockInfo{ Hash: candidateRelayParent, Number: 0, StorageRoot: common.Hash{0x00}, } - baseConstraints := &inclusionemulator.Constraints{ + baseConstraints := ¶chaintypes.Constraints{ RequiredParent: parachaintypes.HeadData{Data: []byte{byte(0)}}, MinRelayParentNumber: 0, ValidationCodeHash: parachaintypes.ValidationCodeHash(common.Hash{0x03}), } - - scope, err := fragmentchain.NewScopeWithAncestors(relayParent, baseConstraints, nil, 10, nil) + scope, err := newScopeWithAncestors(relayParent, baseConstraints, nil, 10, nil) assert.NoError(t, err) - prospectiveParachains.View.PerRelayParent[candidateRelayParent] = RelayBlockViewData{ - FragmentChains: map[parachaintypes.ParaID]fragmentchain.FragmentChain{ - paraId: *fragmentchain.NewFragmentChain(scope, fragmentchain.NewCandidateStorage()), + prospectiveParachains.View.perRelayParent[candidateRelayParent] = &relayParentData{ + fragmentChains: map[parachaintypes.ParaID]*fragmentChain{ + paraId: newFragmentChain(scope, newCandidateStorage()), }, } go prospectiveParachains.Run(context.Background(), overseerToSubsystem) @@ -180,24 +177,24 @@ func TestHandleIntroduceSecondedCandidate( prospectiveParachains := NewProspectiveParachains(subsystemToOverseer) - relayParent := inclusionemulator.RelayChainBlockInfo{ + relayParent := relayChainBlockInfo{ Hash: candidateRelayParent, Number: 0, StorageRoot: common.Hash{0x00}, } - baseConstraints := &inclusionemulator.Constraints{ + baseConstraints := ¶chaintypes.Constraints{ RequiredParent: parachaintypes.HeadData{Data: []byte{byte(0)}}, MinRelayParentNumber: 0, ValidationCodeHash: parachaintypes.ValidationCodeHash(common.Hash{0x03}), } - scope, err := fragmentchain.NewScopeWithAncestors(relayParent, baseConstraints, nil, 10, nil) + scope, err := newScopeWithAncestors(relayParent, baseConstraints, nil, 10, nil) assert.NoError(t, err) - prospectiveParachains.View.PerRelayParent[candidateRelayParent] = RelayBlockViewData{ - FragmentChains: map[parachaintypes.ParaID]fragmentchain.FragmentChain{ - paraId: *fragmentchain.NewFragmentChain(scope, fragmentchain.NewCandidateStorage()), + prospectiveParachains.View.perRelayParent[candidateRelayParent] = &relayParentData{ + fragmentChains: map[parachaintypes.ParaID]*fragmentChain{ + paraId: newFragmentChain(scope, newCandidateStorage()), }, } go prospectiveParachains.Run(context.Background(), overseerToSubsystem)