Skip to content

Commit

Permalink
Merge pull request #5669 from oasisprotocol/peternose/trivial/undo-fi…
Browse files Browse the repository at this point in the history
…x-gas-charge

go/consensus/cometbft/apps/keymanager/secrets: Undo fix gas charge
  • Loading branch information
peternose authored May 1, 2024
2 parents b36b56c + 289dd45 commit 7c3b63a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 42 deletions.
Empty file added .changelog/5669.trivial.md
Empty file.
84 changes: 42 additions & 42 deletions go/consensus/cometbft/apps/keymanager/secrets/txs.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,6 @@ func (ext *secretsExt) updatePolicy(
state *secretsState.MutableState,
sigPol *secrets.SignedPolicySGX,
) error {
// Charge gas for this operation.
kmParams, err := state.ConsensusParameters(ctx)
if err != nil {
return err
}
if err = ctx.Gas().UseGas(1, secrets.GasOpUpdatePolicy, kmParams.GasCosts); err != nil {
return err
}

// Return early if simulating since this is just estimating gas.
if ctx.IsSimulation() {
return nil
}

// Ensure that the runtime exists and is a key manager.
regState := registryState.NewMutableState(ctx.State())
kmRt, err := common.KeyManagerRuntime(ctx, sigPol.Policy.ID)
Expand Down Expand Up @@ -70,6 +56,20 @@ func (ext *secretsExt) updatePolicy(
return nil
}

// Charge gas for this operation.
kmParams, err := state.ConsensusParameters(ctx)
if err != nil {
return err
}
if err = ctx.Gas().UseGas(1, secrets.GasOpUpdatePolicy, kmParams.GasCosts); err != nil {
return err
}

// Return early if simulating since this is just estimating gas.
if ctx.IsSimulation() {
return nil
}

// Ok, as far as we can tell the new policy is valid, apply it.
//
// Note: The key manager cohort responsible for servicing this ID
Expand Down Expand Up @@ -133,20 +133,6 @@ func (ext *secretsExt) publishMasterSecret(
state *secretsState.MutableState,
secret *secrets.SignedEncryptedMasterSecret,
) error {
// Charge gas for this operation.
kmParams, err := state.ConsensusParameters(ctx)
if err != nil {
return err
}
if err = ctx.Gas().UseGas(1, secrets.GasOpPublishMasterSecret, kmParams.GasCosts); err != nil {
return err
}

// Return early if simulating since this is just estimating gas.
if ctx.IsSimulation() {
return nil
}

// Ensure that the runtime exists and is a key manager.
kmRt, err := common.KeyManagerRuntime(ctx, secret.Secret.ID)
if err != nil {
Expand Down Expand Up @@ -198,6 +184,20 @@ func (ext *secretsExt) publishMasterSecret(
return nil
}

// Charge gas for this operation.
kmParams, err := state.ConsensusParameters(ctx)
if err != nil {
return err
}
if err = ctx.Gas().UseGas(1, secrets.GasOpPublishMasterSecret, kmParams.GasCosts); err != nil {
return err
}

// Return early if simulating since this is just estimating gas.
if ctx.IsSimulation() {
return nil
}

// Ok, as far as we can tell the secret is valid, save it.
if err := state.SetMasterSecret(ctx, secret); err != nil {
ctx.Logger().Error("keymanager: failed to set key manager master secret",
Expand Down Expand Up @@ -231,20 +231,6 @@ func (ext *secretsExt) publishEphemeralSecret(
state *secretsState.MutableState,
secret *secrets.SignedEncryptedEphemeralSecret,
) error {
// Charge gas for this operation.
kmParams, err := state.ConsensusParameters(ctx)
if err != nil {
return err
}
if err = ctx.Gas().UseGas(1, secrets.GasOpPublishEphemeralSecret, kmParams.GasCosts); err != nil {
return err
}

// Return early if simulating since this is just estimating gas.
if ctx.IsSimulation() {
return nil
}

// Ensure that the runtime exists and is a key manager.
kmRt, err := common.KeyManagerRuntime(ctx, secret.Secret.ID)
if err != nil {
Expand Down Expand Up @@ -289,6 +275,20 @@ func (ext *secretsExt) publishEphemeralSecret(
return nil
}

// Charge gas for this operation.
kmParams, err := state.ConsensusParameters(ctx)
if err != nil {
return err
}
if err = ctx.Gas().UseGas(1, secrets.GasOpPublishEphemeralSecret, kmParams.GasCosts); err != nil {
return err
}

// Return early if simulating since this is just estimating gas.
if ctx.IsSimulation() {
return nil
}

// Ok, as far as we can tell the secret is valid, save it.
if err := state.SetEphemeralSecret(ctx, secret); err != nil {
ctx.Logger().Error("keymanager: failed to set key manager ephemeral secret",
Expand Down

0 comments on commit 7c3b63a

Please sign in to comment.