Skip to content

Commit

Permalink
go/consensus/api: Use staking.Address in GetSignerNonceRequest type
Browse files Browse the repository at this point in the history
Replace GetSignerNonceRequest's ID field with AccountAddress field to
reflect the recent staking account id/address change.
  • Loading branch information
tjanez committed Jun 11, 2020
1 parent 0e9f602 commit 3eb688f
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 17 deletions.
4 changes: 4 additions & 0 deletions .changelog/2940.breaking.3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
go/consensus/api: Use `staking.Address` in `GetSignerNonceRequest` type

Replace `GetSignerNonceRequest`'s `ID` field with `AccountAddress` field to
reflect the recent staking account id/address change.
4 changes: 2 additions & 2 deletions go/consensus/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,6 @@ type EstimateGasRequest struct {

// GetSignerNonceRequest is a GetSignerNonce request.
type GetSignerNonceRequest struct {
ID signature.PublicKey `json:"id"`
Height int64 `json:"height"`
AccountAddress staking.Address `json:"account_address"`
Height int64 `json:"height"`
}
7 changes: 5 additions & 2 deletions go/consensus/api/submission.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/oasisprotocol/oasis-core/go/common/logging"
"github.com/oasisprotocol/oasis-core/go/common/quantity"
"github.com/oasisprotocol/oasis-core/go/consensus/api/transaction"
staking "github.com/oasisprotocol/oasis-core/go/staking/api"
)

