Skip to content

Commit 2c4e314

Browse files
committed
go/registry/api: Add VerifyRuntimeOptions
1 parent 9083912 commit 2c4e314

6 files changed

Lines changed: 31 additions & 13 deletions

File tree

go/consensus/cometbft/apps/keymanager/common/genesis.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ func RegistryRuntimes(ctx *tmapi.Context, doc *genesis.Document, epoch beacon.Ep
1616
regSt := doc.Registry
1717
rtMap := make(map[common.Namespace]*registry.Runtime)
1818
for _, rt := range regSt.Runtimes {
19-
err := registry.VerifyRuntime(&regSt.Parameters, ctx.Logger(), rt, true, false, epoch, true)
19+
verifyOpts := registry.VerifyRuntimeOptions{IsGenesis: true, IsFeatureVersion242: true}
20+
err := registry.VerifyRuntime(&regSt.Parameters, ctx.Logger(), rt, epoch, verifyOpts)
2021
if err != nil {
2122
ctx.Logger().Error("InitChain: Invalid runtime",
2223
"err", err,

go/consensus/cometbft/apps/registry/genesis.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ func (app *Application) InitChain(ctx *abciAPI.Context, _ types.RequestInitChain
5555
if rt == nil {
5656
return fmt.Errorf("registry: genesis runtime index %d is nil", i)
5757
}
58-
err := registry.VerifyRuntime(&st.Parameters, ctx.Logger(), rt, ctx.IsInitChain(), false, epoch, true)
58+
verifyOpts := registry.VerifyRuntimeOptions{IsGenesis: ctx.IsInitChain(), IsFeatureVersion242: true}
59+
err := registry.VerifyRuntime(&st.Parameters, ctx.Logger(), rt, epoch, verifyOpts)
5960
if err != nil {
6061
return err
6162
}

go/consensus/cometbft/apps/registry/transactions.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,8 @@ func (app *Application) registerRuntime( // nolint: gocyclo
598598
}
599599
}
600600

601-
if err = registry.VerifyRuntime(params, ctx.Logger(), rt, ctx.IsInitChain(), false, epoch, isFeatureVersion242); err != nil {
601+
verifyOpts := registry.VerifyRuntimeOptions{IsGenesis: ctx.IsInitChain(), IsFeatureVersion242: isFeatureVersion242}
602+
if err = registry.VerifyRuntime(params, ctx.Logger(), rt, epoch, verifyOpts); err != nil {
602603
return nil, err
603604
}
604605

go/registry/api/api.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,21 +1101,29 @@ func VerifyNodeUpdate(
11011101
return nil
11021102
}
11031103

1104+
// VerifyRuntimeOptions contains the options for VerifyRuntime.
1105+
type VerifyRuntimeOptions struct {
1106+
// IsGenesis is true if the runtime is being verified during genesis.
1107+
IsGenesis bool
1108+
// IsSanityCheck is true if this is a sanity check and not a live transaction verification.
1109+
IsSanityCheck bool
1110+
// IsFeatureVersion242 is true if consensus version 24.2 or higher is active.
1111+
IsFeatureVersion242 bool
1112+
}
1113+
11041114
// VerifyRuntime verifies the given runtime.
1105-
func VerifyRuntime( // nolint: gocyclo
1115+
func VerifyRuntime(
11061116
params *ConsensusParameters,
11071117
logger *logging.Logger,
11081118
rt *Runtime,
1109-
isGenesis bool,
1110-
isSanityCheck bool,
11111119
now beacon.EpochTime,
1112-
isFeatureVersion242 bool,
1120+
opts VerifyRuntimeOptions,
11131121
) error {
11141122
if rt == nil {
11151123
return fmt.Errorf("%w: no runtime given", ErrInvalidArgument)
11161124
}
11171125

1118-
if err := rt.ValidateBasic(!isGenesis && !isSanityCheck); err != nil {
1126+
if err := rt.ValidateBasic(!opts.IsGenesis && !opts.IsSanityCheck); err != nil {
11191127
logger.Error("RegisterRuntime: invalid runtime descriptor",
11201128
"runtime", rt,
11211129
"err", err,
@@ -1130,7 +1138,7 @@ func VerifyRuntime( // nolint: gocyclo
11301138
return fmt.Errorf("%w: test runtime not allowed", ErrInvalidArgument)
11311139
}
11321140

1133-
if err := rt.Genesis.SanityCheck(isGenesis); err != nil {
1141+
if err := rt.Genesis.SanityCheck(opts.IsGenesis); err != nil {
11341142
return err
11351143
}
11361144

@@ -1154,7 +1162,7 @@ func VerifyRuntime( // nolint: gocyclo
11541162

11551163
// Validate the deployments. This also handles validating that the
11561164
// appropriate TEE configuration is present in each deployment.
1157-
if err := rt.ValidateDeployments(now, params, isFeatureVersion242); err != nil {
1165+
if err := rt.ValidateDeployments(now, params, opts.IsFeatureVersion242); err != nil {
11581166
logger.Error("RegisterRuntime: invalid deployments",
11591167
"runtime_id", rt.ID,
11601168
"err", err,

go/registry/api/runtime_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,8 @@ func TestVerifyRuntime(t *testing.T) {
347347
tc.modifyParams(&cp)
348348
}
349349

350-
err := VerifyRuntime(&cp, logging.GetLogger("runtime/tests"), &rt, false, true, beacon.EpochTime(10), true)
350+
verifyOpts := VerifyRuntimeOptions{IsSanityCheck: true, IsFeatureVersion242: true}
351+
err := VerifyRuntime(&cp, logging.GetLogger("runtime/tests"), &rt, beacon.EpochTime(10), verifyOpts)
351352
if tc.errContains == "" {
352353
require.NoError(t, err)
353354
return

go/registry/api/sanity_check.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,18 +147,24 @@ func SanityCheckRuntimes(
147147
now beacon.EpochTime,
148148
isFeatureVersion242 bool,
149149
) (RuntimeLookup, error) {
150+
verifyOpts := VerifyRuntimeOptions{
151+
IsGenesis: isGenesis,
152+
IsSanityCheck: true,
153+
IsFeatureVersion242: isFeatureVersion242,
154+
}
155+
150156
// First go through all runtimes and perform general sanity checks.
151157
seenRuntimes := []*Runtime{}
152158
for _, rt := range runtimes {
153-
if err := VerifyRuntime(params, logger, rt, isGenesis, true, now, isFeatureVersion242); err != nil {
159+
if err := VerifyRuntime(params, logger, rt, now, verifyOpts); err != nil {
154160
return nil, fmt.Errorf("runtime sanity check failed: %w", err)
155161
}
156162
seenRuntimes = append(seenRuntimes, rt)
157163
}
158164

159165
seenSuspendedRuntimes := []*Runtime{}
160166
for _, rt := range suspendedRuntimes {
161-
if err := VerifyRuntime(params, logger, rt, isGenesis, true, now, isFeatureVersion242); err != nil {
167+
if err := VerifyRuntime(params, logger, rt, now, verifyOpts); err != nil {
162168
return nil, fmt.Errorf("runtime sanity check failed: %w", err)
163169
}
164170
seenSuspendedRuntimes = append(seenSuspendedRuntimes, rt)

0 commit comments

Comments
 (0)