Skip to content

Commit

Permalink
Implemented extra parachain host runtime API calls (#3237)
Browse files Browse the repository at this point in the history
Implemented following parachain host runtime calls
- ParachainHost_persisted_validation_data
- ParachainHost_validation_code
  • Loading branch information
kishansagathiya authored Jul 27, 2023
1 parent 4389c37 commit 507231f
Show file tree
Hide file tree
Showing 16 changed files with 487 additions and 5 deletions.
30 changes: 30 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.

30 changes: 30 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.

30 changes: 30 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.

30 changes: 30 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.

30 changes: 30 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.

30 changes: 30 additions & 0 deletions lib/grandpa/mocks_runtime_test.go

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

8 changes: 4 additions & 4 deletions lib/parachain/approval_distribution_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
type AssignmentCertKind scale.VaryingDataType

// New will enable scale to create new instance when needed
func (ack AssignmentCertKind) New() AssignmentCertKind {
func (AssignmentCertKind) New() AssignmentCertKind {
return NewAssignmentCertKindVDT()
}

Expand Down Expand Up @@ -77,7 +77,7 @@ func NewVRFDelay() RelayVRFDelay {
}

// Index returns varying data type index
func (rvd RelayVRFDelay) Index() uint {
func (RelayVRFDelay) Index() uint {
return 1
}

Expand Down Expand Up @@ -121,7 +121,7 @@ type Assignment struct {
type Assignments []Assignment

// Index returns varying data type index
func (a Assignments) Index() uint {
func (Assignments) Index() uint {
return 0
}

Expand All @@ -141,7 +141,7 @@ type IndirectSignedApprovalVote struct {
type Approvals []IndirectSignedApprovalVote

// Index returns varying data type index
func (ap Approvals) Index() uint {
func (Approvals) Index() uint {
return 1
}

Expand Down
79 changes: 79 additions & 0 deletions lib/parachain/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,3 +389,82 @@ func NewCandidateEvents() (scale.VaryingDataTypeSlice, error) {

return scale.NewVaryingDataTypeSlice(vdt), nil
}

// PersistedValidationData should be relatively lightweight primarily because it is constructed
// during inclusion for each candidate and therefore lies on the critical path of inclusion.
type PersistedValidationData struct {
ParentHead HeadData `scale:"1"`
RelayParentNumber uint32 `scale:"2"`
RelayParentStorageRoot common.Hash `scale:"3"`
MaxPovSize uint32 `scale:"4"`
}

// OccupiedCoreAssumption is an assumption being made about the state of an occupied core.
type OccupiedCoreAssumption scale.VaryingDataType

// Set will set a VaryingDataTypeValue using the underlying VaryingDataType
func (o *OccupiedCoreAssumption) Set(val scale.VaryingDataTypeValue) (err error) {
// cast to VaryingDataType to use VaryingDataType.Set method
vdt := scale.VaryingDataType(*o)
err = vdt.Set(val)
if err != nil {
return fmt.Errorf("setting value to varying data type: %w", err)
}
// store original ParentVDT with VaryingDataType that has been set
*o = OccupiedCoreAssumption(vdt)
return nil
}

// Value will return value from underying VaryingDataType
func (o *OccupiedCoreAssumption) Value() (scale.VaryingDataTypeValue, error) {
vdt := scale.VaryingDataType(*o)
return vdt.Value()
}

// IncludedOccupiedCoreAssumption means the candidate occupying the core was made available and
// included to free the core.
type IncludedOccupiedCoreAssumption struct{}

// Index returns VDT index
func (IncludedOccupiedCoreAssumption) Index() uint {
return 0
}

func (IncludedOccupiedCoreAssumption) String() string {
return "Included"
}

// TimedOutOccupiedCoreAssumption means the candidate occupying the core timed out and freed the
// core without advancing the para.
type TimedOutOccupiedCoreAssumption struct{}

// Index returns VDT index
func (TimedOutOccupiedCoreAssumption) Index() uint {
return 1
}

func (TimedOutOccupiedCoreAssumption) String() string {
return "TimedOut"
}

// FreeOccupiedCoreAssumption means the core was not occupied to begin with.
type FreeOccupiedCoreAssumption struct{}

// Index returns VDT index
func (FreeOccupiedCoreAssumption) Index() uint {
return 2
}

func (FreeOccupiedCoreAssumption) String() string {
return "Free"
}

// NewOccupiedCoreAssumption creates a OccupiedCoreAssumption varying data type.
func NewOccupiedCoreAssumption() OccupiedCoreAssumption {
vdt := scale.MustNewVaryingDataType(
IncludedOccupiedCoreAssumption{},
FreeOccupiedCoreAssumption{},
TimedOutOccupiedCoreAssumption{})

return OccupiedCoreAssumption(vdt)
}
Loading

0 comments on commit 507231f

Please sign in to comment.