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

feat/runtime: Add few parachain runtime calls #3241

Merged
merged 75 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from 73 commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
10f6e6b
add ParachainHostValidators to runtime
kanishkatn Apr 19, 2023
0b78f37
add ParachainHostValidatorGroups to runtime
kanishkatn Apr 24, 2023
f1a035d
add ParachainHostAvailabilityCores to runtime
kanishkatn Apr 24, 2023
e31c956
fix CoreState enum
kanishkatn Apr 24, 2023
9958871
cleanup
kanishkatn Apr 24, 2023
dff1140
add ParachainHostCheckValidationOutputs
kanishkatn Apr 24, 2023
eacdd10
add ParachainHostSessionIndexForChild
kanishkatn Apr 24, 2023
58ef4ef
add ParachainHostCandidatePendingAvailability
kanishkatn Apr 24, 2023
e779201
add ParachainHostSessionInfo
kanishkatn Apr 24, 2023
5c8f0f8
add InboundHrmpChannelsContents and DMQContents
kanishkatn Apr 24, 2023
8baa4e6
add IndexVec
kanishkatn Apr 25, 2023
e41710b
add ParachainHostCandidateEvents
kanishkatn Apr 26, 2023
e9df9aa
fix vdt
kanishkatn Apr 26, 2023
c4d15e4
add `state_call` and fix test
kanishkatn Apr 27, 2023
586a2ae
cleanup
kanishkatn Apr 27, 2023
97d410e
cleanup
kanishkatn Apr 27, 2023
be9037c
fix tests
kanishkatn Apr 27, 2023
7d9bcc3
fix test
kanishkatn Apr 27, 2023
c0c413e
cleanup
kanishkatn Apr 27, 2023
0c01506
cleanup
kanishkatn Apr 27, 2023
6c5e32a
use blockHash if present
kanishkatn Apr 27, 2023
23c69b3
Merge branch 'development' into feat/k/state-call-rpc
kanishkatn Apr 27, 2023
80d30aa
cleanup
kanishkatn Apr 27, 2023
84d7abf
Merge branch 'development' into feat/k/state-call-rpc
kanishkatn Apr 27, 2023
a1441ec
fix unit test
kanishkatn Apr 27, 2023
0ddd6a3
cleanup
kanishkatn Apr 28, 2023
28bd340
fix test
kanishkatn Apr 28, 2023
780a11b
address review comments
kanishkatn May 2, 2023
462ac39
cleanup DecodeScale
kanishkatn May 2, 2023
cb49d8f
cleanup
kanishkatn May 2, 2023
cf9302f
Merge branch 'development' into feat/k/state-call-rpc
kanishkatn May 2, 2023
94206ca
add tests for parachain types
kanishkatn May 3, 2023
629d7e8
fix availability-cores and add tests
kanishkatn May 3, 2023
0e4190b
add session-index tests
kanishkatn May 3, 2023
0f7d857
fix err
kanishkatn May 3, 2023
e36bd97
add tests
kanishkatn May 4, 2023
5cfd809
fix tests
kanishkatn May 4, 2023
1748902
fix tests
kanishkatn May 4, 2023
b571bad
fix lint
kanishkatn May 4, 2023
13b80a0
add test
kanishkatn May 5, 2023
fad1dfa
use types in inherents
kanishkatn May 5, 2023
2cefde8
Merge branch 'development' into feat/k/parachain-runtime
kanishkatn May 5, 2023
09661be
cleanup
kanishkatn May 5, 2023
30a724f
fix lint
kanishkatn May 5, 2023
738a123
fix lint
kanishkatn May 5, 2023
1f83d79
fix lint
kanishkatn May 5, 2023
8ce531c
fix lint
kanishkatn May 5, 2023
d200706
fix test
kanishkatn May 5, 2023
5baac84
fix type
kanishkatn May 5, 2023
d93e268
fix type
kanishkatn May 5, 2023
52b3b02
fix err
kanishkatn May 5, 2023
13f00ab
refactor
kanishkatn May 8, 2023
01c18ed
refactor fix
kanishkatn May 8, 2023
e564af6
Merge branch 'feat/k/state-call-rpc' into feat/k/parachain-runtime
kanishkatn May 8, 2023
62de2f8
cleanup
kanishkatn May 9, 2023
e0f618b
cleanup
kanishkatn May 9, 2023
19f46bb
cleanup
kanishkatn May 9, 2023
1d725a5
Merge branch 'development' into feat/k/parachain-runtime
kanishkatn May 19, 2023
16222e5
add tests
kanishkatn May 23, 2023
bafc235
add tests(incomplete)
kanishkatn May 24, 2023
3201ef5
add latest runtime
kanishkatn May 29, 2023
e684e35
merge branch `development` into feat/k/parachain-runtime
kanishkatn May 29, 2023
c4e9922
Merge branch 'feat/parachain' into feat/k/parachain-runtime
kanishkatn May 29, 2023
be3912c
update tests
kanishkatn May 30, 2023
83deb93
use blocknumber
kanishkatn May 30, 2023
7509ce5
fix imports
kanishkatn May 30, 2023
6367099
merge branch `feat/parachain` into `feat/k/parachain-runtime`
kanishkatn Jun 15, 2023
ee880f8
cleanup
kanishkatn Jun 15, 2023
8d1800e
revert types
kanishkatn Jun 15, 2023
d43ea57
embed test data
kanishkatn Jun 16, 2023
f616ce1
cleanup
kanishkatn Jun 16, 2023
6b1059f
cleanup
kanishkatn Jun 20, 2023
e77dbd1
cleanup
kanishkatn Jun 20, 2023
8033ad9
Added parachain runtime funcs to runtime interface
kishansagathiya Jun 21, 2023
61fa0cf
Merge branch 'feat/parachain' into feat/k/parachain-runtime
kishansagathiya Jun 21, 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
22 changes: 22 additions & 0 deletions lib/runtime/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ const (
WESTEND_RUNTIME_V0929_FP = "westend_runtime-v929.compact.wasm"
WESTEND_RUNTIME_V0929_URL = "https://github.com/paritytech/polkadot/releases/download/v0.9." +
"29/westend_runtime-v9290.compact.compressed.wasm?raw=true"

// v0.9.42 westend
WESTEND_RUNTIME_v0942 = "westend_runtime-v942"
WESTEND_RUNTIME_V0942_FP = "westend_runtime-v942.compact.wasm"
WESTEND_RUNTIME_V0942_URL = "https://github.com/paritytech/polkadot/releases/download/v0.9." +
"42/westend_runtime-v9420.compact.compressed.wasm?raw=true"
)

