Skip to content

Commit

Permalink
go/consensus/tendermint/apps: Avoid loading all registered runtimes
Browse files Browse the repository at this point in the history
This is a performance optimization to avoid loading a list of all registered
runtimes into memory in cases when only a specific runtime is actually needed.
  • Loading branch information
kostko committed Jan 14, 2020
1 parent e28cc5e commit 35c5ec1
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 109 deletions.
4 changes: 4 additions & 0 deletions .changelog/2538.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Optimize registry runtime lookups during node registration.

A performance optimization to avoid loading a list of all registered runtimes into memory in cases
when only a specific runtime is actually needed.
2 changes: 1 addition & 1 deletion go/consensus/tendermint/apps/keymanager/keymanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func (app *keymanagerApplication) generateStatus(kmrt *registry.Runtime, oldStat
continue
}

initResponse, err := api.VerifyExtraInfo(kmrt, nodeRt, ts)
initResponse, err := api.VerifyExtraInfo(app.logger, kmrt, nodeRt, ts)
if err != nil {
app.logger.Error("failed to validate ExtraInfo",
"err", err,
Expand Down
30 changes: 10 additions & 20 deletions go/consensus/tendermint/apps/registry/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,16 @@ func (app *registryApplication) registerNode( // nolint: gocyclo
)
return err
}
// TODO: Avoid loading a list of all runtimes.
regRuntimes, err := state.AllRuntimes()
if err != nil {
app.logger.Error("RegisterNode: failed to obtain registry runtimes",
"err", err,
"signed_node", sigNode,
)
return err
}
newNode, err := registry.VerifyRegisterNodeArgs(params, app.logger, sigNode, untrustedEntity, ctx.Now(), ctx.IsInitChain(), regRuntimes, state)
newNode, paidRuntimes, err := registry.VerifyRegisterNodeArgs(
params,
app.logger,
sigNode,
untrustedEntity,
ctx.Now(),
ctx.IsInitChain(),
state,
state,
)
if err != nil {
return err
}
Expand Down Expand Up @@ -255,16 +255,6 @@ func (app *registryApplication) registerNode( // nolint: gocyclo
additionalEpochs = 0
}
}
var paidRuntimes []*registry.Runtime
for _, nodeRt := range newNode.Runtimes {
var rt *registry.Runtime
rt, err = state.AnyRuntime(nodeRt.ID)
if err != nil {
return fmt.Errorf("failed to fetch runtime: %w", err)
}

paidRuntimes = append(paidRuntimes, rt)
}
feeCount := len(paidRuntimes) * int(additionalEpochs)
if err = ctx.Gas().UseGas(feeCount, registry.GasOpRuntimeEpochMaintenance, params.GasCosts); err != nil {
return err
Expand Down
5 changes: 3 additions & 2 deletions go/keymanager/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/oasislabs/oasis-core/go/common/crypto/signature"
memorySigner "github.com/oasislabs/oasis-core/go/common/crypto/signature/signers/memory"
"github.com/oasislabs/oasis-core/go/common/errors"
"github.com/oasislabs/oasis-core/go/common/logging"
"github.com/oasislabs/oasis-core/go/common/node"
"github.com/oasislabs/oasis-core/go/common/pubsub"
registry "github.com/oasislabs/oasis-core/go/registry/api"
Expand Down Expand Up @@ -107,7 +108,7 @@ func (r *SignedInitResponse) Verify(pk signature.PublicKey) error {

// VerifyExtraInfo verifies and parses the per-node + per-runtime ExtraInfo
// blob for a key manager.
func VerifyExtraInfo(rt *registry.Runtime, nodeRt *node.Runtime, ts time.Time) (*InitResponse, error) {
func VerifyExtraInfo(logger *logging.Logger, rt *registry.Runtime, nodeRt *node.Runtime, ts time.Time) (*InitResponse, error) {
var (
hw node.TEEHardware
rak signature.PublicKey
Expand All @@ -121,7 +122,7 @@ func VerifyExtraInfo(rt *registry.Runtime, nodeRt *node.Runtime, ts time.Time) (
}
if hw != rt.TEEHardware {
return nil, fmt.Errorf("keymanger: TEEHardware mismatch")
} else if err := registry.VerifyNodeRuntimeEnclaveIDs(nil, nodeRt, []*registry.Runtime{rt}, ts); err != nil {
} else if err := registry.VerifyNodeRuntimeEnclaveIDs(logger, nodeRt, rt, ts); err != nil {
return nil, err
}

Expand Down
Loading

0 comments on commit 35c5ec1

Please sign in to comment.