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

[WIP] feat/parachain: disputes coordinator #3347

Closed
wants to merge 42 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
1f1367e
add queue
kanishkatn Jun 13, 2023
8847198
use rwmutex
kanishkatn Jul 5, 2023
3e99781
add tests
kanishkatn Aug 21, 2023
6ea2c83
add backend
kanishkatn Jun 19, 2023
94e6d14
resolve rebase issues
kanishkatn Aug 2, 2023
90b3cf0
cleanup
kanishkatn Aug 18, 2023
f1811e1
cleanup
kanishkatn Aug 23, 2023
115463a
add imports
kanishkatn Jun 21, 2023
466a526
resolve rebase issues
kanishkatn Aug 2, 2023
c4820ea
fix rebase issues
kanishkatn Sep 18, 2023
c253c9d
add queue
kanishkatn Jun 13, 2023
5bf6f08
add tests
kanishkatn Aug 21, 2023
f0e3d0a
add backend
kanishkatn Jun 19, 2023
ddcee28
resolve rebase issues
kanishkatn Aug 2, 2023
018af5f
cleanup
kanishkatn Aug 18, 2023
9b5ec4a
cleanup
kanishkatn Aug 23, 2023
b36b7e4
add lru cache
kanishkatn Jul 31, 2023
04b61b1
add candidates
kanishkatn Jul 31, 2023
d07ad8d
add scrapper
kanishkatn Aug 1, 2023
8e4b832
use lrucache from lib
kanishkatn Aug 4, 2023
dca5889
init scraper
kanishkatn Aug 10, 2023
0ccd628
replace google btree
kanishkatn Aug 11, 2023
64e8cb1
resolve rebase issues
kanishkatn Aug 23, 2023
42db003
handle todos
kanishkatn Aug 28, 2023
78a3a63
add tests
kanishkatn Aug 29, 2023
ec48cc9
cleanup
kanishkatn Sep 14, 2023
f1b2e72
add queue
kanishkatn Jun 13, 2023
f3f5794
add backend
kanishkatn Jun 19, 2023
203333b
resolve rebase issues
kanishkatn Aug 2, 2023
ce83314
add lru cache
kanishkatn Jul 31, 2023
d316c18
use lrucache from lib
kanishkatn Aug 4, 2023
b558f8d
add spam slots
kanishkatn Jun 21, 2023
968d248
make thread safe, add tests
kanishkatn Jun 27, 2023
8e7aeb5
add benchmark
kanishkatn Jun 28, 2023
af73bb3
review suggestions
kanishkatn Jul 3, 2023
ae41f35
lint
kanishkatn Jul 5, 2023
137ede1
lint, review suggestions
kanishkatn Jul 5, 2023
9e7b234
add disputes coordinator
kanishkatn Jun 20, 2023
b4c444f
resolve rebase issues
kanishkatn Sep 19, 2023
b97f834
process onchain votes
kanishkatn Sep 28, 2023
84845cc
handle incoming
kanishkatn Sep 28, 2023
c327608
finish processors
kanishkatn Oct 5, 2023
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
Prev Previous commit
Next Next commit
cleanup
kanishkatn committed Sep 18, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit ec48cc94cad382c76314b28072251d748ccdebee
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
@@ -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
@@ -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
@@ -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
@@ -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{
21 changes: 10 additions & 11 deletions dot/parachain/dispute/scraping/scraping_test.go
Original file line number Diff line number Diff line change
@@ -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"
@@ -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),
@@ -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,
@@ -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()
@@ -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)
@@ -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)
@@ -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)
@@ -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)
@@ -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)
@@ -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)
@@ -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)
3 changes: 2 additions & 1 deletion dot/parachain/dispute/test_helpers.go
Original file line number Diff line number Diff line change
@@ -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())
187 changes: 0 additions & 187 deletions dot/parachain/dispute/types/cover

This file was deleted.

8 changes: 7 additions & 1 deletion dot/parachain/types/scraping.go
Original file line number Diff line number Diff line change
@@ -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
@@ -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