From 8a2933deb9126e703bba68deaabdd833a81b45fd Mon Sep 17 00:00:00 2001 From: Kanishka Date: Thu, 23 Nov 2023 22:17:40 +0530 Subject: [PATCH] cleanup --- .../collator-protocol/mocks_generate_test.go | 4 - dot/parachain/dispute/backend.go | 6 +- dot/parachain/dispute/comm.go | 15 +- dot/parachain/dispute/coordinator.go | 145 +++++----- dot/parachain/dispute/db.go | 6 +- dot/parachain/dispute/initialized.go | 75 +++-- dot/parachain/dispute/mock_runtime_test.go | 2 +- dot/parachain/dispute/overseer/message.go | 28 +- dot/parachain/dispute/participation.go | 72 ++--- dot/parachain/dispute/participation_test.go | 61 ++-- dot/parachain/dispute/queue_test.go | 265 ++++++++---------- dot/parachain/dispute/queues.go | 15 +- dot/parachain/dispute/scraping/comm.go | 6 +- .../dispute/scraping/mock_runtime_test.go | 2 +- .../dispute/scraping/scraping_test.go | 4 +- dot/parachain/dispute/spam_slots.go | 2 +- .../dot/parachain/mocks_runtime_test.go | 126 --------- dot/parachain/mock_runtime_test.go | 32 ++- dot/parachain/pov_fetching.go | 1 - dot/state/storage_notify.go | 2 +- .../inherents/parachain_inherents_test.go | 14 +- .../varying_data_type_nested_example_test.go | 16 +- 22 files changed, 405 insertions(+), 494 deletions(-) delete mode 100644 dot/parachain/dot/parachain/mocks_runtime_test.go diff --git a/dot/parachain/collator-protocol/mocks_generate_test.go b/dot/parachain/collator-protocol/mocks_generate_test.go index fc98e2d23ab..52038ee3442 100644 --- a/dot/parachain/collator-protocol/mocks_generate_test.go +++ b/dot/parachain/collator-protocol/mocks_generate_test.go @@ -3,9 +3,5 @@ package collatorprotocol -<<<<<<<< HEAD:dot/parachain/collator-protocol/mocks_generate_test.go -//go:generate mockgen -destination=mocks_test.go -package=$GOPACKAGE . Network -======== //go:generate mockgen -destination=mocks_test.go -package=$GOPACKAGE . PoVRequestor //go:generate mockgen -destination=mocks_runtime_test.go -package $GOPACKAGE github.com/ChainSafe/gossamer/dot/parachain/runtime RuntimeInstance ->>>>>>>> 7c50d399 (moved `lib/parachain` to `dot/parachain` (#3429)):dot/parachain/mocks_generate_test.go diff --git a/dot/parachain/dispute/backend.go b/dot/parachain/dispute/backend.go index 6fc8bb405db..9fd0870d7fc 100644 --- a/dot/parachain/dispute/backend.go +++ b/dot/parachain/dispute/backend.go @@ -11,7 +11,7 @@ import ( "github.com/ChainSafe/gossamer/lib/common" ) -// Backend is the backend for the dispute coordinator module. +// Backend is the backend for the disputes coordinator module. type Backend interface { // GetEarliestSession returns the earliest session index, if any. GetEarliestSession() (*parachainTypes.SessionIndex, error) @@ -28,7 +28,7 @@ type Backend interface { SetCandidateVotes(session parachainTypes.SessionIndex, candidateHash common.Hash, votes *types.CandidateVotes) error } -// OverlayBackend is the overlay backend for the dispute coordinator module. +// OverlayBackend is the overlay backend for the disputes coordinator module. type OverlayBackend interface { Backend @@ -42,7 +42,7 @@ type OverlayBackend interface { NoteEarliestSession(session parachainTypes.SessionIndex) error } -// DBBackend is the backend for the dispute coordinator module that uses a database. +// DBBackend is the backend for the disputes coordinator module that uses a database. type DBBackend interface { Backend diff --git a/dot/parachain/dispute/comm.go b/dot/parachain/dispute/comm.go index dd11ef56a05..2f7e5cd412b 100644 --- a/dot/parachain/dispute/comm.go +++ b/dot/parachain/dispute/comm.go @@ -18,8 +18,8 @@ func getBlockNumber(overseerChannel chan<- any, receipt parachainTypes.Candidate return 0, fmt.Errorf("get hash: %w", err) } - message := overseer.ChainAPIMessage[overseer.BlockNumberRequest]{ - Message: overseer.BlockNumberRequest{Hash: relayParent}, + message := overseer.ChainAPIMessage[overseer.BlockNumber]{ + Message: overseer.BlockNumber{Hash: relayParent}, ResponseChannel: respCh, } result, err := call(overseerChannel, message, message.ResponseChannel) @@ -48,16 +48,13 @@ func sendMessage(channel chan<- any, message any) error { } func call(channel chan<- any, message any, responseChan chan any) (any, error) { - // Send with timeout + if err := sendMessage(channel, message); err != nil { + return nil, fmt.Errorf("send message: %w", err) + } + ctx, cancel := context.WithTimeout(context.Background(), timeout) defer cancel() - select { - case channel <- message: - case <-ctx.Done(): - return nil, ctx.Err() - } - select { case response := <-responseChan: return response, nil diff --git a/dot/parachain/dispute/coordinator.go b/dot/parachain/dispute/coordinator.go index c1d0cae6bbc..b7152b9963c 100644 --- a/dot/parachain/dispute/coordinator.go +++ b/dot/parachain/dispute/coordinator.go @@ -24,31 +24,12 @@ type Coordinator struct { store *overlayBackend runtime parachain.RuntimeInstance - sender chan<- any + overseer chan<- any receiver <-chan any } -func (d *Coordinator) Run() error { - initResult, err := d.initialize() - if err != nil { - return fmt.Errorf("initialize dispute coordinator: %w", err) - } - - initData := InitialData{ - Participation: initResult.participation, - Votes: initResult.votes, - Leaf: initResult.activatedLeaf, - } - - if err := initResult.initialized.Run(d.sender, d.store.inner, &initData); err != nil { - return fmt.Errorf("run initialized state: %w", err) - } - - return nil -} - type startupResult struct { - participation []ParticipationRequestWithPriority + participation []ParticipationData votes []parachainTypes.ScrapedOnChainVotes spamSlots SpamSlots orderingProvider scraping.ChainScraper @@ -57,20 +38,69 @@ type startupResult struct { } type initializeResult struct { - participation []ParticipationRequestWithPriority + participation []ParticipationData votes []parachainTypes.ScrapedOnChainVotes activatedLeaf *overseer.ActivatedLeaf initialized *Initialized } +func (d *Coordinator) sendDisputeMessages( + env types.CandidateEnvironment, + voteState types.CandidateVoteState, +) { + ownVotes, err := voteState.Own.Votes() + if err != nil { + logger.Errorf("get own votes: %s", err) + return + } + + for _, vote := range ownVotes { + keypair, err := types.GetValidatorKeyPair(d.keystore, env.Session.Validators, vote.ValidatorIndex) + if err != nil { + logger.Errorf("get validator key pair: %s", err) + continue + } + + candidateHash, err := voteState.Votes.CandidateReceipt.Hash() + if err != nil { + logger.Errorf("get candidate hash: %s", err) + continue + } + + isValid, err := vote.DisputeStatement.IsValid() + if err != nil { + logger.Errorf("check if dispute statement is valid: %s", err) + continue + } + + signedDisputeStatement, err := types.NewSignedDisputeStatement(keypair, isValid, candidateHash, env.SessionIndex) + if err != nil { + logger.Errorf("create signed dispute statement: %s", err) + continue + } + + disputeMessage, err := types.NewDisputeMessage(keypair, voteState.Votes, &signedDisputeStatement, vote.ValidatorIndex, env.Session) + if err != nil { + logger.Errorf("create dispute message: %s", err) + continue + } + + if err := sendMessage(d.overseer, disputeMessage); err != nil { + logger.Errorf("send dispute message: %s", err) + } + } +} + func (d *Coordinator) waitForFirstLeaf() (*overseer.ActivatedLeaf, error) { - // TODO: handle other messages for { select { case overseerMessage := <-d.receiver: switch message := overseerMessage.(type) { case overseer.Signal[overseer.ActiveLeavesUpdate]: return message.Data.Activated, nil + default: + logger.Warnf("Received message before first active leaves update. "+ + "This is not expected - message will be dropped. %T", message) } } } @@ -100,7 +130,7 @@ func (d *Coordinator) initialize() ( participation: startupData.participation, votes: startupData.votes, activatedLeaf: firstLeaf, - initialized: NewInitializedState(d.sender, + initialized: NewInitializedState(d.overseer, d.runtime, startupData.spamSlots, &startupData.orderingProvider, @@ -127,9 +157,9 @@ func (d *Coordinator) handleStartup(initialHead *overseer.ActivatedLeaf) ( } gapsInCache := false - for idx := highestSession - (Window - 1); idx <= highestSession; idx++ { - _, err = d.runtime.ParachainHostSessionInfo(initialHead.Hash, idx) - if err != nil { + for idx := saturatingSub(uint32(highestSession), Window-1); idx <= uint32(highestSession); idx++ { + sessionInfo, err := d.runtime.ParachainHostSessionInfo(initialHead.Hash, parachainTypes.SessionIndex(idx)) + if err != nil || sessionInfo == nil { logger.Debugf("no session info for session %d", idx) gapsInCache = true continue @@ -137,7 +167,8 @@ func (d *Coordinator) handleStartup(initialHead *overseer.ActivatedLeaf) ( } // prune obsolete disputes - if err := d.store.NoteEarliestSession(highestSession); err != nil { + earliestSession := parachainTypes.SessionIndex(saturatingSub(uint32(highestSession), Window-1)) + if err := d.store.NoteEarliestSession(earliestSession); err != nil { return nil, fmt.Errorf("note earliest session: %w", err) } @@ -145,10 +176,10 @@ func (d *Coordinator) handleStartup(initialHead *overseer.ActivatedLeaf) ( // get candidate votes // check if it is a potential spam // participate if needed, if not distribute the own vote - var participationRequests []ParticipationRequestWithPriority + var participationRequests []ParticipationData spamDisputes := make(map[unconfirmedKey]*treeset.Set) leafHash := initialHead.Hash - scraper, scrapedVotes, err := scraping.NewChainScraper(d.sender, d.runtime, initialHead) + scraper, scrapedVotes, err := scraping.NewChainScraper(d.overseer, d.runtime, initialHead) if err != nil { return nil, fmt.Errorf("new chain scraper: %w", err) } @@ -206,7 +237,7 @@ func (d *Coordinator) handleStartup(initialHead *overseer.ActivatedLeaf) ( priority = ParticipationPriorityBestEffort } - participationRequests = append(participationRequests, ParticipationRequestWithPriority{ + participationRequests = append(participationRequests, ParticipationData{ request: ParticipationRequest{ candidateHash: dispute.Comparator.CandidateHash, candidateReceipt: voteState.Votes.CandidateReceipt, @@ -232,51 +263,23 @@ func (d *Coordinator) handleStartup(initialHead *overseer.ActivatedLeaf) ( }, nil } -func (d *Coordinator) sendDisputeMessages( - env types.CandidateEnvironment, - voteState types.CandidateVoteState, -) { - ownVotes, err := voteState.Own.Votes() +func (d *Coordinator) Run() error { + initResult, err := d.initialize() if err != nil { - logger.Errorf("get own votes: %s", err) - return + return fmt.Errorf("initialize dispute coordinator: %w", err) } - for _, vote := range ownVotes { - keypair, err := types.GetValidatorKeyPair(d.keystore, env.Session.Validators, vote.ValidatorIndex) - if err != nil { - logger.Errorf("get validator key pair: %s", err) - continue - } - - candidateHash, err := voteState.Votes.CandidateReceipt.Hash() - if err != nil { - logger.Errorf("get candidate hash: %s", err) - continue - } - - isValid, err := vote.DisputeStatement.IsValid() - if err != nil { - logger.Errorf("check if dispute statement is valid: %s", err) - continue - } - - signedDisputeStatement, err := types.NewSignedDisputeStatement(keypair, isValid, candidateHash, env.SessionIndex) - if err != nil { - logger.Errorf("create signed dispute statement: %s", err) - continue - } - - disputeMessage, err := types.NewDisputeMessage(keypair, voteState.Votes, &signedDisputeStatement, vote.ValidatorIndex, env.Session) - if err != nil { - logger.Errorf("create dispute message: %s", err) - continue - } + initData := InitialData{ + Participation: initResult.participation, + Votes: initResult.votes, + Leaf: initResult.activatedLeaf, + } - if err := sendMessage(d.sender, disputeMessage); err != nil { - logger.Errorf("send dispute message: %s", err) - } + if err := initResult.initialized.Run(d.overseer, d.store.inner, &initData); err != nil { + return fmt.Errorf("run initialized state: %w", err) } + + return nil } func NewDisputeCoordinator(path string) (*Coordinator, error) { diff --git a/dot/parachain/dispute/db.go b/dot/parachain/dispute/db.go index 55f14dd2bf1..5ff0b025433 100644 --- a/dot/parachain/dispute/db.go +++ b/dot/parachain/dispute/db.go @@ -241,12 +241,12 @@ func (b *BadgerBackend) setVotesCleanupTxn(txn *badger.Txn, earliestSession para return fmt.Errorf("get watermark: %w", err) } - cleanUntil := earliestSession - watermark + cleanUntil := saturatingSub(uint32(earliestSession), uint32(watermark)) if cleanUntil > MaxCleanBatchSize { cleanUntil = MaxCleanBatchSize } - for i := watermark; i < cleanUntil; i++ { + for i := watermark; i < parachainTypes.SessionIndex(cleanUntil); i++ { prefix := newCandidateVotesSessionPrefix(i) it := txn.NewIterator(badger.DefaultIteratorOptions) @@ -263,7 +263,7 @@ func (b *BadgerBackend) setVotesCleanupTxn(txn *badger.Txn, earliestSession para } // new watermark - if err := b.setWatermarkTxn(txn, cleanUntil); err != nil { + if err := b.setWatermarkTxn(txn, parachainTypes.SessionIndex(cleanUntil)); err != nil { return fmt.Errorf("set watermark: %w", err) } diff --git a/dot/parachain/dispute/initialized.go b/dot/parachain/dispute/initialized.go index 39baca08365..8ce08c87bce 100644 --- a/dot/parachain/dispute/initialized.go +++ b/dot/parachain/dispute/initialized.go @@ -37,7 +37,7 @@ type Initialized struct { } type InitialData struct { - Participation []ParticipationRequestWithPriority + Participation []ParticipationData Votes []parachainTypes.ScrapedOnChainVotes Leaf *overseer.ActivatedLeaf } @@ -69,7 +69,7 @@ func (i *Initialized) Run(overseerChannel chan<- any, backend DBBackend, initial func (i *Initialized) runUntilError(overseerChannel chan<- any, backend DBBackend, initialData *InitialData) error { if initialData != nil { for _, p := range initialData.Participation { - if err := i.Participation.Queue(overseerChannel, p.request, p.priority); err != nil { + if err := i.Participation.Queue(overseerChannel, p); err != nil { return fmt.Errorf("queue participation request: %w", err) } } @@ -160,30 +160,25 @@ func (i *Initialized) ProcessActiveLeavesUpdate( } else { // If error has occurred during last session caching - fetch the whole window // Otherwise - cache only the new sessions - var lowerBound parachainTypes.SessionIndex - if i.GapsInCache { - lowerBound = sessionIDx - (Window - 1) - if sessionIDx < lowerBound { - lowerBound = sessionIDx - } - } else { - lowerBound = i.HighestSessionSeen + 1 + lowerBound := saturatingSub(uint32(sessionIDx), Window-1) + if !i.GapsInCache { + lowerBound = uint32(i.HighestSessionSeen + 1) } // There is a new session. Perform a dummy fetch to cache it. - for session := lowerBound; session <= sessionIDx; session++ { - if _, err := i.runtime.ParachainHostSessionInfo(update.Activated.Hash, session); err != nil { + for session := lowerBound; session <= uint32(sessionIDx); session++ { + if _, err := i.runtime.ParachainHostSessionInfo(update.Activated.Hash, parachainTypes.SessionIndex(session)); err != nil { logger.Debugf("error caching SessionInfo on ActiveLeaves update. "+ "Session: %v, Hash: %v, Error: %v", session, update.Activated.Hash, - err) + err, + ) i.GapsInCache = true } } i.HighestSessionSeen = sessionIDx - earliestSession := saturatingSub(uint32(sessionIDx), Window-1) if err := backend.NoteEarliestSession(parachainTypes.SessionIndex(earliestSession)); err != nil { logger.Tracef("error noting earliest session: %w", err) @@ -224,7 +219,6 @@ func (i *Initialized) ProcessChainImportBacklog( } importRange := minInt(ChainImportMaxBatchSize, chainImportBacklog.Len()) - for k := 0; k < importRange; k++ { votes := chainImportBacklog.PopFront() if err := i.ProcessOnChainVotes(overseerChannel, backend, votes, now, blockHash); err != nil { @@ -380,6 +374,25 @@ func (i *Initialized) ProcessOnChainVotes( dispute.Session, ) + disputeSessionInfo, err := i.runtime.ParachainHostSessionInfo(blockHash, parachainTypes.SessionIndex(dispute.Session)) + if err != nil || disputeSessionInfo == nil { + logger.Warnf("no session info for disputeSession %d", dispute.Session) + continue + } + + var filteredStatements []types.Statement + for _, statement := range statements { + if int(statement.ValidatorIndex) >= len(disputeSessionInfo.Validators) { + logger.Warnf("invalid validator index %d for dispute session %d", + statement.ValidatorIndex, + dispute.Session) + continue + } + + statement.SignedDisputeStatement.ValidatorPublic = disputeSessionInfo.Validators[statement.ValidatorIndex] + filteredStatements = append(filteredStatements, statement) + } + if len(statements) == 0 { logger.Errorf("skipping empty from chain dispute import. session: %v, candidateHash: %v", votes.Session, @@ -395,7 +408,7 @@ func (i *Initialized) ProcessOnChainVotes( backend, candidateReceipt, votes.Session, - statements, + filteredStatements, now, ); err != nil || outcome == InvalidImport { logger.Errorf("attempted import of on-chain dispute votes failed. "+ @@ -434,7 +447,8 @@ func (i *Initialized) HandleIncoming( "candidateHash: %v, Error: %v", message.Data.Session, message.Data.CandidateHash, - err) + err, + ) } else { logger.Tracef( "issuing local statement based on participation outcome. Session: %v, "+ @@ -769,12 +783,15 @@ func (i *Initialized) HandleImportStatements( priority, ) // TODO: metrics - participationRequest := ParticipationRequest{ - candidateHash: candidateHash, - candidateReceipt: newState.Votes.CandidateReceipt, - session: session, + participationData := ParticipationData{ + ParticipationRequest{ + candidateHash: candidateHash, + candidateReceipt: newState.Votes.CandidateReceipt, + session: session, + }, + priority, } - if err := i.Participation.Queue(overseerChannel, participationRequest, priority); err != nil { + if err := i.Participation.Queue(overseerChannel, participationData); err != nil { logger.Errorf("failed to queue participation request: %s", err) } } else { @@ -918,8 +935,8 @@ func (i *Initialized) HandleImportStatements( } if len(blocks) > 0 { - message := overseer.ChainSelectionMessage{ - RevertBlocks: &overseer.RevertBlocksRequest{Blocks: blocks}, + message := overseer.ChainSelectionMessage[overseer.RevertBlocks]{ + Message: overseer.RevertBlocks{Blocks: blocks}, } if err := sendMessage(overseerChannel, message); err != nil { return InvalidImport, fmt.Errorf("send revert blocks request: %w", err) @@ -1061,8 +1078,7 @@ func (i *Initialized) IssueLocalStatement( } func (i *Initialized) sessionIsAncient(session parachainTypes.SessionIndex) bool { - diff := session - (Window - 1) - return session < diff || session < i.HighestSessionSeen + return uint32(session) < saturatingSub(uint32(i.HighestSessionSeen), Window-1) } func (i *Initialized) determineUndisputedChain(backend OverlayBackend, @@ -1138,11 +1154,10 @@ func NewInitializedState(overseerChannel chan<- any, // saturatingSub returns the result of a - b, saturating at 0. func saturatingSub(a, b uint32) uint32 { - result := int(a) - int(b) - if result < 0 { - return 0 + if a > b { + return a - b } - return uint32(result) + return 0 } // minInt returns the smallest of a or b. diff --git a/dot/parachain/dispute/mock_runtime_test.go b/dot/parachain/dispute/mock_runtime_test.go index a5f141780c7..0ca59d1a444 100644 --- a/dot/parachain/dispute/mock_runtime_test.go +++ b/dot/parachain/dispute/mock_runtime_test.go @@ -1,7 +1,7 @@ // Code generated by MockGen. DO NOT EDIT. // Source: github.com/ChainSafe/gossamer/dot/parachain/runtime (interfaces: RuntimeInstance) -// Package dispute is a generated GoMock package. +// Package disputes is a generated GoMock package. package dispute import ( diff --git a/dot/parachain/dispute/overseer/message.go b/dot/parachain/dispute/overseer/message.go index 19845603553..85b76759fb7 100644 --- a/dot/parachain/dispute/overseer/message.go +++ b/dot/parachain/dispute/overseer/message.go @@ -45,11 +45,15 @@ type AvailabilityRecoveryResponse struct { Error *RecoveryError } -type AvailabilityRecoveryMessage struct { +type AvailabilityRecoveryMessage[message any] struct { + Message message + ResponseChannel chan any +} + +type RecoverAvailableData struct { CandidateReceipt parachainTypes.CandidateReceipt SessionIndex parachainTypes.SessionIndex GroupIndex *uint32 - ResponseChannel chan any } type PvfExecTimeoutKind uint32 @@ -59,11 +63,15 @@ const ( PvfExecTimeoutKindApproval ) +type CandidateValidationMessage[message any] struct { + Data message + ResponseChannel chan any +} + type ValidateFromChainState struct { CandidateReceipt parachainTypes.CandidateReceipt PoV []byte PvfExecTimeoutKind PvfExecTimeoutKind - ResponseChannel chan any } type ValidValidationResult struct { @@ -87,11 +95,11 @@ type BlockNumberResponse struct { Err error } -type BlockNumberRequest struct { +type BlockNumber struct { Hash common.Hash } -type FinalizedBlockNumberRequest struct { +type FinalizedBlockNumber struct { Number uint32 } @@ -100,7 +108,7 @@ type AncestorsResponse struct { Error error } -type AncestorsRequest struct { +type Ancestors struct { Hash common.Hash K uint32 } @@ -119,12 +127,12 @@ func NewBlock(blockNumber uint32, hash common.Hash) Block { } } -type RevertBlocksRequest struct { - Blocks []Block +type ChainSelectionMessage[message any] struct { + Message message } -type ChainSelectionMessage struct { - RevertBlocks *RevertBlocksRequest +type RevertBlocks struct { + Blocks []Block } type ApprovalVotingMessage[message any] struct { diff --git a/dot/parachain/dispute/participation.go b/dot/parachain/dispute/participation.go index ec591a64412..836c59f81c2 100644 --- a/dot/parachain/dispute/participation.go +++ b/dot/parachain/dispute/participation.go @@ -36,8 +36,8 @@ type ParticipationRequest struct { //TODO: requestTimer for metrics } -// ParticipationRequestWithPriority a dispute participation request with priority -type ParticipationRequestWithPriority struct { +// ParticipationData a dispute participation request with priority +type ParticipationData struct { request ParticipationRequest priority ParticipationPriority } @@ -53,7 +53,7 @@ type ParticipationStatement struct { // Participation keeps track of the disputes we need to participate in. type Participation interface { // Queue a dispute for the node to participate in - Queue(overseerChannel chan<- any, request ParticipationRequest, priority ParticipationPriority) error + Queue(overseerChannel chan<- any, data ParticipationData) error // Clear clears a participation request. This is called when we have the dispute result. Clear(candidateHash common.Hash) error @@ -78,8 +78,7 @@ type ParticipationHandler struct { queue Queue recentBlock *block - runtime parachain.RuntimeInstance - + runtime parachain.RuntimeInstance overseer chan<- any //TODO: metrics @@ -88,31 +87,30 @@ type ParticipationHandler struct { const MaxParallelParticipation = 3 func (p *ParticipationHandler) Queue(overseerChannel chan<- any, - request ParticipationRequest, - priority ParticipationPriority, + data ParticipationData, ) error { - if _, ok := p.runningParticipation.Load(request.candidateHash); ok { + if _, ok := p.runningParticipation.Load(data.request.candidateHash); ok { return nil } // if we already have a recent block, participate right away if p.recentBlock != nil && p.numberOfWorkers() < MaxParallelParticipation { - p.forkParticipation(&request, p.recentBlock.Hash) + p.forkParticipation(data.request, p.recentBlock.Hash) return nil } - blockNumber, err := getBlockNumber(overseerChannel, request.candidateReceipt) + blockNumber, err := getBlockNumber(overseerChannel, data.request.candidateReceipt) if err != nil { return fmt.Errorf("get block number: %w", err) } - candidateHash, err := request.candidateReceipt.Hash() + candidateHash, err := data.request.candidateReceipt.Hash() if err != nil { return fmt.Errorf("hash candidate receipt: %w", err) } comparator := NewCandidateComparator(&blockNumber, candidateHash) - if err := p.queue.Queue(comparator, &request, priority); err != nil { + if err := p.queue.Queue(comparator, data); err != nil { return fmt.Errorf("queue ParticipationHandler request: %w", err) } @@ -132,8 +130,6 @@ func (p *ParticipationHandler) Clear(candidateHash common.Hash) error { } func (p *ParticipationHandler) ProcessActiveLeavesUpdate(update overseer.ActiveLeavesUpdate) { - // TODO: to check if this is needed here - // if it is being called in only one place, we could just add a check there itself if update.Activated == nil { return } @@ -145,7 +141,6 @@ func (p *ParticipationHandler) ProcessActiveLeavesUpdate(update overseer.ActiveL } return } - p.recentBlock = &block{ Number: update.Activated.Number, Hash: update.Activated.Hash, @@ -198,11 +193,11 @@ func (p *ParticipationHandler) dequeueUntilCapacity(recentHead common.Hash) { break } - p.forkParticipation(request.request, recentHead) + p.forkParticipation(*request.request, recentHead) } } -func (p *ParticipationHandler) forkParticipation(request *ParticipationRequest, recentHead common.Hash) { +func (p *ParticipationHandler) forkParticipation(request ParticipationRequest, recentHead common.Hash) { _, ok := p.runningParticipation.LoadOrStore(request.candidateHash, nil) if ok { return @@ -210,7 +205,7 @@ func (p *ParticipationHandler) forkParticipation(request *ParticipationRequest, p.workers.Add(1) go func() { - if err := p.participate(recentHead, *request); err != nil { + if err := p.participate(recentHead, request); err != nil { logger.Debugf( "failed to participate in dispute. CandidateHash: %s, Error: %s", request.candidateHash.String(), @@ -223,35 +218,42 @@ func (p *ParticipationHandler) forkParticipation(request *ParticipationRequest, func (p *ParticipationHandler) participate(blockHash common.Hash, request ParticipationRequest) error { // get available data from the overseer respCh := make(chan any, 1) - message := overseer.AvailabilityRecoveryMessage{ - CandidateReceipt: request.candidateReceipt, - SessionIndex: request.session, - GroupIndex: nil, - ResponseChannel: respCh, + message := overseer.AvailabilityRecoveryMessage[overseer.RecoverAvailableData]{ + Message: overseer.RecoverAvailableData{ + CandidateReceipt: request.candidateReceipt, + SessionIndex: request.session, + GroupIndex: nil, + }, + ResponseChannel: respCh, } res, err := call(p.overseer, message, message.ResponseChannel) if err != nil { return fmt.Errorf("send availability recovery message: %w", err) } - availableData, ok := res.(overseer.AvailabilityRecoveryResponse) + data, ok := res.(overseer.AvailabilityRecoveryResponse) if !ok { return fmt.Errorf("unexpected response type: %T", res) } - if availableData.Error != nil { - switch *availableData.Error { + if data.Error != nil { + switch *data.Error { case overseer.RecoveryErrorInvalid: sendResult(p.overseer, request, types.ParticipationOutcomeInvalid) - return fmt.Errorf("invalid available data: %s", availableData.Error.String()) + return fmt.Errorf("invalid available data: %s", data.Error.String()) case overseer.RecoveryErrorUnavailable: sendResult(p.overseer, request, types.ParticipationOutcomeUnAvailable) - return fmt.Errorf("unavailable data: %s", availableData.Error.String()) + return fmt.Errorf("unavailable data: %s", data.Error.String()) default: - return fmt.Errorf("unexpected recovery error: %d", availableData.Error) + return fmt.Errorf("unexpected recovery error: %d", data.Error) } } + if data.AvailableData == nil { + sendResult(p.overseer, request, types.ParticipationOutcomeError) + return fmt.Errorf("available data is nil") + } + validationCode, err := p.runtime.ParachainHostValidationCodeByHash( blockHash, request.candidateReceipt.Descriptor.ValidationCodeHash) @@ -271,11 +273,13 @@ func (p *ParticipationHandler) participate(blockHash common.Hash, request Partic // validate the request and send the result respChan := make(chan any, 1) - validateMessage := overseer.ValidateFromChainState{ - CandidateReceipt: request.candidateReceipt, - PoV: availableData.AvailableData.POV, - PvfExecTimeoutKind: overseer.PvfExecTimeoutKindApproval, - ResponseChannel: respChan, + validateMessage := overseer.CandidateValidationMessage[overseer.ValidateFromChainState]{ + Data: overseer.ValidateFromChainState{ + CandidateReceipt: request.candidateReceipt, + PoV: data.AvailableData.POV, + PvfExecTimeoutKind: overseer.PvfExecTimeoutKindApproval, + }, + ResponseChannel: respChan, } res, err = call(p.overseer, validateMessage, validateMessage.ResponseChannel) if err != nil { diff --git a/dot/parachain/dispute/participation_test.go b/dot/parachain/dispute/participation_test.go index 3c9b99e4b80..c813b45d4f3 100644 --- a/dot/parachain/dispute/participation_test.go +++ b/dot/parachain/dispute/participation_test.go @@ -161,13 +161,16 @@ func participateWithCommitmentsHash( return fmt.Errorf("failed to hash candidate receipt: %w", err) } - participationRequest := ParticipationRequest{ - candidateHash: candidateHash, - candidateReceipt: candidateReceipt, - session: session, + participationData := ParticipationData{ + ParticipationRequest{ + candidateHash: candidateHash, + candidateReceipt: candidateReceipt, + session: session, + }, + ParticipationPriorityBestEffort, } - return participation.Queue(overseerChannel, participationRequest, ParticipationPriorityBestEffort) + return participation.Queue(overseerChannel, participationData) } func TestNewParticipation(t *testing.T) { @@ -200,10 +203,10 @@ func TestParticipationHandler_Queue(t *testing.T) { select { case msg := <-mockOverseer: switch message := msg.(type) { - case overseer.ChainAPIMessage[overseer.BlockNumberRequest]: + case overseer.ChainAPIMessage[overseer.BlockNumber]: response := uint32(1) message.ResponseChannel <- response - case overseer.AvailabilityRecoveryMessage: + case overseer.AvailabilityRecoveryMessage[overseer.RecoverAvailableData]: response := overseer.RecoveryErrorUnavailable message.ResponseChannel <- overseer.AvailabilityRecoveryResponse{ Error: &response, @@ -278,10 +281,10 @@ func TestParticipationHandler_Queue(t *testing.T) { } counter++ switch message := msg.(type) { - case overseer.ChainAPIMessage[overseer.BlockNumberRequest]: + case overseer.ChainAPIMessage[overseer.BlockNumber]: response := uint32(1) message.ResponseChannel <- response - case overseer.AvailabilityRecoveryMessage: + case overseer.AvailabilityRecoveryMessage[overseer.RecoverAvailableData]: response := overseer.RecoveryErrorUnavailable message.ResponseChannel <- overseer.AvailabilityRecoveryResponse{ Error: &response, @@ -341,7 +344,7 @@ func TestParticipationHandler_Queue(t *testing.T) { select { case msg := <-mockOverseer: switch message := msg.(type) { - case overseer.ChainAPIMessage[overseer.BlockNumberRequest]: + case overseer.ChainAPIMessage[overseer.BlockNumber]: response := uint32(1) message.ResponseChannel <- response break @@ -368,7 +371,7 @@ func TestParticipationHandler_Queue(t *testing.T) { case msg := <-mockOverseer: counter++ switch message := msg.(type) { - case overseer.AvailabilityRecoveryMessage: + case overseer.AvailabilityRecoveryMessage[overseer.RecoverAvailableData]: response := overseer.RecoveryErrorUnavailable message.ResponseChannel <- overseer.AvailabilityRecoveryResponse{ Error: &response, @@ -415,10 +418,10 @@ func TestParticipationHandler_Queue(t *testing.T) { select { case msg := <-mockOverseer: switch message := msg.(type) { - case overseer.ChainAPIMessage[overseer.BlockNumberRequest]: + case overseer.ChainAPIMessage[overseer.BlockNumber]: response := uint32(1) message.ResponseChannel <- response - case overseer.AvailabilityRecoveryMessage: + case overseer.AvailabilityRecoveryMessage[overseer.RecoverAvailableData]: response := overseer.RecoveryErrorUnavailable message.ResponseChannel <- overseer.AvailabilityRecoveryResponse{ Error: &response, @@ -460,10 +463,10 @@ func TestParticipationHandler_Queue(t *testing.T) { select { case msg := <-mockOverseer: switch message := msg.(type) { - case overseer.ChainAPIMessage[overseer.BlockNumberRequest]: + case overseer.ChainAPIMessage[overseer.BlockNumber]: response := uint32(1) message.ResponseChannel <- response - case overseer.AvailabilityRecoveryMessage: + case overseer.AvailabilityRecoveryMessage[overseer.RecoverAvailableData]: availableData := overseer.AvailableData{ POV: []byte{}, ValidationData: overseer.PersistedValidationData{}, @@ -522,10 +525,10 @@ func TestParticipationHandler_Queue(t *testing.T) { select { case msg := <-mockOverseer: switch message := msg.(type) { - case overseer.ChainAPIMessage[overseer.BlockNumberRequest]: + case overseer.ChainAPIMessage[overseer.BlockNumber]: response := uint32(1) message.ResponseChannel <- response - case overseer.AvailabilityRecoveryMessage: + case overseer.AvailabilityRecoveryMessage[overseer.RecoverAvailableData]: response := overseer.RecoveryErrorInvalid message.ResponseChannel <- overseer.AvailabilityRecoveryResponse{ Error: &response, @@ -570,17 +573,17 @@ func TestParticipationHandler_Queue(t *testing.T) { select { case msg := <-mockOverseer: switch message := msg.(type) { - case overseer.ChainAPIMessage[overseer.BlockNumberRequest]: + case overseer.ChainAPIMessage[overseer.BlockNumber]: response := uint32(1) message.ResponseChannel <- response - case overseer.ValidateFromChainState: - if message.PvfExecTimeoutKind == overseer.PvfExecTimeoutKindApproval { + case overseer.CandidateValidationMessage[overseer.ValidateFromChainState]: + if message.Data.PvfExecTimeoutKind == overseer.PvfExecTimeoutKindApproval { message.ResponseChannel <- overseer.ValidationResult{ IsValid: false, Error: nil, } } - case overseer.AvailabilityRecoveryMessage: + case overseer.AvailabilityRecoveryMessage[overseer.RecoverAvailableData]: availableData := overseer.AvailableData{ POV: []byte{}, ValidationData: overseer.PersistedValidationData{}, @@ -635,10 +638,10 @@ func TestParticipationHandler_Queue(t *testing.T) { select { case msg := <-mockOverseer: switch message := msg.(type) { - case overseer.ChainAPIMessage[overseer.BlockNumberRequest]: + case overseer.ChainAPIMessage[overseer.BlockNumber]: response := uint32(1) message.ResponseChannel <- response - case overseer.AvailabilityRecoveryMessage: + case overseer.AvailabilityRecoveryMessage[overseer.RecoverAvailableData]: availableData := overseer.AvailableData{ POV: []byte{}, ValidationData: overseer.PersistedValidationData{}, @@ -648,8 +651,8 @@ func TestParticipationHandler_Queue(t *testing.T) { AvailableData: &availableData, Error: nil, } - case overseer.ValidateFromChainState: - if message.PvfExecTimeoutKind == overseer.PvfExecTimeoutKindApproval { + case overseer.CandidateValidationMessage[overseer.ValidateFromChainState]: + if message.Data.PvfExecTimeoutKind == overseer.PvfExecTimeoutKindApproval { message.ResponseChannel <- overseer.ValidationResult{ IsValid: false, Error: nil, @@ -704,10 +707,10 @@ func TestParticipationHandler_Queue(t *testing.T) { select { case msg := <-mockOverseer: switch message := msg.(type) { - case overseer.ChainAPIMessage[overseer.BlockNumberRequest]: + case overseer.ChainAPIMessage[overseer.BlockNumber]: response := uint32(1) message.ResponseChannel <- response - case overseer.AvailabilityRecoveryMessage: + case overseer.AvailabilityRecoveryMessage[overseer.RecoverAvailableData]: availableData := overseer.AvailableData{ POV: []byte{}, ValidationData: overseer.PersistedValidationData{}, @@ -717,8 +720,8 @@ func TestParticipationHandler_Queue(t *testing.T) { AvailableData: &availableData, Error: nil, } - case overseer.ValidateFromChainState: - if message.PvfExecTimeoutKind == overseer.PvfExecTimeoutKindApproval { + case overseer.CandidateValidationMessage[overseer.ValidateFromChainState]: + if message.Data.PvfExecTimeoutKind == overseer.PvfExecTimeoutKindApproval { message.ResponseChannel <- overseer.ValidationResult{ IsValid: true, Error: nil, diff --git a/dot/parachain/dispute/queue_test.go b/dot/parachain/dispute/queue_test.go index 58589a3b5f0..f404220fd9c 100644 --- a/dot/parachain/dispute/queue_test.go +++ b/dot/parachain/dispute/queue_test.go @@ -29,11 +29,14 @@ func newComparator(blockNumber, order uint32) CandidateComparator { } } -func dummyParticipationRequest() *ParticipationRequest { - return &ParticipationRequest{ - candidateHash: [32]byte{}, - candidateReceipt: parachain.CandidateReceipt{}, - session: 1, +func dummyParticipationData(priority ParticipationPriority) ParticipationData { + return ParticipationData{ + ParticipationRequest{ + candidateHash: [32]byte{}, + candidateReceipt: parachain.CandidateReceipt{}, + session: 1, + }, + priority, } } @@ -41,12 +44,11 @@ type test struct { name string // operation one of "queue", "dequeue", "prioritise", "pop_priority", "pop_best_effort", // "len_priority", "len_best_effort" - operation string - comparator CandidateComparator - request *ParticipationRequest - priority ParticipationPriority - expected any - mustError bool + operation string + comparator CandidateComparator + participation ParticipationData + expected any + mustError bool } func runTests(t *testing.T, tests []test, queue Queue) { @@ -55,7 +57,7 @@ func runTests(t *testing.T, tests []test, queue Queue) { t.Run(tt.name, func(t *testing.T) { switch tt.operation { case "queue": - err := queue.Queue(tt.comparator, tt.request, tt.priority) + err := queue.Queue(tt.comparator, tt.participation) if tt.mustError { require.Error(t, err) require.Equal(t, err, tt.expected) @@ -94,41 +96,38 @@ func runTests(t *testing.T, tests []test, queue Queue) { // - queueing 1 request with the best effort priority // - dequeue must return the request with the lowest relay parent block number from the priority queue func TestQueue_CompareRelayParentBlock(t *testing.T) { + expectedParticipation := dummyParticipationData(ParticipationPriorityHigh) tests := []test{ { - name: "block 1", - operation: "queue", - comparator: newComparator(1, 1), - request: dummyParticipationRequest(), - priority: ParticipationPriorityHigh, + name: "block 1", + operation: "queue", + comparator: newComparator(1, 1), + participation: dummyParticipationData(ParticipationPriorityHigh), }, { - name: "block 2", - operation: "queue", - comparator: newComparator(2, 1), - request: dummyParticipationRequest(), - priority: ParticipationPriorityHigh, + name: "block 2", + operation: "queue", + comparator: newComparator(2, 1), + participation: dummyParticipationData(ParticipationPriorityHigh), }, { - name: "block 3", - operation: "queue", - comparator: newComparator(3, 1), - request: dummyParticipationRequest(), - priority: ParticipationPriorityHigh, + name: "block 3", + operation: "queue", + comparator: newComparator(3, 1), + participation: dummyParticipationData(ParticipationPriorityHigh), }, { - name: "block 1 - best effort", - operation: "queue", - comparator: newComparator(1, 1), - request: dummyParticipationRequest(), - priority: ParticipationPriorityBestEffort, + name: "block 1 - best effort", + operation: "queue", + comparator: newComparator(1, 1), + participation: dummyParticipationData(ParticipationPriorityHigh), }, { name: "dequeue", operation: "dequeue", expected: &ParticipationItem{ comparator: newComparator(1, 1), - request: dummyParticipationRequest(), + request: &expectedParticipation.request, }, }, } @@ -141,27 +140,26 @@ func TestQueue_CompareRelayParentBlock(t *testing.T) { // - queueing 1 request with the best effort priority // - dequeue must return the request with the lowest candidate hash from the priority queue func TestQueue_CompareCandidateHash(t *testing.T) { + expectedParticipation := dummyParticipationData(ParticipationPriorityHigh) tests := []test{ { - name: "block 1", - operation: "queue", - comparator: newComparator(1, 1), - request: dummyParticipationRequest(), - priority: ParticipationPriorityHigh, + name: "block 1", + operation: "queue", + comparator: newComparator(1, 1), + participation: dummyParticipationData(ParticipationPriorityHigh), }, { - name: "block 1 - 2", - operation: "queue", - comparator: newComparator(1, 2), - request: dummyParticipationRequest(), - priority: ParticipationPriorityHigh, + name: "block 1 - 2", + operation: "queue", + comparator: newComparator(1, 2), + participation: dummyParticipationData(ParticipationPriorityHigh), }, { name: "dequeue", operation: "dequeue", expected: &ParticipationItem{ comparator: newComparator(1, 1), - request: dummyParticipationRequest(), + request: &expectedParticipation.request, }, }, } @@ -176,48 +174,43 @@ func TestQueue_CompareCandidateHash(t *testing.T) { // - popping the priority queue // - prioritising a request in the best effort queue func TestQueue_EndToEnd(t *testing.T) { + expectedParticipation := dummyParticipationData(ParticipationPriorityHigh) tests := []test{ { - name: "block 1, order 1", - operation: "queue", - comparator: newComparator(1, 1), - request: dummyParticipationRequest(), - priority: ParticipationPriorityHigh, + name: "block 1, order 1", + operation: "queue", + comparator: newComparator(1, 1), + participation: dummyParticipationData(ParticipationPriorityHigh), }, { - name: "block 2, order 1", - operation: "queue", - comparator: newComparator(2, 1), - request: dummyParticipationRequest(), - priority: ParticipationPriorityHigh, + name: "block 2, order 1", + operation: "queue", + comparator: newComparator(2, 1), + participation: dummyParticipationData(ParticipationPriorityHigh), }, { - name: "block 3, order 1", - operation: "queue", - comparator: newComparator(3, 1), - request: dummyParticipationRequest(), - priority: ParticipationPriorityHigh, + name: "block 3, order 1", + operation: "queue", + comparator: newComparator(3, 1), + participation: dummyParticipationData(ParticipationPriorityHigh), }, { - name: "block 1, order 2 - best effort", - operation: "queue", - comparator: newComparator(1, 2), - request: dummyParticipationRequest(), - priority: ParticipationPriorityBestEffort, + name: "block 1, order 2 - best effort", + operation: "queue", + comparator: newComparator(1, 2), + participation: dummyParticipationData(ParticipationPriorityBestEffort), }, { - name: "block 2, order 2 - best effort", - operation: "queue", - comparator: newComparator(2, 2), - request: dummyParticipationRequest(), - priority: ParticipationPriorityBestEffort, + name: "block 2, order 2 - best effort", + operation: "queue", + comparator: newComparator(2, 2), + participation: dummyParticipationData(ParticipationPriorityBestEffort), }, { - name: "block 3, order 2 - best effort", - operation: "queue", - comparator: newComparator(3, 2), - request: dummyParticipationRequest(), - priority: ParticipationPriorityBestEffort, + name: "block 3, order 2 - best effort", + operation: "queue", + comparator: newComparator(3, 2), + participation: dummyParticipationData(ParticipationPriorityBestEffort), }, { name: "priority length", @@ -234,7 +227,7 @@ func TestQueue_EndToEnd(t *testing.T) { operation: "pop_priority", expected: &ParticipationItem{ comparator: newComparator(1, 1), - request: dummyParticipationRequest(), + request: &expectedParticipation.request, }, }, { @@ -242,7 +235,7 @@ func TestQueue_EndToEnd(t *testing.T) { operation: "pop_best_effort", expected: &ParticipationItem{ comparator: newComparator(1, 2), - request: dummyParticipationRequest(), + request: &expectedParticipation.request, }, }, { @@ -270,7 +263,7 @@ func TestQueue_EndToEnd(t *testing.T) { operation: "dequeue", expected: &ParticipationItem{ comparator: newComparator(2, 1), - request: dummyParticipationRequest(), + request: &expectedParticipation.request, }, }, { @@ -278,7 +271,7 @@ func TestQueue_EndToEnd(t *testing.T) { operation: "dequeue", expected: &ParticipationItem{ comparator: newComparator(2, 2), - request: dummyParticipationRequest(), + request: &expectedParticipation.request, }, }, } @@ -292,41 +285,36 @@ func TestQueue_EndToEnd(t *testing.T) { func TestQueue_OverflowPriority(t *testing.T) { tests := []test{ { - name: "block 1", - operation: "queue", - comparator: newComparator(1, 1), - request: dummyParticipationRequest(), - priority: ParticipationPriorityHigh, + name: "block 1", + operation: "queue", + comparator: newComparator(1, 1), + participation: dummyParticipationData(ParticipationPriorityHigh), }, { - name: "block 1 - 2", - operation: "queue", - comparator: newComparator(1, 2), - request: dummyParticipationRequest(), - priority: ParticipationPriorityHigh, + name: "block 1 - 2", + operation: "queue", + comparator: newComparator(1, 2), + participation: dummyParticipationData(ParticipationPriorityHigh), }, { - name: "block 1 - 3", - operation: "queue", - comparator: newComparator(1, 3), - request: dummyParticipationRequest(), - priority: ParticipationPriorityHigh, + name: "block 1 - 3", + operation: "queue", + comparator: newComparator(1, 3), + participation: dummyParticipationData(ParticipationPriorityHigh), }, { - name: "block 1 - 4", - operation: "queue", - comparator: newComparator(1, 4), - request: dummyParticipationRequest(), - priority: ParticipationPriorityHigh, + name: "block 1 - 4", + operation: "queue", + comparator: newComparator(1, 4), + participation: dummyParticipationData(ParticipationPriorityHigh), }, { - name: "block 1 - 5", - operation: "queue", - comparator: newComparator(1, 5), - request: dummyParticipationRequest(), - priority: ParticipationPriorityHigh, - mustError: true, - expected: errorPriorityQueueFull, + name: "block 1 - 5", + operation: "queue", + comparator: newComparator(1, 5), + participation: dummyParticipationData(ParticipationPriorityHigh), + mustError: true, + expected: errorPriorityQueueFull, }, } @@ -339,41 +327,36 @@ func TestQueue_OverflowPriority(t *testing.T) { func TestQueue_OverflowBestEffort(t *testing.T) { tests := []test{ { - name: "block 1", - operation: "queue", - comparator: newComparator(1, 1), - request: dummyParticipationRequest(), - priority: ParticipationPriorityBestEffort, + name: "block 1", + operation: "queue", + comparator: newComparator(1, 1), + participation: dummyParticipationData(ParticipationPriorityBestEffort), }, { - name: "block 1 - 2", - operation: "queue", - comparator: newComparator(1, 2), - request: dummyParticipationRequest(), - priority: ParticipationPriorityBestEffort, + name: "block 1 - 2", + operation: "queue", + comparator: newComparator(1, 2), + participation: dummyParticipationData(ParticipationPriorityBestEffort), }, { - name: "block 1 - 3", - operation: "queue", - comparator: newComparator(1, 3), - request: dummyParticipationRequest(), - priority: ParticipationPriorityBestEffort, + name: "block 1 - 3", + operation: "queue", + comparator: newComparator(1, 3), + participation: dummyParticipationData(ParticipationPriorityBestEffort), }, { - name: "block 1 - 4", - operation: "queue", - comparator: newComparator(1, 4), - request: dummyParticipationRequest(), - priority: ParticipationPriorityBestEffort, + name: "block 1 - 4", + operation: "queue", + comparator: newComparator(1, 4), + participation: dummyParticipationData(ParticipationPriorityBestEffort), }, { - name: "block 1 - 5", - operation: "queue", - comparator: newComparator(1, 5), - request: dummyParticipationRequest(), - priority: ParticipationPriorityBestEffort, - mustError: true, - expected: errorBestEffortQueueFull, + name: "block 1 - 5", + operation: "queue", + comparator: newComparator(1, 5), + participation: dummyParticipationData(ParticipationPriorityBestEffort), + mustError: true, + expected: errorBestEffortQueueFull, }, } @@ -394,7 +377,7 @@ func TestQueueConcurrency_Dequeue(t *testing.T) { go func() { defer wg.Done() - err := q.Queue(newComparator(block, 1), dummyParticipationRequest(), ParticipationPriorityHigh) + err := q.Queue(newComparator(block, 1), dummyParticipationData(ParticipationPriorityHigh)) require.NoError(t, err) }() } @@ -428,7 +411,7 @@ func TestQueueConcurrency_Prioritise(t *testing.T) { go func() { defer wg.Done() - err := q.Queue(newComparator(block, 1), dummyParticipationRequest(), ParticipationPriorityBestEffort) + err := q.Queue(newComparator(block, 1), dummyParticipationData(ParticipationPriorityBestEffort)) require.NoError(t, err) }() } @@ -465,7 +448,7 @@ func TestQueueConcurrency_PopBestEffort(t *testing.T) { go func() { defer wg.Done() - err := q.Queue(newComparator(block, 1), dummyParticipationRequest(), ParticipationPriorityBestEffort) + err := q.Queue(newComparator(block, 1), dummyParticipationData(ParticipationPriorityBestEffort)) require.NoError(t, err) }() } @@ -500,7 +483,7 @@ func TestQueueConcurrency_PopPriority(t *testing.T) { go func() { defer wg.Done() - err := q.Queue(newComparator(block, 1), dummyParticipationRequest(), ParticipationPriorityHigh) + err := q.Queue(newComparator(block, 1), dummyParticipationData(ParticipationPriorityHigh)) require.NoError(t, err) }() } @@ -525,7 +508,7 @@ func BenchmarkQueue_Queue(b *testing.B) { q := newTestQueue(priorityQueueSize) for i := 0; i < priorityQueueSize; i++ { - err := q.Queue(newComparator(uint32(i), 1), dummyParticipationRequest(), ParticipationPriorityHigh) + err := q.Queue(newComparator(uint32(i), 1), dummyParticipationData(ParticipationPriorityHigh)) require.NoError(b, err) } } @@ -534,7 +517,7 @@ func BenchmarkQueue_Dequeue(b *testing.B) { q := NewQueue() for i := 0; i < bestEffortQueueSize; i++ { - err := q.Queue(newComparator(uint32(i), 1), dummyParticipationRequest(), ParticipationPriorityBestEffort) + err := q.Queue(newComparator(uint32(i), 1), dummyParticipationData(ParticipationPriorityBestEffort)) require.NoError(b, err) } b.ResetTimer() @@ -549,7 +532,7 @@ func BenchmarkQueue_PopPriority(b *testing.B) { q := NewQueue() for i := 0; i < priorityQueueSize; i++ { - err := q.Queue(newComparator(uint32(i), 1), dummyParticipationRequest(), ParticipationPriorityHigh) + err := q.Queue(newComparator(uint32(i), 1), dummyParticipationData(ParticipationPriorityHigh)) require.NoError(b, err) } b.ResetTimer() @@ -564,7 +547,7 @@ func BenchmarkQueue_PopBestEffort(b *testing.B) { q := NewQueue() for i := 0; i < bestEffortQueueSize; i++ { - err := q.Queue(newComparator(uint32(i), 1), dummyParticipationRequest(), ParticipationPriorityBestEffort) + err := q.Queue(newComparator(uint32(i), 1), dummyParticipationData(ParticipationPriorityBestEffort)) require.NoError(b, err) } b.ResetTimer() @@ -579,7 +562,7 @@ func BenchmarkQueue_PrioritiseIfPresent(b *testing.B) { q := NewQueue() for i := 0; i < bestEffortQueueSize; i++ { - err := q.Queue(newComparator(uint32(i), 1), dummyParticipationRequest(), ParticipationPriorityBestEffort) + err := q.Queue(newComparator(uint32(i), 1), dummyParticipationData(ParticipationPriorityBestEffort)) require.NoError(b, err) } b.ResetTimer() diff --git a/dot/parachain/dispute/queues.go b/dot/parachain/dispute/queues.go index d648096372d..95aa15fc0a2 100644 --- a/dot/parachain/dispute/queues.go +++ b/dot/parachain/dispute/queues.go @@ -78,7 +78,7 @@ func (p ParticipationPriority) IsPriority() bool { // Queue the dispute participation queue type Queue interface { // Queue adds a new participation request to the queue - Queue(comparator CandidateComparator, request *ParticipationRequest, priority ParticipationPriority) error + Queue(comparator CandidateComparator, participationData ParticipationData) error // Dequeue gets the next best request for dispute participation if any. Dequeue() *ParticipationItem @@ -130,25 +130,24 @@ const ( func (q *QueueHandler) Queue( comparator CandidateComparator, - request *ParticipationRequest, - priority ParticipationPriority, + data ParticipationData, ) error { - if priority.IsPriority() { + if data.priority.IsPriority() { if q.Len(ParticipationPriorityHigh) >= q.priorityMaxSize { return errorPriorityQueueFull } // remove the item from the best effort queue if it exists q.bestEffort.Lock() - q.bestEffort.BTree.Delete(newParticipationItem(comparator, request)) + q.bestEffort.BTree.Delete(newParticipationItem(comparator, &data.request)) q.bestEffort.Unlock() q.priority.Lock() - q.priority.BTree.Set(newParticipationItem(comparator, request)) + q.priority.BTree.Set(newParticipationItem(comparator, &data.request)) q.priority.Unlock() } else { // if the item is already in priority queue, do nothing - if item := q.priority.BTree.Get(newParticipationItem(comparator, request)); item != nil { + if item := q.priority.BTree.Get(newParticipationItem(comparator, &data.request)); item != nil { return nil } @@ -157,7 +156,7 @@ func (q *QueueHandler) Queue( } q.bestEffort.Lock() - q.bestEffort.BTree.Set(newParticipationItem(comparator, request)) + q.bestEffort.BTree.Set(newParticipationItem(comparator, &data.request)) q.bestEffort.Unlock() } diff --git a/dot/parachain/dispute/scraping/comm.go b/dot/parachain/dispute/scraping/comm.go index 7c22419b07d..429b9b7ccd6 100644 --- a/dot/parachain/dispute/scraping/comm.go +++ b/dot/parachain/dispute/scraping/comm.go @@ -12,7 +12,7 @@ const timeout = 10 * time.Second // getFinalisedBlockNumber sends a message to the overseer to get the finalised block number. func getFinalisedBlockNumber(overseerChannel chan<- any) (uint32, error) { - message := overseer.ChainAPIMessage[overseer.FinalizedBlockNumberRequest]{ + message := overseer.ChainAPIMessage[overseer.FinalizedBlockNumber]{ ResponseChannel: make(chan any, 1), } res, err := call(overseerChannel, message, message.ResponseChannel) @@ -39,8 +39,8 @@ func getBlockAncestors( numAncestors uint32, ) ([]common.Hash, error) { respChan := make(chan any, 1) - message := overseer.ChainAPIMessage[overseer.AncestorsRequest]{ - Message: overseer.AncestorsRequest{ + message := overseer.ChainAPIMessage[overseer.Ancestors]{ + Message: overseer.Ancestors{ Hash: head, K: numAncestors, }, diff --git a/dot/parachain/dispute/scraping/mock_runtime_test.go b/dot/parachain/dispute/scraping/mock_runtime_test.go index c0bcbdbd008..986faa9d372 100644 --- a/dot/parachain/dispute/scraping/mock_runtime_test.go +++ b/dot/parachain/dispute/scraping/mock_runtime_test.go @@ -1,7 +1,7 @@ // Code generated by MockGen. DO NOT EDIT. // Source: github.com/ChainSafe/gossamer/dot/parachain/runtime (interfaces: RuntimeInstance) -// Package dispute is a generated GoMock package. +// Package disputes is a generated GoMock package. package scraping import ( diff --git a/dot/parachain/dispute/scraping/scraping_test.go b/dot/parachain/dispute/scraping/scraping_test.go index 9f3f5329f7c..57ed3024a99 100644 --- a/dot/parachain/dispute/scraping/scraping_test.go +++ b/dot/parachain/dispute/scraping/scraping_test.go @@ -118,7 +118,7 @@ func configureMockOverseer( select { case msg := <-overseerChannel: switch request := msg.(type) { - case overseer.ChainAPIMessage[overseer.FinalizedBlockNumberRequest]: + case overseer.ChainAPIMessage[overseer.FinalizedBlockNumber]: require.LessOrEqual(t, finalisedBlockRequestCalls, messages.finalisedBlockRequests) result := finalisedBlock if finalisedBlockRequestCalls == 0 { @@ -131,7 +131,7 @@ func configureMockOverseer( Err: nil, } request.ResponseChannel <- response - case overseer.ChainAPIMessage[overseer.AncestorsRequest]: + case overseer.ChainAPIMessage[overseer.Ancestors]: require.LessOrEqual(t, ancestorRequestCalls, messages.ancestorRequests) ancestorRequestCalls++ maybeBlockPosition := -1 diff --git a/dot/parachain/dispute/spam_slots.go b/dot/parachain/dispute/spam_slots.go index 40ec3ede2a5..e3b81998372 100644 --- a/dot/parachain/dispute/spam_slots.go +++ b/dot/parachain/dispute/spam_slots.go @@ -194,7 +194,7 @@ func NewSpamSlotsFromState(unconfirmedDisputes map[unconfirmedKey]*treeset.Set, key := newSlotsKey(k.session, parachainTypes.ValidatorIndex(validator)) slots[key]++ if slots[key] > maxSpamVotes { - // TODO: improve this after we have a logger for dispute coordinator + // TODO: improve this after we have a logger for disputes coordinator logger.Errorf("Spam count for validator %d in session %d is greater than max spam votes %d", validator, k.session, maxSpamVotes) } diff --git a/dot/parachain/dot/parachain/mocks_runtime_test.go b/dot/parachain/dot/parachain/mocks_runtime_test.go deleted file mode 100644 index 0e3104cdb7a..00000000000 --- a/dot/parachain/dot/parachain/mocks_runtime_test.go +++ /dev/null @@ -1,126 +0,0 @@ -// Code generated by MockGen. DO NOT EDIT. -// Source: github.com/ChainSafe/gossamer/dot/parachain/runtime (interfaces: RuntimeInstance) - -// Package parachain is a generated GoMock package. -package parachain - -import ( - reflect "reflect" - - parachaintypes "github.com/ChainSafe/gossamer/dot/parachain/types" - common "github.com/ChainSafe/gossamer/lib/common" - gomock "github.com/golang/mock/gomock" -) - -// MockRuntimeInstance is a mock of RuntimeInstance interface. -type MockRuntimeInstance struct { - ctrl *gomock.Controller - recorder *MockRuntimeInstanceMockRecorder -} - -// MockRuntimeInstanceMockRecorder is the mock recorder for MockRuntimeInstance. -type MockRuntimeInstanceMockRecorder struct { - mock *MockRuntimeInstance -} - -// NewMockRuntimeInstance creates a new mock instance. -func NewMockRuntimeInstance(ctrl *gomock.Controller) *MockRuntimeInstance { - mock := &MockRuntimeInstance{ctrl: ctrl} - mock.recorder = &MockRuntimeInstanceMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockRuntimeInstance) EXPECT() *MockRuntimeInstanceMockRecorder { - return m.recorder -} - -// ParachainHostCheckValidationOutputs mocks base method. -func (m *MockRuntimeInstance) ParachainHostCheckValidationOutputs(arg0 uint32, arg1 parachaintypes.CandidateCommitments) (bool, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ParachainHostCheckValidationOutputs", arg0, arg1) - ret0, _ := ret[0].(bool) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// ParachainHostCheckValidationOutputs indicates an expected call of ParachainHostCheckValidationOutputs. -func (mr *MockRuntimeInstanceMockRecorder) ParachainHostCheckValidationOutputs(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ParachainHostCheckValidationOutputs", reflect.TypeOf((*MockRuntimeInstance)(nil).ParachainHostCheckValidationOutputs), arg0, arg1) -} - -// ParachainHostPersistedValidationData mocks base method. -func (m *MockRuntimeInstance) ParachainHostPersistedValidationData(arg0 uint32, arg1 parachaintypes.OccupiedCoreAssumption) (*parachaintypes.PersistedValidationData, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ParachainHostPersistedValidationData", arg0, arg1) - ret0, _ := ret[0].(*parachaintypes.PersistedValidationData) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// ParachainHostPersistedValidationData indicates an expected call of ParachainHostPersistedValidationData. -func (mr *MockRuntimeInstanceMockRecorder) ParachainHostPersistedValidationData(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ParachainHostPersistedValidationData", reflect.TypeOf((*MockRuntimeInstance)(nil).ParachainHostPersistedValidationData), arg0, arg1) -} - -// ParachainHostSessionIndexForChild mocks base method. -func (m *MockRuntimeInstance) ParachainHostSessionIndexForChild(arg0 common.Hash) (parachaintypes.SessionIndex, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ParachainHostSessionIndexForChild", arg0) - ret0, _ := ret[0].(parachaintypes.SessionIndex) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// ParachainHostSessionIndexForChild indicates an expected call of ParachainHostSessionIndexForChild. -func (mr *MockRuntimeInstanceMockRecorder) ParachainHostSessionIndexForChild(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ParachainHostSessionIndexForChild", reflect.TypeOf((*MockRuntimeInstance)(nil).ParachainHostSessionIndexForChild), arg0) -} - -// ParachainHostSessionInfo mocks base method. -func (m *MockRuntimeInstance) ParachainHostSessionInfo(arg0 common.Hash, arg1 parachaintypes.SessionIndex) (*parachaintypes.SessionInfo, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ParachainHostSessionInfo", arg0, arg1) - ret0, _ := ret[0].(*parachaintypes.SessionInfo) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// ParachainHostSessionInfo indicates an expected call of ParachainHostSessionInfo. -func (mr *MockRuntimeInstanceMockRecorder) ParachainHostSessionInfo(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ParachainHostSessionInfo", reflect.TypeOf((*MockRuntimeInstance)(nil).ParachainHostSessionInfo), arg0, arg1) -} - -// ParachainHostValidationCode mocks base method. -func (m *MockRuntimeInstance) ParachainHostValidationCode(arg0 uint32, arg1 parachaintypes.OccupiedCoreAssumption) (*parachaintypes.ValidationCode, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ParachainHostValidationCode", arg0, arg1) - ret0, _ := ret[0].(*parachaintypes.ValidationCode) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// ParachainHostValidationCode indicates an expected call of ParachainHostValidationCode. -func (mr *MockRuntimeInstanceMockRecorder) ParachainHostValidationCode(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ParachainHostValidationCode", reflect.TypeOf((*MockRuntimeInstance)(nil).ParachainHostValidationCode), arg0, arg1) -} - -// ParachainHostValidationCodeByHash mocks base method. -func (m *MockRuntimeInstance) ParachainHostValidationCodeByHash(arg0 common.Hash, arg1 parachaintypes.ValidationCodeHash) (*parachaintypes.ValidationCode, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ParachainHostValidationCodeByHash", arg0, arg1) - ret0, _ := ret[0].(*parachaintypes.ValidationCode) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// ParachainHostValidationCodeByHash indicates an expected call of ParachainHostValidationCodeByHash. -func (mr *MockRuntimeInstanceMockRecorder) ParachainHostValidationCodeByHash(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ParachainHostValidationCodeByHash", reflect.TypeOf((*MockRuntimeInstance)(nil).ParachainHostValidationCodeByHash), arg0, arg1) -} diff --git a/dot/parachain/mock_runtime_test.go b/dot/parachain/mock_runtime_test.go index d9614670168..22881292836 100644 --- a/dot/parachain/mock_runtime_test.go +++ b/dot/parachain/mock_runtime_test.go @@ -1,7 +1,7 @@ // Code generated by MockGen. DO NOT EDIT. // Source: github.com/ChainSafe/gossamer/dot/parachain/runtime (interfaces: RuntimeInstance) -// Package parachain is a generated GoMock package. +// Package disputes is a generated GoMock package. package parachain import ( @@ -96,6 +96,36 @@ func (mr *MockRuntimeInstanceMockRecorder) ParachainHostPersistedValidationData( return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ParachainHostPersistedValidationData", reflect.TypeOf((*MockRuntimeInstance)(nil).ParachainHostPersistedValidationData), arg0, arg1) } +// ParachainHostSessionIndexForChild mocks base method. +func (m *MockRuntimeInstance) ParachainHostSessionIndexForChild(arg0 common.Hash) (parachaintypes.SessionIndex, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ParachainHostSessionIndexForChild", arg0) + ret0, _ := ret[0].(parachaintypes.SessionIndex) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ParachainHostSessionIndexForChild indicates an expected call of ParachainHostSessionIndexForChild. +func (mr *MockRuntimeInstanceMockRecorder) ParachainHostSessionIndexForChild(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ParachainHostSessionIndexForChild", reflect.TypeOf((*MockRuntimeInstance)(nil).ParachainHostSessionIndexForChild), arg0) +} + +// ParachainHostSessionInfo mocks base method. +func (m *MockRuntimeInstance) ParachainHostSessionInfo(arg0 common.Hash, arg1 parachaintypes.SessionIndex) (*parachaintypes.SessionInfo, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ParachainHostSessionInfo", arg0, arg1) + ret0, _ := ret[0].(*parachaintypes.SessionInfo) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ParachainHostSessionInfo indicates an expected call of ParachainHostSessionInfo. +func (mr *MockRuntimeInstanceMockRecorder) ParachainHostSessionInfo(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ParachainHostSessionInfo", reflect.TypeOf((*MockRuntimeInstance)(nil).ParachainHostSessionInfo), arg0, arg1) +} + // ParachainHostValidationCode mocks base method. func (m *MockRuntimeInstance) ParachainHostValidationCode(arg0 uint32, arg1 parachaintypes.OccupiedCoreAssumption) (*parachaintypes.ValidationCode, error) { m.ctrl.T.Helper() diff --git a/dot/parachain/pov_fetching.go b/dot/parachain/pov_fetching.go index 6ee7c300d38..7942bbda722 100644 --- a/dot/parachain/pov_fetching.go +++ b/dot/parachain/pov_fetching.go @@ -6,7 +6,6 @@ package parachain import ( "fmt" parachaintypes "github.com/ChainSafe/gossamer/dot/parachain/types" - "github.com/ChainSafe/gossamer/pkg/scale" ) diff --git a/dot/state/storage_notify.go b/dot/state/storage_notify.go index ef3f327c7bc..45cf810f06c 100644 --- a/dot/state/storage_notify.go +++ b/dot/state/storage_notify.go @@ -18,7 +18,7 @@ type KeyValue struct { } func (kv KeyValue) String() string { - return fmt.Sprintf("{Key: 0x%x, BTree: 0x%x}", kv.Key, kv.Value) + return fmt.Sprintf("{Key: 0x%x, Value: 0x%x}", kv.Key, kv.Value) } // SubscriptionResult holds results of storage changes diff --git a/lib/babe/inherents/parachain_inherents_test.go b/lib/babe/inherents/parachain_inherents_test.go index 00ddbd30ed3..9bec5a75b2b 100644 --- a/lib/babe/inherents/parachain_inherents_test.go +++ b/lib/babe/inherents/parachain_inherents_test.go @@ -28,12 +28,12 @@ func TestValidDisputeStatementKind(t *testing.T) { }, { name: "BackingSeconded", - enumValue: backingSeconded(common.Hash{1}), + enumValue: BackingSeconded(common.Hash{1}), encodingValue: []byte{0x1, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, //nolint:lll }, { name: "BackingValid", - enumValue: backingValid(common.Hash{1}), + enumValue: BackingValid(common.Hash{1}), encodingValue: []byte{0x2, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, //nolint:lll }, @@ -50,7 +50,7 @@ func TestValidDisputeStatementKind(t *testing.T) { t.Parallel() vdsKind, err := scale.NewVaryingDataType( - ExplicitValidDisputeStatementKind{}, backingSeconded{}, backingValid{}, ApprovalChecking{}) + ExplicitValidDisputeStatementKind{}, BackingSeconded{}, BackingValid{}, ApprovalChecking{}) require.NoError(t, err) err = vdsKind.Set(c.enumValue) @@ -111,7 +111,7 @@ func TestDisputeStatement(t *testing.T) { name: "Valid_Explicit", vdtBuilder: func(t *testing.T) DisputeStatement { vdsKind, err := scale.NewVaryingDataType( - ExplicitValidDisputeStatementKind{}, backingSeconded{}, backingValid{}, ApprovalChecking{}) + ExplicitValidDisputeStatementKind{}, BackingSeconded{}, BackingValid{}, ApprovalChecking{}) require.NoError(t, err) err = vdsKind.Set(ExplicitValidDisputeStatementKind{}) @@ -130,7 +130,7 @@ func TestDisputeStatement(t *testing.T) { name: "Valid_ApprovalChecking", vdtBuilder: func(t *testing.T) DisputeStatement { vdsKind, err := scale.NewVaryingDataType( - ExplicitValidDisputeStatementKind{}, backingSeconded{}, backingValid{}, ApprovalChecking{}, + ExplicitValidDisputeStatementKind{}, BackingSeconded{}, BackingValid{}, ApprovalChecking{}, ) require.NoError(t, err) @@ -149,11 +149,11 @@ func TestDisputeStatement(t *testing.T) { name: "Valid_BackingSeconded", vdtBuilder: func(t *testing.T) DisputeStatement { vdsKind, err := scale.NewVaryingDataType( - ExplicitValidDisputeStatementKind{}, backingSeconded{}, backingValid{}, ApprovalChecking{}, + ExplicitValidDisputeStatementKind{}, BackingSeconded{}, BackingValid{}, ApprovalChecking{}, ) require.NoError(t, err) - err = vdsKind.Set(backingSeconded(common.Hash{})) + err = vdsKind.Set(BackingSeconded(common.Hash{})) require.NoError(t, err) ds := NewDisputeStatement() diff --git a/pkg/scale/varying_data_type_nested_example_test.go b/pkg/scale/varying_data_type_nested_example_test.go index 29155db2778..107802b67ce 100644 --- a/pkg/scale/varying_data_type_nested_example_test.go +++ b/pkg/scale/varying_data_type_nested_example_test.go @@ -27,7 +27,7 @@ func (pvdt *ParentVDT) Set(val scale.VaryingDataTypeValue) (err error) { return } -// BTree will return value from underying VaryingDataType +// Value will return value from underying VaryingDataType func (pvdt *ParentVDT) Value() (val scale.VaryingDataTypeValue, err error) { vdt := scale.VaryingDataType(*pvdt) return vdt.Value() @@ -73,7 +73,7 @@ func (cvdt *ChildVDT) Set(val scale.VaryingDataTypeValue) (err error) { //skipcq return } -// BTree will return value from underying VaryingDataType +// Value will return value from underying VaryingDataType func (cvdt *ChildVDT) Value() (val scale.VaryingDataTypeValue, err error) { //skipcq: GO-W1029 vdt := scale.VaryingDataType(*cvdt) return vdt.Value() @@ -181,20 +181,20 @@ func Example() { panic(err) } - // validate ParentVDT.BTree() + // validate ParentVDT.Value() parentVal, err := parent.Value() if err != nil { panic(err) } - fmt.Printf("parent.BTree(): %+v\n", parentVal) + fmt.Printf("parent.Value(): %+v\n", parentVal) // should cast to ChildVDT, since that was set earlier valChildVDT := parentVal.(ChildVDT) - // validate ChildVDT.BTree() as ChildInt16(888) + // validate ChildVDT.Value() as ChildInt16(888) childVdtValue, err := valChildVDT.Value() if err != nil { panic(err) } - fmt.Printf("child.BTree(): %+v\n", childVdtValue) + fmt.Printf("child.Value(): %+v\n", childVdtValue) // marshal into scale encoded bytes bytes, err := scale.Marshal(parent) @@ -213,8 +213,8 @@ func Example() { fmt.Println(reflect.DeepEqual(parent, dstParent)) // Output: - // parent.BTree(): ChildVDT(ChildInt16(888)) - // child.BTree(): ChildInt16(888) + // parent.Value(): ChildVDT(ChildInt16(888)) + // child.Value(): ChildInt16(888) // bytes: 01 01 78 03 // true }