Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
kanishkatn committed Sep 18, 2023
1 parent 78a3a63 commit 8b67d3a
Show file tree
Hide file tree
Showing 9 changed files with 187 additions and 21 deletions.
33 changes: 32 additions & 1 deletion dot/parachain/dispute/mock_runtime_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion dot/parachain/dispute/mocks_generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@

package dispute

//go:generate mockgen -destination=mocks_test.go -package=$GOPACKAGE . PoVRequestor
//go:generate mockgen -destination=mock_runtime_test.go -package $GOPACKAGE github.com/ChainSafe/gossamer/dot/parachain/runtime RuntimeInstance
127 changes: 127 additions & 0 deletions dot/parachain/dispute/scraping/mock_runtime_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions dot/parachain/dispute/scraping/mocks_generate_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright 2023 ChainSafe Systems (ON)
// SPDX-License-Identifier: LGPL-3.0-only

package scraping

//go:generate mockgen -destination=mock_runtime_test.go -package $GOPACKAGE github.com/ChainSafe/gossamer/dot/parachain/runtime RuntimeInstance
5 changes: 3 additions & 2 deletions dot/parachain/dispute/scraping/scraping.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const (
AncestryChunkSize = uint32(10)

// AncestrySizeLimit Limits the overall number of ancestors walked through for a given head.
AncestrySizeLimit = int(500) // TODO: This should be a MaxFinalityLag
AncestrySizeLimit = int(500) // TODO: This should be MaxFinalityLag

// LRUObservedBlocksCapacity Number of hashes to keep in the LRU cache.
LRUObservedBlocksCapacity = 20
Expand Down Expand Up @@ -224,7 +224,7 @@ func (cs *ChainScraper) IsPotentialSpam(voteState types.CandidateVoteState, cand
isBacked := cs.IsCandidateBacked(candidateHash)
isConfirmed, err := voteState.IsConfirmed()
if err != nil {
return false, fmt.Errorf("is confirmed: %w", err)
return false, fmt.Errorf("checking if the vote state is confirmed: %w", err)
}

return isDisputed && !isIncluded && !isBacked && !isConfirmed, nil
Expand Down Expand Up @@ -255,6 +255,7 @@ func NewChainScraper(
return chainScraper, updates, nil
}

// getFinalisedBlockNumber sends a message to the overseer to get the finalised block number.
func getFinalisedBlockNumber(sender overseer.Sender) (uint32, error) {
tx := make(chan overseer.FinalizedBlockNumberResponse, 1)
message := overseer.FinalizedBlockNumberRequest{
Expand Down
21 changes: 10 additions & 11 deletions dot/parachain/dispute/scraping/scraping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"testing"

"github.com/ChainSafe/gossamer/dot/parachain"
"github.com/ChainSafe/gossamer/dot/parachain/dispute"
"github.com/ChainSafe/gossamer/dot/parachain/dispute/overseer"
parachainTypes "github.com/ChainSafe/gossamer/dot/parachain/types"
Expand Down Expand Up @@ -248,7 +247,7 @@ func mockCandidateEvents(blockHash common.Hash, chain *[]common.Hash) (*scale.Va
}

func configureMockRuntime(
runtime *parachain.MockRuntimeInstance,
runtime *MockRuntimeInstance,
chain *[]common.Hash,
calls expectedRuntimeCalls,
eventGenerator func(blockHash common.Hash, chain *[]common.Hash) (*scale.VaryingDataTypeSlice, error),
Expand Down Expand Up @@ -278,7 +277,7 @@ func configureMockRuntime(
func newTestState(
t *testing.T,
sender *overseer.MockSender,
runtime *parachain.MockRuntimeInstance,
runtime *MockRuntimeInstance,
messages expectedMessages,
calls expectedRuntimeCalls,
finalisedBlock uint32,
Expand All @@ -299,7 +298,7 @@ func TestChainScraper(t *testing.T) {
t.Run("scraper_provides_included_state_when_initialised", func(t *testing.T) {
t.Parallel()
ctrl := gomock.NewController(t)
mockRuntime := parachain.NewMockRuntimeInstance(ctrl)
mockRuntime := NewMockRuntimeInstance(ctrl)
mockSender := overseer.NewMockSender(ctrl)

candidate1, err := dispute.DummyCandidateReceipt(dispute.GetBlockNumberHash(1)).Hash()
Expand Down Expand Up @@ -340,7 +339,7 @@ func TestChainScraper(t *testing.T) {
const BlocksToSkip = 30

ctrl := gomock.NewController(t)
mockRuntime := parachain.NewMockRuntimeInstance(ctrl)
mockRuntime := NewMockRuntimeInstance(ctrl)
mockSender := overseer.NewMockSender(ctrl)

finalisedBlock := uint32(0)
Expand Down Expand Up @@ -370,7 +369,7 @@ func TestChainScraper(t *testing.T) {
var BlocksToSkip = []int{30, 15}

ctrl := gomock.NewController(t)
mockRuntime := parachain.NewMockRuntimeInstance(ctrl)
mockRuntime := NewMockRuntimeInstance(ctrl)
mockSender := overseer.NewMockSender(ctrl)

finalisedBlock := uint32(0)
Expand Down Expand Up @@ -399,7 +398,7 @@ func TestChainScraper(t *testing.T) {
const BlocksToSkip = 30

ctrl := gomock.NewController(t)
mockRuntime := parachain.NewMockRuntimeInstance(ctrl)
mockRuntime := NewMockRuntimeInstance(ctrl)
mockSender := overseer.NewMockSender(ctrl)

finalisedBlock := uint32(17)
Expand All @@ -425,7 +424,7 @@ func TestChainScraper(t *testing.T) {
)

ctrl := gomock.NewController(t)
mockRuntime := parachain.NewMockRuntimeInstance(ctrl)
mockRuntime := NewMockRuntimeInstance(ctrl)
mockSender := overseer.NewMockSender(ctrl)

finalisedBlock := uint32(1)
Expand Down Expand Up @@ -475,7 +474,7 @@ func TestChainScraper(t *testing.T) {
)

ctrl := gomock.NewController(t)
mockRuntime := parachain.NewMockRuntimeInstance(ctrl)
mockRuntime := NewMockRuntimeInstance(ctrl)
mockSender := overseer.NewMockSender(ctrl)

finalisedBlock := uint32(1)
Expand Down Expand Up @@ -532,7 +531,7 @@ func TestChainScraper(t *testing.T) {
const BlocksToSkip = 3

ctrl := gomock.NewController(t)
mockRuntime := parachain.NewMockRuntimeInstance(ctrl)
mockRuntime := NewMockRuntimeInstance(ctrl)
mockSender := overseer.NewMockSender(ctrl)

finalisedBlock := uint32(1)
Expand Down Expand Up @@ -595,7 +594,7 @@ func TestChainScraper(t *testing.T) {
const BlocksToSkip = 4

ctrl := gomock.NewController(t)
mockRuntime := parachain.NewMockRuntimeInstance(ctrl)
mockRuntime := NewMockRuntimeInstance(ctrl)
mockSender := overseer.NewMockSender(ctrl)

finalisedBlock := uint32(1)
Expand Down
3 changes: 2 additions & 1 deletion dot/parachain/dispute/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,11 @@ func activateLeaf(
}

func GetBlockNumberHash(blockNumber parachainTypes.BlockNumber) common.Hash {
encodedBlockNumber, err := blockNumber.Encode()
encodedBlockNumber, err := scale.Marshal(blockNumber)
if err != nil {
panic("failed to encode block number:" + err.Error())
}

blockHash, err := common.Blake2bHash(encodedBlockNumber)
if err != nil {
panic("failed to hash block number:" + err.Error())
Expand Down
8 changes: 7 additions & 1 deletion dot/parachain/types/scraping.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,29 @@ import (
"github.com/ChainSafe/gossamer/lib/common"
)

// BackingValidators backing validators for a candidate
type BackingValidators struct {
ValidatorIndex ValidatorIndex
ValidityAttestation inherents.ValidityAttestation
}

// BackingValidatorsPerCandidate Set of backing validators for each candidate, represented by its candidate receipt.
type BackingValidatorsPerCandidate struct {
CandidateReceipt common.Hash
BackingValidators []BackingValidators
}

// ScrapedOnChainVotes scraped runtime backing votes and resolved disputes
type ScrapedOnChainVotes struct {
Session SessionIndex
BackingValidators BackingValidatorsPerCandidate
Disputes inherents.MultiDisputeStatementSet
}

// ScrapedUpdates Updates to `OnChainVotes` and included receipts for new active leaf and its unprocessed ancestors.
type ScrapedUpdates struct {
OnChainVotes []ScrapedOnChainVotes
// New votes as seen on chain
OnChainVotes []ScrapedOnChainVotes
// Newly included parachain block candidate receipts as seen on chain
IncludedReceipts []CandidateReceipt
}
4 changes: 0 additions & 4 deletions dot/parachain/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ type ValidatorID [sr25519.PublicKeyLength]byte
// BlockNumber The block number type.
type BlockNumber uint32

func (b BlockNumber) Encode() ([]byte, error) {
return scale.Marshal(&b)
}

// GroupRotationInfo A helper data-type for tracking validator-group rotations.
type GroupRotationInfo struct {
// SessionStartBlock is the block number at which the session started
Expand Down

0 comments on commit 8b67d3a

Please sign in to comment.