Skip to content

Commit

Permalink
[Hot-fix] TSS amount precision (#176)
Browse files Browse the repository at this point in the history
### What

Fix TSS's database amount precision to be compliant with the Stellar network amount precision.

### Why

The database amount was configured to NUMERIC(10,7), which allows the maximum value of 999.9999999. This is not compliant with the Stellar network amounts though, which according with the [docs](https://developers.stellar.org/docs/fundamentals-and-concepts/stellar-data-structures/assets#amount-precision) supports numbers from 0.0000001 to 922,337,203,685.4775807.
  • Loading branch information
marcelosalloum committed Feb 6, 2024
1 parent e12d7db commit b2b7a88
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

None

## [1.1.1](https://github.com/stellar/stellar-disbursement-platform-backend/compare/1.1.0...1.1.1)

### Fixed

- TSS amount precision [#176](https://github.com/stellar/stellar-disbursement-platform-backend/pull/176)

## [1.1.0](https://github.com/stellar/stellar-disbursement-platform-backend/compare/1.0.1...1.1.0)

### Changed
Expand Down
2 changes: 1 addition & 1 deletion helmchart/sdp/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v2
name: stellar-disbursement-platform
description: A Helm chart for the Stellar Disbursement Platform Backend (A.K.A. `sdp`)
version: 0.9.4
appVersion: "1.1.0"
appVersion: "1.1.1"
type: application
maintainers:
- name: Stellar Development Foundation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ALTER TABLE public.submitter_transactions
ADD COLUMN xdr_received TEXT UNIQUE,
ALTER COLUMN external_id SET NOT NULL,
ALTER COLUMN status SET DEFAULT 'PENDING',
ALTER COLUMN amount TYPE numeric(10,7),
ALTER COLUMN amount TYPE NUMERIC(19,7),
ADD CONSTRAINT unique_stellar_transaction_hash UNIQUE (stellar_transaction_hash),
ADD CONSTRAINT check_retry_count CHECK (retry_count >= 0);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- +migrate Up

ALTER TABLE public.submitter_transactions
ALTER COLUMN amount TYPE NUMERIC(19,7);

-- +migrate Down
6 changes: 4 additions & 2 deletions internal/transactionsubmission/store/transactions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,16 @@ func Test_TransactionModel_BulkInsert(t *testing.T) {
ExternalID: "external-id-1",
AssetCode: "USDC",
AssetIssuer: keypair.MustRandom().Address(),
Amount: 1,
// Lowest number in the Stellar network (ref: https://developers.stellar.org/docs/fundamentals-and-concepts/stellar-data-structures/assets#amount-precision):
Amount: 0.0000001,
Destination: keypair.MustRandom().Address(),
}
incomingTx2 := Transaction{
ExternalID: "external-id-2",
AssetCode: "USDC",
AssetIssuer: keypair.MustRandom().Address(),
Amount: 2,
// Largest number in the Stellar network (ref: https://developers.stellar.org/docs/fundamentals-and-concepts/stellar-data-structures/assets#amount-precision):
Amount: 922337203685.4775807,
Destination: keypair.MustRandom().Address(),
}
insertedTransactions, err := txModel.BulkInsert(ctx, dbConnectionPool, []Transaction{incomingTx1, incomingTx2})
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

// Version is the official version of this application. Whenever it's changed
// here, it also needs to be updated at the `helmchart/Chart.yaml#appVersion“.
const Version = "1.1.0"
const Version = "1.1.1"

// GitCommit is populated at build time by
// go build -ldflags "-X main.GitCommit=$GIT_COMMIT"
Expand Down

0 comments on commit b2b7a88

Please sign in to comment.