const (
Expand Down Expand Up @@ -63,7 +64,9 @@ type submissionManager struct {
func (m *submissionManager) signAndSubmitTx(ctx context.Context, signer signature.Signer, tx *transaction.Transaction) error {
// Update transaction nonce.
var err error
tx.Nonce, err = m.backend.GetSignerNonce(ctx, &GetSignerNonceRequest{ID: signer.Public(), Height: HeightLatest})
signerAddr := staking.NewAddress(signer.Public())

tx.Nonce, err = m.backend.GetSignerNonce(ctx, &GetSignerNonceRequest{AccountAddress: signerAddr, Height: HeightLatest})
if err != nil {
if errors.Is(err, ErrNoCommittedBlocks) {
// No committed blocks available, retry submission.
Expand Down Expand Up @@ -123,7 +126,7 @@ func (m *submissionManager) signAndSubmitTx(ctx context.Context, signer signatur
if errors.Is(err, transaction.ErrInvalidNonce) {
// Invalid nonce, retry submission.
m.logger.Debug("retrying transaction submission due to invalid nonce",
"account_id", signer.Public(),
"account_address", signerAddr,
"nonce", tx.Nonce,
)
return err
Expand Down
4 changes: 1 addition & 3 deletions go/consensus/tendermint/apps/staking/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/oasisprotocol/oasis-core/go/consensus/tendermint/abci"
abciAPI "github.com/oasisprotocol/oasis-core/go/consensus/tendermint/api"
stakingState "github.com/oasisprotocol/oasis-core/go/consensus/tendermint/apps/staking/state"
staking "github.com/oasisprotocol/oasis-core/go/staking/api"
)

var _ abci.TransactionAuthHandler = (*stakingApplication)(nil)
Expand All @@ -20,8 +19,7 @@ func (app *stakingApplication) GetSignerNonce(ctx context.Context, req *api.GetS
return 0, err
}

addr := staking.NewAddress(req.ID)
acct, err := q.Account(ctx, addr)
acct, err := q.Account(ctx, req.AccountAddress)
if err != nil {
return 0, err
}
Expand Down
6 changes: 5 additions & 1 deletion go/consensus/tests/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import (

"github.com/stretchr/testify/require"

"github.com/oasisprotocol/oasis-core/go/common/crypto/signature"
memorySigner "github.com/oasisprotocol/oasis-core/go/common/crypto/signature/signers/memory"
consensus "github.com/oasisprotocol/oasis-core/go/consensus/api"
"github.com/oasisprotocol/oasis-core/go/consensus/api/transaction"
"github.com/oasisprotocol/oasis-core/go/consensus/tendermint/apps/epochtime_mock"
staking "github.com/oasisprotocol/oasis-core/go/staking/api"
)

const (
Expand Down Expand Up @@ -74,7 +76,9 @@ func ConsensusImplementationTests(t *testing.T, backend consensus.ClientBackend)
require.NoError(err, "EstimateGas")

nonce, err := backend.GetSignerNonce(ctx, &consensus.GetSignerNonceRequest{
ID: memorySigner.NewTestSigner("get signer nonce signer").Public(),
AccountAddress: staking.NewAddress(
signature.NewPublicKey("badfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),
),
Height: consensus.HeightLatest,
})
require.NoError(err, "GetSignerNonce")
Expand Down
19 changes: 12 additions & 7 deletions go/oasis-node/cmd/debug/txsource/workload/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/oasisprotocol/oasis-core/go/consensus/api/transaction"
cmdCommon "github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/common"
registry "github.com/oasisprotocol/oasis-core/go/registry/api"
staking "github.com/oasisprotocol/oasis-core/go/staking/api"
)

const (
Expand Down Expand Up @@ -181,25 +182,28 @@ func (r *registration) Run( // nolint: gocyclo
}
entityAccs := make([]struct {
signer signature.Signer
address staking.Address
reckonedNonce uint64
nodeIdentities []*nodeAcc
}, registryNumEntities)

fac := memorySigner.NewFactory()
for i := range entityAccs {
entityAccs[i].signer, err = fac.Generate(signature.SignerEntity, rng)
signer, err2 := fac.Generate(signature.SignerEntity, rng)
if err != nil {
return fmt.Errorf("memory signer factory Generate account %d: %w", i, err)
return fmt.Errorf("memory signer factory Generate account %d: %w", i, err2)
}
entityAccs[i].signer = signer
entityAccs[i].address = staking.NewAddress(signer.Public())
}

// Register entities.
// XXX: currently entities are only registered at start. Could also
// periodically register new entities.
for i := range entityAccs {
entityAccs[i].reckonedNonce, err = cnsc.GetSignerNonce(ctx, &consensus.GetSignerNonceRequest{
ID: entityAccs[i].signer.Public(),
Height: consensus.HeightLatest,
AccountAddress: entityAccs[i].address,
Height: consensus.HeightLatest,
})
if err != nil {
return fmt.Errorf("GetSignerNonce error: %w", err)
Expand All @@ -223,12 +227,13 @@ func (r *registration) Run( // nolint: gocyclo
nodeDesc := getNodeDesc(rng, ident, entityAccs[i].signer.Public(), r.ns)

var nodeAccNonce uint64
nodeAccAddress := staking.NewAddress(ident.NodeSigner.Public())
nodeAccNonce, err = cnsc.GetSignerNonce(ctx, &consensus.GetSignerNonceRequest{
ID: ident.NodeSigner.Public(),
Height: consensus.HeightLatest,
AccountAddress: nodeAccAddress,
Height: consensus.HeightLatest,
})
if err != nil {
return fmt.Errorf("GetSignerNonce error: %w", err)
return fmt.Errorf("GetSignerNonce error for accout %s: %w", nodeAccAddress, err)
}

entityAccs[i].nodeIdentities = append(entityAccs[i].nodeIdentities, &nodeAcc{ident, nodeDesc, nodeAccNonce})
Expand Down
5 changes: 3 additions & 2 deletions go/oasis-node/cmd/debug/txsource/workload/workload.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,11 @@ func transferFunds(
// Maybe just expose the SignAndSubmit() method in the
// consensus.ClientBackend?
return backoff.Retry(func() error {
fromAddr := staking.NewAddress(from.Public())
// Get test entity nonce.
nonce, err := cnsc.GetSignerNonce(ctx, &consensus.GetSignerNonceRequest{
ID: from.Public(),
Height: consensus.HeightLatest,
AccountAddress: fromAddr,
Height: consensus.HeightLatest,
})
if err != nil {
return backoff.Permanent(fmt.Errorf("GetSignerNonce TestEntity error: %w", err))
Expand Down

0 comments on commit 3eb688f

Please sign in to comment.