const (
Expand Down Expand Up @@ -60,4 +66,20 @@ const (
TransactionPaymentCallAPIQueryCallInfo = "TransactionPaymentCallApi_query_call_info"
// TransactionPaymentCallAPIQueryCallFeeDetails returns call query call fee details
TransactionPaymentCallAPIQueryCallFeeDetails = "TransactionPaymentCallApi_query_call_fee_details"
// ParachainHostValidators is the runtime API call ParachainHost_validators
ParachainHostValidators = "ParachainHost_validators"
// ParachainHostValidatorGroups is the runtime API call ParachainHost_validator_groups
ParachainHostValidatorGroups = "ParachainHost_validator_groups"
// ParachainHostAvailabilityCores is the runtime API call ParachainHost_availability_cores
ParachainHostAvailabilityCores = "ParachainHost_availability_cores"
// ParachainHostCheckValidationOutputs is the runtime API call ParachainHost_check_validation_outputs
ParachainHostCheckValidationOutputs = "ParachainHost_check_validation_outputs"
// ParachainHostSessionIndexForChild is the runtime API call ParachainHost_session_index_for_child
ParachainHostSessionIndexForChild = "ParachainHost_session_index_for_child"
// ParachainHostCandidatePendingAvailability is the runtime API call ParachainHost_candidate_pending_availability
ParachainHostCandidatePendingAvailability = "ParachainHost_candidate_pending_availability"
// ParachainHostCandidateEvents is the runtime API call ParachainHost_candidate_events
ParachainHostCandidateEvents = "ParachainHost_candidate_events"
// ParachainHostSessionInfo is the runtime API call ParachainHost_session_info
ParachainHostSessionInfo = "ParachainHost_session_info"
)
3 changes: 3 additions & 0 deletions lib/runtime/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ func GetRuntime(ctx context.Context, runtime string) (
case WESTEND_RUNTIME_v0929:
runtimeFilename = WESTEND_RUNTIME_V0929_FP
url = WESTEND_RUNTIME_V0929_URL
case WESTEND_RUNTIME_v0942:
runtimeFilename = WESTEND_RUNTIME_V0942_FP
url = WESTEND_RUNTIME_V0942_URL
default:
return "", fmt.Errorf("%w: %s", ErrRuntimeUnknown, runtime)
}
Expand Down
169 changes: 169 additions & 0 deletions lib/runtime/wasmer/exports.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/ChainSafe/gossamer/dot/types"
"github.com/ChainSafe/gossamer/lib/crypto/ed25519"
"github.com/ChainSafe/gossamer/lib/parachain"
"github.com/ChainSafe/gossamer/lib/runtime"
"github.com/ChainSafe/gossamer/lib/transaction"
"github.com/ChainSafe/gossamer/pkg/scale"
Expand Down Expand Up @@ -346,6 +347,174 @@ func (in *Instance) GrandpaSubmitReportEquivocationUnsignedExtrinsic(
return nil
}

// ParachainHostValidators returns the validator set at the current state.
// The specified validators are responsible for backing parachains for the current state.
func (in *Instance) ParachainHostValidators() ([]parachain.ValidatorID, error) {
encodedValidators, err := in.Exec(runtime.ParachainHostValidators, []byte{})
if err != nil {
return nil, fmt.Errorf("exec: %w", err)
}

var validatorIDs []parachain.ValidatorID
err = scale.Unmarshal(encodedValidators, &validatorIDs)
if err != nil {
return nil, fmt.Errorf("unmarshalling: %w", err)
}

return validatorIDs, nil
}

// ParachainHostValidatorGroups returns the validator groups used during the current session.
// The validators in the groups are referred to by the validator set Id.
func (in *Instance) ParachainHostValidatorGroups() (*parachain.ValidatorGroups, error) {
encodedValidatorGroups, err := in.Exec(runtime.ParachainHostValidatorGroups, []byte{})
if err != nil {
return nil, fmt.Errorf("exec: %w", err)
}

var validatorGroups parachain.ValidatorGroups
err = scale.Unmarshal(encodedValidatorGroups, &validatorGroups)
if err != nil {
return nil, fmt.Errorf("unmarshalling: %w", err)
}

return &validatorGroups, nil
}

// ParachainHostAvailabilityCores returns the availability cores for the current state.
func (in *Instance) ParachainHostAvailabilityCores() (*scale.VaryingDataTypeSlice, error) {
encodedAvailabilityCores, err := in.Exec(runtime.ParachainHostAvailabilityCores, []byte{})
if err != nil {
return nil, fmt.Errorf("exec: %w", err)
}

availabilityCores, err := parachain.NewAvailabilityCores()
if err != nil {
return nil, fmt.Errorf("new availability cores: %w", err)
}
err = scale.Unmarshal(encodedAvailabilityCores, &availabilityCores)
if err != nil {
return nil, fmt.Errorf("unmarshalling: %w", err)
}

return &availabilityCores, nil
}

// ParachainHostCheckValidationOutputs checks the validation outputs of a candidate.
// Returns true if the candidate is valid.
func (in *Instance) ParachainHostCheckValidationOutputs(
parachainID parachain.ParaID,
outputs parachain.CandidateCommitments,
) (bool, error) {
buffer := bytes.NewBuffer(nil)
encoder := scale.NewEncoder(buffer)
err := encoder.Encode(parachainID)
if err != nil {
return false, fmt.Errorf("encode parachainID: %w", err)
}
err = encoder.Encode(outputs)
if err != nil {
return false, fmt.Errorf("encode outputs: %w", err)
}

encodedPersistedValidationData, err := in.Exec(runtime.ParachainHostCheckValidationOutputs, buffer.Bytes())
if err != nil {
return false, fmt.Errorf("exec: %w", err)
}

var isValid bool
err = scale.Unmarshal(encodedPersistedValidationData, &isValid)
if err != nil {
return false, fmt.Errorf("unmarshalling: %w", err)
}

return isValid, nil
}

// ParachainHostSessionIndexForChild returns the session index that is expected at the child of a block.
func (in *Instance) ParachainHostSessionIndexForChild() (parachain.SessionIndex, error) {
encodedSessionIndex, err := in.Exec(runtime.ParachainHostSessionIndexForChild, []byte{})
if err != nil {
return 0, fmt.Errorf("exec: %w", err)
}

var sessionIndex parachain.SessionIndex
err = scale.Unmarshal(encodedSessionIndex, &sessionIndex)
if err != nil {
return 0, fmt.Errorf("unmarshalling: %w", err)
}

return sessionIndex, nil
}

// ParachainHostCandidatePendingAvailability returns the receipt of a candidate pending availability
// for any parachain assigned to an occupied availability core.
func (in *Instance) ParachainHostCandidatePendingAvailability(
parachainID parachain.ParaID,
) (*parachain.CommittedCandidateReceipt, error) {
buffer := bytes.NewBuffer(nil)
encoder := scale.NewEncoder(buffer)
err := encoder.Encode(parachainID)
if err != nil {
return nil, fmt.Errorf("encode parachainID: %w", err)
}

encodedCandidateReceipt, err := in.Exec(runtime.ParachainHostCandidatePendingAvailability, buffer.Bytes())
if err != nil {
return nil, fmt.Errorf("exec: %w", err)
}

var candidateReceipt *parachain.CommittedCandidateReceipt
err = scale.Unmarshal(encodedCandidateReceipt, &candidateReceipt)
if err != nil {
return nil, fmt.Errorf("unmarshalling: %w", err)
}

return candidateReceipt, nil
}

// ParachainHostCandidateEvents returns an array of candidate events that occurred within the latest state.
func (in *Instance) ParachainHostCandidateEvents() (*scale.VaryingDataTypeSlice, error) {
encodedCandidateEvents, err := in.Exec(runtime.ParachainHostCandidateEvents, []byte{})
if err != nil {
return nil, fmt.Errorf("exec: %w", err)
}

candidateEvents, err := parachain.NewCandidateEvents()
if err != nil {
return nil, fmt.Errorf("create new candidate events: %w", err)
}
err = scale.Unmarshal(encodedCandidateEvents, &candidateEvents)
if err != nil {
return nil, fmt.Errorf("unmarshalling: %w", err)
}

return &candidateEvents, nil
}

// ParachainHostSessionInfo returns the session info of the given session, if available.
func (in *Instance) ParachainHostSessionInfo(sessionIndex parachain.SessionIndex) (*parachain.SessionInfo, error) {
buffer := bytes.NewBuffer(nil)
encoder := scale.NewEncoder(buffer)
err := encoder.Encode(sessionIndex)
if err != nil {
return nil, fmt.Errorf("encode sessionIndex: %w", err)
}

encodedSessionInfo, err := in.Exec(runtime.ParachainHostSessionInfo, buffer.Bytes())
if err != nil {
return nil, fmt.Errorf("exec: %w", err)
}

var sessionInfo *parachain.SessionInfo
err = scale.Unmarshal(encodedSessionInfo, &sessionInfo)
if err != nil {
return nil, fmt.Errorf("unmarshalling: %w", err)
}

return sessionInfo, nil
}

func (in *Instance) RandomSeed() {}
func (in *Instance) OffchainWorker() {}
func (in *Instance) GenerateSessionKeys() {}
Loading