From 289dd453fda19c2ad197b5ab7b5cf60eda7a24ad Mon Sep 17 00:00:00 2001 From: Peter Nose Date: Tue, 30 Apr 2024 20:34:11 +0200 Subject: [PATCH] go/consensus/cometbft/apps/keymanager/secrets: Undo fix gas charge --- .changelog/5669.trivial.md | 0 .../cometbft/apps/keymanager/secrets/txs.go | 84 +++++++++---------- 2 files changed, 42 insertions(+), 42 deletions(-) create mode 100644 .changelog/5669.trivial.md diff --git a/.changelog/5669.trivial.md b/.changelog/5669.trivial.md new file mode 100644 index 00000000000..e69de29bb2d diff --git a/go/consensus/cometbft/apps/keymanager/secrets/txs.go b/go/consensus/cometbft/apps/keymanager/secrets/txs.go index 8e1e2a4ea52..c1258f001f9 100644 --- a/go/consensus/cometbft/apps/keymanager/secrets/txs.go +++ b/go/consensus/cometbft/apps/keymanager/secrets/txs.go @@ -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) @@ -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 @@ -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 { @@ -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", @@ -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 { @@ -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",