Skip to content

Commit

Permalink
feat: introduce ParachainHost_disputes runtime call (#4554)
Browse files Browse the repository at this point in the history
  • Loading branch information
EclesioMeloJunior authored Feb 24, 2025
1 parent ff2940b commit d4424ff
Show file tree
Hide file tree
Showing 25 changed files with 1,836 additions and 1,539 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ jobs:
go-version: "1.23.2"
stable: true
check-latest: true

- name: Install latest nightly
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
override: true
default: true
components: rustfmt, clippy

- name: Set cache variables
id: go-cache-paths
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/mocks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ jobs:
stable: true
check-latest: true

- name: Install latest nightly
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
override: true
default: true
components: rustfmt, clippy

- run: go install go.uber.org/mock/mockgen@v0.4.0

- name: Check devnet module
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ jobs:
stable: true
check-latest: true

- name: Install latest nightly
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
override: true
default: true
components: rustfmt, clippy

- name: Set cache variables
id: go-cache-paths
run: |
Expand Down
15 changes: 15 additions & 0 deletions dot/core/mock_runtime_instance_test.go

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

15 changes: 15 additions & 0 deletions dot/parachain/availability-store/mock_runtime_instance_test.go

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

15 changes: 15 additions & 0 deletions dot/parachain/backing/mocks_runtime_test.go

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

15 changes: 15 additions & 0 deletions dot/parachain/candidate-validation/mocks_instance_test.go

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

15 changes: 15 additions & 0 deletions dot/parachain/overseer/mock_parachain_instance_test.go

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

15 changes: 15 additions & 0 deletions dot/parachain/overseer/mock_runtime_instance_test.go

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

33 changes: 33 additions & 0 deletions dot/parachain/provisioner/prioritized_disputes_selection.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package provisioner

import (
"fmt"

parachain "github.com/ChainSafe/gossamer/dot/parachain/runtime"
parachaintypes "github.com/ChainSafe/gossamer/dot/parachain/types"
"github.com/ChainSafe/gossamer/lib/common"
)

type BlockState interface {
GetRuntime(blockHash common.Hash) (instance parachain.RuntimeInstance, err error)
}

// GetOnchainDisputes gets the on-chain disputes at a given block number and returns them as a map
// for efficient searching. It takes a relay parent hash and returns a map of session index and
// candidate hash tuples to dispute states.
func GetOnchainDisputes(
blockstate BlockState,
relayParent common.Hash,
) (map[parachaintypes.DisputeKey]parachaintypes.DisputeState, error) {
rt, err := blockstate.GetRuntime(relayParent)
if err != nil {
return nil, fmt.Errorf("getting runtime for relay parent %s: %w", relayParent, err)
}

disputes, err := rt.ParachainHostDisputes()
if err != nil {
return nil, fmt.Errorf("getting disputes from runtime: %w", err)
}

return disputes, nil
}
1 change: 1 addition & 0 deletions dot/parachain/runtime/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ type RuntimeInstance interface {
ParachainHostCandidateEvents() ([]parachaintypes.CandidateEvent, error)
ParachainHostSessionIndexForChild() (parachaintypes.SessionIndex, error)
ParachainHostSessionExecutorParams(index parachaintypes.SessionIndex) (*parachaintypes.ExecutorParams, error)
ParachainHostDisputes() (map[parachaintypes.DisputeKey]parachaintypes.DisputeState, error)
}

type RuntimeAPIMessage struct {
Expand Down
26 changes: 25 additions & 1 deletion dot/parachain/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,31 @@ type CandidateHashAndRelayParent struct {
CandidateRelayParent common.Hash
}

// validator represents local validator information.
// DisputeKey identifies a single dispute
// under polkadot-sdk the same representation is
// a tuple of (SessionIndex, CandidateHash)
type DisputeKey struct {
SessionIndex SessionIndex
CandidateHash CandidateHash
}

// DisputeState is stored by the runtime
// and represents the entire dispute state
type DisputeState struct {
// A bitfield indicating all validators for the candidate.
ValidatorsFor BitVec

// A bitfield indicating all validators against the candidate.
ValidatorsAgainst BitVec

// The block number at which the dispute started on-chain.
Start BlockNumber

// The block number at which the dispute concluded on-chain.
ConcludedAt *BlockNumber
}

// Validator represents local validator information.
// It can be created if the local node is a validator in the context of a particular relay chain block.
type Validator struct {
SigningContext SigningContext
Expand Down
15 changes: 15 additions & 0 deletions dot/state/mocks_runtime_test.go

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

15 changes: 15 additions & 0 deletions dot/sync/mock_runtime_test.go

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

15 changes: 15 additions & 0 deletions lib/babe/mocks/runtime.go

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

15 changes: 15 additions & 0 deletions lib/blocktree/mocks_test.go

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

Loading

0 comments on commit d4424ff

Please sign in to comment.