Skip to content

Commit

Permalink
runtime/parachain: add ValidationCodeByHash and copy tests to wazero (
Browse files Browse the repository at this point in the history
#3427)

Co-authored-by: Kishan Sagathiya <[email protected]>
  • Loading branch information
2 people authored and timwu20 committed Jun 20, 2024
1 parent c62759c commit 9697a6e
Show file tree
Hide file tree
Showing 13 changed files with 545 additions and 0 deletions.
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/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.

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

2 changes: 2 additions & 0 deletions lib/runtime/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ const (
ParachainHostPersistedValidationData = "ParachainHost_persisted_validation_data"
// ParachainHostValidationCode returns parachain host's validation code
ParachainHostValidationCode = "ParachainHost_validation_code"
// ParachainHostValidationCodeByHash returns parachain host's validation code by hash
ParachainHostValidationCodeByHash = "ParachainHost_validation_code_by_hash"
// ParachainHostValidators is the runtime API call ParachainHost_validators
ParachainHostValidators = "ParachainHost_validators"
// ParachainHostValidatorGroups is the runtime API call ParachainHost_validator_groups
Expand Down
1 change: 1 addition & 0 deletions lib/runtime/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type Instance interface {
) (*parachaintypes.PersistedValidationData, error)
ParachainHostValidationCode(parachaidID uint32, assumption parachaintypes.OccupiedCoreAssumption,
) (*parachaintypes.ValidationCode, error)
ParachainHostValidationCodeByHash(validationCodeHash common.Hash) (*parachaintypes.ValidationCode, error)
ParachainHostValidators() ([]parachaintypes.ValidatorID, error)
ParachainHostValidatorGroups() (*parachaintypes.ValidatorGroups, error)
ParachainHostAvailabilityCores() ([]parachaintypes.CoreState, error)
Expand Down
15 changes: 15 additions & 0 deletions lib/runtime/mocks/mocks.go

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

24 changes: 24 additions & 0 deletions lib/runtime/wazero/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -1336,6 +1336,30 @@ func (in *Instance) ParachainHostSessionInfo(sessionIndex parachaintypes.Session
return sessionInfo, nil
}

// ParachainHostValidationCodeByHash returns validation code for the given hash.
func (in *Instance) ParachainHostValidationCodeByHash(validationCodeHash common.Hash) (
*parachaintypes.ValidationCode, error) {
buffer := bytes.NewBuffer(nil)
encoder := scale.NewEncoder(buffer)
err := encoder.Encode(validationCodeHash)
if err != nil {
return nil, fmt.Errorf("encoding validation code hash: %w", err)
}

encodedValidationCodeHash, err := in.Exec(runtime.ParachainHostValidationCodeByHash, buffer.Bytes())
if err != nil {
return nil, err
}

var validationCode *parachaintypes.ValidationCode
err = scale.Unmarshal(encodedValidationCodeHash, &validationCode)
if err != nil {
return nil, fmt.Errorf("unmarshalling validation code: %w", err)
}

return validationCode, nil
}

func (*Instance) RandomSeed() {
panic("unimplemented")
}
Expand Down
Loading

0 comments on commit 9697a6e

Please sign in to comment.