Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API account counter issue #2104

Closed
lrettig opened this issue Aug 6, 2020 · 3 comments
Closed

API account counter issue #2104

lrettig opened this issue Aug 6, 2020 · 3 comments

Comments

@lrettig
Copy link
Member

lrettig commented Aug 6, 2020

Description

Calling GlobalStateService.Account returns the actual account counter (nonce) (along with balance) from global state. However, this is not the counter value that should be included in a newly-submitted tx. For a new tx, the system expects the counter to match the projected counter value returned by TransactionProcessor.GetProjection, which factors in pending transactions:

go-spacemesh/mesh/meshdb.go

Lines 576 to 584 in 1c81878

// GetProjection returns projection of address
func (m *DB) GetProjection(addr types.Address, prevNonce, prevBalance uint64) (nonce, balance uint64, err error) {
pending, err := m.getAccountPendingTxs(addr)
if err != nil {
return 0, 0, err
}
nonce, balance = pending.GetProjection(prevNonce, prevBalance)
return nonce, balance, nil
}

If a client naively reads account data from the API, then tries to submit a tx, it will fail as a result.

CC @noamnelke @avive, would appreciate your input on this.

Steps To Reproduce

  1. Call GlobalStateService.Account
  2. Submit a new, valid tx to TransactionService.SubmitTransaction using the account counter you just got. If there are any pending txs from this sender, it will fail.

Expected Behavior

I see a few options:

  • return projected counter and balance instead of current values from global state - probably a bad idea
  • add a new API endpoint to get projected account data
  • add projected data to the existing account API endpoints
@noamnelke
Copy link
Member

The old api had GetNonce and GetBalace endpoints which returned projected values.

I agree that it can be confusing to get an account info without the projected values. I think that from an api-consumer perspective it's best to get those values as part of the existing account endpoints, in addition to the "final" data from the state. Any reason not to do it that way?

@lrettig
Copy link
Member Author

lrettig commented Aug 10, 2020

I agree. I'll update the API to add projected as well as current state values.

@lrettig
Copy link
Member Author

lrettig commented Oct 7, 2020

The API has been updated. I'm adding support for the latest API release in #2133 which should take care of this.

@bors bors bot closed this as completed in e23ac3e Nov 6, 2020
lrettig added a commit that referenced this issue Feb 3, 2021
Closes #2133
Closes #2104

- Upgrade to spacemesh API v1.0.0. Major API changes include:
  - split account state into current/projected (spacemeshos/api#111)
  - align node error types with zapcore error types (spacemeshos/api#102)
  - harmonize layernum type as uint32 (spacemeshos/api#120)
  - add an unimplemented SmesherService endpoint (EstimatedRewards) (spacemeshos/api#101)
- Upgrade google modules (required by API)

No new tests are needed. No new functionality has been added to the API. Existing tests have been updated.

There are no docs to update. Master API docs live in the API repository and have already been updated. Implementation docs are still a work in progress in #2083.

- [x] Finish upgrading API code

Note: Google modules were upgraded because cmd/sync imports google.golang.org/api/option, and the version it was importing was incompatible with google.golang.org/grpc >= v1.30.0. More info here:

- google/trillian#2195
- etcd-io/etcd#12124

Here's the error I was getting:

```
> go mod tidy
go: finding module for package google.golang.org/grpc/naming
github.com/spacemeshos/go-spacemesh/cmd/sync imports
        google.golang.org/api/option imports
        google.golang.org/api/internal imports
        google.golang.org/grpc/naming: module google.golang.org/grpc@latest found (v1.32.0), but does not contain package google.golang.org/grpc/naming
```

For reference here are the API changes: spacemeshos/api@49b94a5...v1.0.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants