Skip to content

Latest commit

 

History

History
89 lines (53 loc) · 5.41 KB

README.md

File metadata and controls

89 lines (53 loc) · 5.41 KB

mina-payouts-data-provider

Data provider API for mina-pool-payouts This application provides an API to that provides the data needed by mina-pool-payouts

The API exposes resources for staking-ledgers, blocks, and consensus (current tip).

Example return values can be seen here

The application assumes the availability of a mina archive database as well as a mina stakes database that is maintained separately. The stakes database can be created using the script in /deploy/db-setup/stakesDB.sql. The staking ledger for each epoch must be extracted from a mina node and uploaded to the staking-ledgers endpoint each epoch (or in advance.)

consensus

/consensus

The /consensus endpoint returns the current (ish) network tip

staking-ledgers

A staking-ledger can be retrieved from the /staking-ledgers endpoint by hash or by epoch, and is filtered by block producer key.

/staking-ledgers/epoch/[epochNumber]?key=[blockProducerKey]
/staking-ledgers/[stakingLedgerHash]

A staking-ledger can also be uploaded to the /staking-ledgers endpoign by posting the ledger to it's hash.

POST /staking-ledgers/[stakingLedgerHash] -- see example below in the maintenance section.

blocks

The blocks needed for payout calculation can be retrieved from the /blocks endpoint, filtered by block producer key and minimum and maximum block heights.

/blocks?key=[blockProducerKey]&minHeight=[minBlockHeight]&maxHeight=[maxBlockHeight]

Deployment

create container images

Mac version for local testing
docker build -f ./deploy/Dockerfile.mac -t [registry]mppdp-mac:v1.3.0 .
Linux version for k8s deployment
docker build -f ./deploy/Dockerfile.linux -t [registry]mppdp-linux:v1.3.0 .

tag and upload to container registry

docker tag [registry]/mppdp:v1.3.0 [cloud registry]/[repo]/mppdp:v1.3.0
docker push [registry]/[repo]/mppdp:v1.3.0

apply k8s deployment

Create secrets for db password and basic auth for ledgers upload.

database secrets

There are three database specifications - read users for the mina archive database and the staking ledgers database, and a separate connection for the user that writes the staking ledgers to the database. It is assumed that each has a client certificate as well; if there is not a client certificate in place, change the *REQUIRE_SSL variables from "true" to "false" for each database connection. (e.g. LEDGER_DB_QUERY_REQUIRE_SSL="false")

The environment variable validation will not check for the presence of the certificate; the application will crash if ssl is set to true but no certificate is provided for any connection.

kubectl create secret generic block-db-query-password --from-literal BLOCK_DB_QUERY_PASSWORD=[Password]
kubectl create secret generic block-db-query-certificate --from-literal BLOCK_DB_QUERY_CERTIFICATE=[CERTIFICATE]
kubectl create secret generic ledger-db-query-password --from-literal LEDGER_DB_QUERY_PASSWORD=[Password]
kubectl create secret generic ledger-db-query-certificate --from-literal LEDGER_DB_QUERY_CERTIFICATE=[CERTIFICATE]
kubectl create secret generic ledger-db-command-password --from-literal LEDGER_DB_COMMAND_PASSWORD=[Password]
kubectl create secret generic ledger-db-command-certificate --from-literal LEDGER_DB_COMMAND_CERTIFICATE=[CERTIFICATE]

upload user basic auth secret

The staking-ledgers POST endpoint uses basic authentication to authenticate the user posting the ledger.
kubectl create secret generic ledger-upload-password --from-literal LEDGER_UPLOAD_PASSWORD=[Password]

deploy to k8s cluster

Apply deployment
kubectl apply -f ./deploy/deployment.yaml

Maintenance

Staking Ledgers

Database

The staking ledgers are stored in a database instead of using json files. The databse must be created when the projec is deployed and is assumed to be an external dependency similar to the archive databsae. The scripts to create the database are in /deploy/db-setup/StakesDB.sql. The script simple creates the single empty table used by this process. The ledgers can be stored by uploading them to the API.

Uploading Staking Ledgers

Staking ledgers must be kept up to date each epoch. The /staking-ledgers endpoint also accepts a form post to get a staking ledger file and apply it. This is on an endpoing that has basic authentication.

The ledgers can be posted via script - for example:

curl -u "mppdpsl:mppdpsl-password" -X POST -H "Content-Type: multipart/form-data" -F "jsonFile=@./jwV7BsK9rBf5uRWqMZmWKVAUcEcd7pDAo9NCFTrvSvXRjHCwypF.json" http://api.minastakes.com/staking-ledgers/jwV7BsK9rBf5uRWqMZmWKVAUcEcd7pDAo9NCFTrvSvXRjHCwypF

When a ledger is being posted for an epoch that has not started yet, the api cannot determine the epoch; so additional parameters are supported to supply a user-specified epoch number with a query string parameter. For example: http://api.minastakes.com/staking-ledgers/[hash]]?userSpecifiedEpoch=[n]