Skip to content

Commit bf37f2c

Browse files
committed
go/consensus/api: Deprecate GetSignerNonce
1 parent f953acb commit bf37f2c

9 files changed

Lines changed: 28 additions & 58 deletions

File tree

.changelog/6207.trivial.md

Whitespace-only changes.

go/consensus/api/api.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ type Backend interface {
159159

160160
// GetSignerNonce returns the nonce that should be used by the given
161161
// signer for transmitting the next transaction.
162+
//
163+
// Deprecated: Use staking backend instead.
162164
GetSignerNonce(ctx context.Context, req *GetSignerNonceRequest) (uint64, error)
163165

164166
// GetTransactions returns a list of all transactions contained within a

go/consensus/api/submission.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ type SubmissionManager interface {
5151
}
5252

5353
type submissionManager struct {
54-
consensus Backend
54+
consensus Services
5555
priceDiscovery PriceDiscovery
5656
maxFee quantity.Quantity
5757

@@ -77,7 +77,7 @@ func (m *submissionManager) EstimateGasAndSetFee(ctx context.Context, signer sig
7777
gas transaction.Gas
7878
err error
7979
)
80-
gas, err = m.consensus.EstimateGas(ctx, &EstimateGasRequest{Signer: signer.Public(), Transaction: tx})
80+
gas, err = m.consensus.Core().EstimateGas(ctx, &EstimateGasRequest{Signer: signer.Public(), Transaction: tx})
8181
if err != nil {
8282
return fmt.Errorf("failed to estimate gas: %w", err)
8383
}
@@ -118,14 +118,14 @@ func (m *submissionManager) getSignerNonce(ctx context.Context, signerAddr staki
118118
nonce, ok := m.nonces[signerAddr]
119119
if !ok {
120120
// Query latest nonce when one is not available.
121-
var err error
122-
nonce, err = m.consensus.GetSignerNonce(ctx, &GetSignerNonceRequest{
123-
AccountAddress: signerAddr,
124-
Height: HeightLatest,
121+
account, err := m.consensus.Staking().Account(ctx, &staking.OwnerQuery{
122+
Height: HeightLatest,
123+
Owner: signerAddr,
125124
})
126125
if err != nil {
127126
return 0, err
128127
}
128+
nonce = account.General.Nonce
129129
}
130130

131131
m.nonces[signerAddr] = nonce + 1
@@ -171,9 +171,9 @@ func (m *submissionManager) signAndSubmitTx(ctx context.Context, signer signatur
171171

172172
var proof *transaction.Proof
173173
if withProof {
174-
proof, err = m.consensus.SubmitTxWithProof(ctx, sigTx)
174+
proof, err = m.consensus.Core().SubmitTxWithProof(ctx, sigTx)
175175
} else {
176-
err = m.consensus.SubmitTx(ctx, sigTx)
176+
err = m.consensus.Core().SubmitTx(ctx, sigTx)
177177
}
178178
if err != nil {
179179
// If the transaction check fails (which cannot be determined from
@@ -236,7 +236,7 @@ func (m *submissionManager) SignAndSubmitTxWithProof(ctx context.Context, signer
236236
}
237237

238238
// NewSubmissionManager creates a new transaction submission manager.
239-
func NewSubmissionManager(consensus Backend, priceDiscovery PriceDiscovery, maxFee uint64) SubmissionManager {
239+
func NewSubmissionManager(consensus Services, priceDiscovery PriceDiscovery, maxFee uint64) SubmissionManager {
240240
sm := &submissionManager{
241241
consensus: consensus,
242242
priceDiscovery: priceDiscovery,

go/consensus/tests/tester.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func ConsensusImplementationTests(t *testing.T, consensus api.Backend) {
131131
})
132132
require.NoError(err, "EstimateGas")
133133

134-
nonce, err := consensus.GetSignerNonce(ctx, &api.GetSignerNonceRequest{
134+
nonce, err := consensus.GetSignerNonce(ctx, &api.GetSignerNonceRequest{ //nolint:staticcheck
135135
AccountAddress: staking.NewAddress(
136136
signature.NewPublicKey("badfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),
137137
),

go/oasis-node/cmd/debug/txsource/txsource.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func doRun(cmd *cobra.Command, _ []string) error {
104104
if err != nil {
105105
return fmt.Errorf("failed to create submission manager: %w", err)
106106
}
107-
sm := consensusAPI.NewSubmissionManager(consensus.Core(), pd, 0)
107+
sm := consensusAPI.NewSubmissionManager(consensus, pd, 0)
108108

109109
// Wait for sync before transferring control to the workload.
110110
ncc := api.NewNodeControllerClient(conn)

go/oasis-node/cmd/debug/txsource/workload/registration.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -220,13 +220,14 @@ func (r *registration) Run( // nolint: gocyclo
220220
// XXX: currently entities are only registered at start. Could also
221221
// periodically register new entities.
222222
for i := range entityAccs {
223-
entityAccs[i].reckonedNonce, err = consensus.Core().GetSignerNonce(ctx, &consensusAPI.GetSignerNonceRequest{
224-
AccountAddress: entityAccs[i].address,
225-
Height: consensusAPI.HeightLatest,
223+
account, err := consensus.Staking().Account(ctx, &staking.OwnerQuery{
224+
Height: consensusAPI.HeightLatest,
225+
Owner: entityAccs[i].address,
226226
})
227227
if err != nil {
228-
return fmt.Errorf("GetSignerNonce error: %w", err)
228+
return fmt.Errorf("failed to query account: %w", err)
229229
}
230+
entityAccs[i].reckonedNonce = account.General.Nonce
230231

231232
ent := &entity.Entity{
232233
Versioned: cbor.NewVersioned(entity.LatestDescriptorVersion),
@@ -245,16 +246,15 @@ func (r *registration) Run( // nolint: gocyclo
245246
}
246247
nodeDesc := getNodeDesc(rng, ident, entityAccs[i].signer.Public(), r.ns)
247248

248-
var nodeAccNonce uint64
249249
nodeAccAddress := staking.NewAddress(ident.NodeSigner.Public())
250-
nodeAccNonce, err = consensus.Core().GetSignerNonce(ctx, &consensusAPI.GetSignerNonceRequest{
251-
AccountAddress: nodeAccAddress,
252-
Height: consensusAPI.HeightLatest,
250+
account, err := consensus.Staking().Account(ctx, &staking.OwnerQuery{
251+
Height: consensusAPI.HeightLatest,
252+
Owner: nodeAccAddress,
253253
})
254254
if err != nil {
255-
return fmt.Errorf("GetSignerNonce error for accout %s: %w", nodeAccAddress, err)
255+
return fmt.Errorf("failed to query account %s: %w", nodeAccAddress, err)
256256
}
257-
257+
nodeAccNonce := account.General.Nonce
258258
entityAccs[i].nodeIdentities = append(entityAccs[i].nodeIdentities, &nodeAcc{ident, nodeDesc, nodeAccNonce})
259259
ent.Nodes = append(ent.Nodes, ident.NodeSigner.Public())
260260

go/oasis-test-runner/scenario/e2e/helpers_consensus.go

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,13 @@ import (
1212
"strconv"
1313

1414
beacon "github.com/oasisprotocol/oasis-core/go/beacon/api"
15-
"github.com/oasisprotocol/oasis-core/go/common/crypto/signature"
16-
"github.com/oasisprotocol/oasis-core/go/common/entity"
1715
consensus "github.com/oasisprotocol/oasis-core/go/consensus/api"
1816
"github.com/oasisprotocol/oasis-core/go/consensus/api/transaction"
1917
governance "github.com/oasisprotocol/oasis-core/go/governance/api"
2018
"github.com/oasisprotocol/oasis-core/go/oasis-test-runner/env"
2119
"github.com/oasisprotocol/oasis-core/go/oasis-test-runner/oasis"
2220
"github.com/oasisprotocol/oasis-core/go/oasis-test-runner/oasis/cli"
2321
registry "github.com/oasisprotocol/oasis-core/go/registry/api"
24-
staking "github.com/oasisprotocol/oasis-core/go/staking/api"
2522
)
2623

2724
// TrustRoot is a consensus trust root.
@@ -99,36 +96,6 @@ func (sc *Scenario) TrustRoot(ctx context.Context) (*TrustRoot, error) {
9996
}, nil
10097
}
10198

102-
// TestEntityNonce returns the nonce of the test entity.
103-
func (sc *Scenario) TestEntityNonce(ctx context.Context) (uint64, error) {
104-
ent, _, err := entity.TestEntity()
105-
if err != nil {
106-
return 0, err
107-
}
108-
return sc.EntityNonce(ctx, ent)
109-
}
110-
111-
// EntityNonce returns the nonce of the specified entity.
112-
func (sc *Scenario) EntityNonce(ctx context.Context, ent *entity.Entity) (uint64, error) {
113-
addr := staking.NewAddress(ent.ID)
114-
return sc.Net.ClientController().Consensus.GetSignerNonce(ctx, &consensus.GetSignerNonceRequest{
115-
Height: consensus.HeightLatest,
116-
AccountAddress: addr,
117-
})
118-
}
119-
120-
// EntityNonceByID returns the nonce of the specified entity.
121-
func (sc *Scenario) EntityNonceByID(ctx context.Context, id signature.PublicKey) (uint64, error) {
122-
ent, err := sc.Net.ClientController().Registry.GetEntity(ctx, &registry.IDQuery{
123-
Height: consensus.HeightLatest,
124-
ID: id,
125-
})
126-
if err != nil {
127-
return 0, err
128-
}
129-
return sc.EntityNonce(ctx, ent)
130-
}
131-
13299
// ExportedGenesisFiles gathers exported genesis files and ensures all exported genesis files match.
133100
func (sc *Scenario) ExportedGenesisFiles(skipCompute bool) ([]string, error) {
134101
dumpGlob := "genesis-*.json"

go/oasis-test-runner/scenario/e2e/runtime/archive_api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ func (sc *archiveAPI) testArchiveAPI(ctx context.Context, archiveCtrl *oasis.Con
169169
}
170170

171171
sc.Logger.Info("testing GetSignerNonce")
172-
_, err = archiveCtrl.Consensus.GetSignerNonce(ctx, &consensusAPI.GetSignerNonceRequest{})
172+
_, err = archiveCtrl.Consensus.GetSignerNonce(ctx, &consensusAPI.GetSignerNonceRequest{}) //nolint:staticcheck
173173
if err != consensusAPI.ErrUnsupported {
174174
return fmt.Errorf("archive node GetSignerNonce should fail with unsupported")
175175
}

go/oasis-test-runner/scenario/e2e/runtime/keymanager_rotation_failure.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,13 +204,14 @@ func (sc *kmRotationFailureImpl) extendKeymanagerRegistrations(ctx context.Conte
204204
if err != nil {
205205
return err
206206
}
207-
nonce, err := sc.Net.Controller().Consensus.GetSignerNonce(ctx, &consensus.GetSignerNonceRequest{
208-
AccountAddress: staking.NewAddress(identity.NodeSigner.Public()),
209-
Height: consensus.HeightLatest,
207+
account, err := sc.Net.Controller().Staking.Account(ctx, &staking.OwnerQuery{
208+
Height: consensus.HeightLatest,
209+
Owner: staking.NewAddress(identity.NodeSigner.Public()),
210210
})
211211
if err != nil {
212212
return err
213213
}
214+
nonce := account.General.Nonce
214215
tx := registry.NewRegisterNodeTx(nonce, &transaction.Fee{Gas: 50000}, sigNode)
215216
sigTx, err := transaction.Sign(identity.NodeSigner, tx)
216217
if err != nil {

0 commit comments

Comments
 (0)