Skip to content

Commit

Permalink
Chore/remove db in offline mode (#256)
Browse files Browse the repository at this point in the history
* stashing changes

* chore: removed the need for a postgres in offline mode

* docs: updated docs

* chore: fixed integration test

* chore: added comment to application-offline.yaml
  • Loading branch information
Kammerlo authored Dec 12, 2024
1 parent c933390 commit 7396473
Show file tree
Hide file tree
Showing 18 changed files with 108 additions and 135 deletions.
2 changes: 1 addition & 1 deletion .env.IntegrationTest
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ GENESIS_VERIFICATION_KEY=

## Api env
API_DOCKER_IMAGE_TAG=main
API_SPRING_PROFILES_ACTIVE=dev
API_SPRING_PROFILES_ACTIVE=online
# staging, h2, test. Additional profiles: mempool (if mempool should be activated)
API_PORT=8082
PRINT_EXCEPTION=true
Expand Down
6 changes: 3 additions & 3 deletions .env.docker-compose
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
## Main variables
API_SPRING_PROFILES_ACTIVE=online
LOG=INFO
NETWORK=preprod
NETWORK=mainnet
# mainnet, preprod, preview, sanchonet, devkit
PROTOCOL_MAGIC=1
PROTOCOL_MAGIC=764824073
# mainnet 764824073, preprod 1, preview 2, sanchonet 4, devkit 42

## Postgres image
Expand Down Expand Up @@ -42,7 +43,6 @@ GENESIS_VERIFICATION_KEY=

## Api env
API_DOCKER_IMAGE_TAG=main
API_SPRING_PROFILES_ACTIVE=dev
# staging, h2, test. Additional profiles: mempool (if mempool should be activated)
API_PORT=8082
PRINT_EXCEPTION=true
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ Detailed explanation can be found in the [Wiki](https://github.com/cardano-found
Depending on using a snapshot feature or not, this will take X amount of time. You can follow along with the commands below. Your instance is ready when you see: `DONE`.

### Offline mode
If you want to run rosetta-java in offline mode you need to set the `OFFLINE_MODE` environment variable to `true` in `./docker/.env.dockerfile`.

This will disable the syncing of the node and the indexer.
If you want to run rosetta-java in offline mode you need to set the `API_SPRING_PROFILES_ACTIVE` environment variable to `offline` in `./docker/.env.dockerfile`.
This will disable the syncing of the node and won't start the db and the indexer.
Default is `online`.

**Useful commands:**
- Following Docker container logs:
Expand Down
1 change: 0 additions & 1 deletion api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class AddressUtxoEntity {
private String ownerStakeAddr;

@Type(JsonType.class)
@Column(columnDefinition = "TEXT") // Use TEXT for H2
private List<Amt> amounts;

@Column(name = "block")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class LocalProtocolParamsEntity {
private Long epoch;

@Type(JsonType.class)
@Column(name = "params")
@Column(name = "params", columnDefinition = "TEXT")
private ProtocolParams protocolParams;

}
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ public class PoolRegistrationEntity {
private String rewardAccount;

@Type(JsonType.class)
@Column(columnDefinition = "TEXT") // Use TEXT for H2
private Set<String> poolOwners;

@Type(JsonType.class)
@Column(columnDefinition = "TEXT") // Use TEXT for H2
private List<Relay> relays;

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ public class TxnEntity {
private BlockEntity block;

@Type(JsonType.class)
@Column(name = "inputs")
@Column(name = "inputs", columnDefinition = "TEXT")
private List<UtxoKey> inputKeys;

@Type(JsonType.class)
@Column(name = "outputs")
@Column(name = "outputs", columnDefinition = "TEXT")
private List<UtxoKey> outputKeys;

@Column(name = "fee")
Expand Down
14 changes: 14 additions & 0 deletions api/src/main/resources/config/application-offline.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Using H2 database as a dummy db for offline mode
spring:
datasource:
driver-class-name: org.h2.Driver
username: ${DB_USER:rosetta_db_admin}
password: ${DB_SECRET:weakpwd#123_d}
url: jdbc:h2:mem:${DB_NAME:rosetta-java}
jpa:
hibernate:
ddl-auto: create-drop

cardano:
rosetta:
OFFLINE_MODE: true
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
server:
port: ${API_PORT:8082}

spring:
datasource:
username: ${DB_USER:rosetta_db_admin}
Expand Down Expand Up @@ -29,34 +26,4 @@ spring:

cardano:
rosetta:
version:
# devkit variables
DEVKIT_URL: ${DEVKIT_URL:localhost}

logging:
level:
root: INFO
com:
zaxxer:
hikari:
pool:
HikariPool: DEBUG
org:
springframework:
transaction: DEBUG
orm:
jpa: DEBUG
web:
filter:
CommonsRequestLoggingFilter: DEBUG
path: ${LOG_FILE_PATH:logs}
file:
name: ${LOG_FILE_NAME:logs/rosetta-api.log}
max-size: ${LOG_FILE_MAX_SIZE:10MB}
max-history: ${LOG_FILE_MAX_HISTORY:10}

management:
endpoints:
web:
exposure:
include: "info"
OFFLINE_MODE: false
21 changes: 8 additions & 13 deletions api/src/main/resources/config/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,17 @@ server:
enabled: true
mime-types: text/html,text/plain,text/css,application/javascript,application/json
min-response-size: 1024
port: ${API_PORT:8082}

spring:
profiles:
active: ${API_SPRING_PROFILES_ACTIVE:dev}
active: ${API_SPRING_PROFILES_ACTIVE:online}
jackson:
default-property-inclusion: NON_NULL
serialization:
write-dates-as-timestamps: false
mvc:
log-resolved-exception: true
datasource:
driver-class-name: org.postgresql.Driver
readOnly: true
readOnlyMode: always
hikari:
maximumPoolSize: 12
poolName: RosettaHikariCP
readOnly: true
autoCommit: false
jpa:
open-in-view: false

cardano:
rosetta:
Expand All @@ -43,7 +33,6 @@ cardano:
DEVKIT_URL: ${DEVKIT_URL:yaci-cli}
DEVKIT_PORT: ${DEVKIT_PORT:3333}
SEARCH_PAGE_SIZE: ${SEARCH_PAGE_SIZE:10}
OFFLINE_MODE: ${OFFLINE_MODE:false}

logging:
level:
Expand All @@ -55,3 +44,9 @@ logging:
rollingpolicy:
max-file-size: ${LOG_FILE_MAX_SIZE:10MB}
max-history: ${LOG_FILE_MAX_HISTORY:10}

management:
endpoints:
web:
exposure:
include: "info"
47 changes: 47 additions & 0 deletions docker-compose-api.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
version: '3.8'
services:
api:
image: cardanofoundation/cardano-rosetta-java-api:${API_DOCKER_IMAGE_TAG}
build:
context: ./
dockerfile: ./api/Dockerfile
ports:
- ${API_PORT}:${API_PORT}
environment:
NETWORK: ${NETWORK}
API_SPRING_PROFILES_ACTIVE: ${API_SPRING_PROFILES_ACTIVE}
API_PORT: ${API_PORT}
DB_HOST: ${DB_HOST}
DB_PORT: ${DB_PORT}
DB_NAME: ${DB_NAME}
DB_USER: ${DB_USER}
DB_SECRET: ${DB_SECRET}
DB_SCHEMA: ${DB_SCHEMA}
CARDANO_NODE_VERSION: ${CARDANO_NODE_VERSION}
TOPOLOGY_FILEPATH: ${TOPOLOGY_FILEPATH}
GENESIS_SHELLEY_PATH: ${GENESIS_SHELLEY_PATH}
GENESIS_ALONZO_PATH: ${GENESIS_ALONZO_PATH}
GENESIS_CONWAY_PATH: ${GENESIS_CONWAY_PATH}
CARDANO_NODE_SUBMIT_HOST: ${CARDANO_NODE_SUBMIT_HOST}
NODE_SUBMIT_API_PORT: ${NODE_SUBMIT_API_PORT}
CARDANO_NODE_SOCKET_PATH: ${CARDANO_NODE_SOCKET_PATH}
DEVKIT_ENABLED: ${DEVKIT_ENABLED}
DEVKIT_URL: ${DEVKIT_URL}
DEVKIT_PORT: ${DEVKIT_PORT}
volumes:
- ${CARDANO_CONFIG}:/config
- ${CARDANO_NODE_DIR}:${CARDANO_NODE_DIR}
healthcheck:
test: [ "CMD-SHELL", "curl --fail http://localhost:${API_PORT}/network/options -H 'Content-Type: application/json' --data '{\"network_identifier\": {\"blockchain\": \"cardano\",\"network\": \"${NETWORK}\"},\"metadata\": {}}' -X POST" ]
interval: 30s
retries: 20
start_period: 20s
timeout: 10s
restart: always

volumes:
data:

networks:
default:
name: cardano-rosetta-java-${NETWORK}
42 changes: 0 additions & 42 deletions docker-api-indexer.yaml → docker-compose-indexer.yaml
Original file line number Diff line number Diff line change
@@ -1,47 +1,5 @@
version: '3.8'
services:
api:
image: cardanofoundation/cardano-rosetta-java-api:${API_DOCKER_IMAGE_TAG}
build:
context: ./
dockerfile: ./api/Dockerfile
ports:
- ${API_PORT}:${API_PORT}
environment:
NETWORK: ${NETWORK}
API_SPRING_PROFILES_ACTIVE: ${API_SPRING_PROFILES_ACTIVE}
API_PORT: ${API_PORT}
DB_HOST: ${DB_HOST}
DB_PORT: ${DB_PORT}
DB_NAME: ${DB_NAME}
DB_USER: ${DB_USER}
DB_SECRET: ${DB_SECRET}
DB_SCHEMA: ${DB_SCHEMA}
CARDANO_NODE_VERSION: ${CARDANO_NODE_VERSION}
TOPOLOGY_FILEPATH: ${TOPOLOGY_FILEPATH}
GENESIS_SHELLEY_PATH: ${GENESIS_SHELLEY_PATH}
GENESIS_ALONZO_PATH: ${GENESIS_ALONZO_PATH}
GENESIS_CONWAY_PATH: ${GENESIS_CONWAY_PATH}
CARDANO_NODE_SUBMIT_HOST: ${CARDANO_NODE_SUBMIT_HOST}
NODE_SUBMIT_API_PORT: ${NODE_SUBMIT_API_PORT}
CARDANO_NODE_SOCKET_PATH: ${CARDANO_NODE_SOCKET_PATH}
DEVKIT_ENABLED: ${DEVKIT_ENABLED}
DEVKIT_URL: ${DEVKIT_URL}
DEVKIT_PORT: ${DEVKIT_PORT}
volumes:
- ${CARDANO_CONFIG}:/config
- ${CARDANO_NODE_DIR}:${CARDANO_NODE_DIR}
healthcheck:
test: [ "CMD-SHELL", "curl --fail http://localhost:${API_PORT}/network/options -H 'Content-Type: application/json' --data '{\"network_identifier\": {\"blockchain\": \"cardano\",\"network\": \"${NETWORK}\"},\"metadata\": {}}' -X POST" ]
interval: 30s
retries: 20
start_period: 20s
timeout: 10s
restart: always
depends_on:
db:
condition: service_healthy

yaci-indexer:
image: cardanofoundation/cardano-rosetta-java-indexer:${INDEXER_DOCKER_IMAGE_TAG}
build:
Expand Down
File renamed without changes.
5 changes: 3 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
version: '3.8'
include:
- docker-api-indexer.yaml
- docker-node.yaml
- docker-compose-indexer.yaml
- docker-compose-node.yaml
- docker-compose-api.yaml

networks:
default:
Expand Down
3 changes: 2 additions & 1 deletion docker-integration-test-environment.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
version: '3.8'
include:
- docker-api-indexer.yaml
- docker-compose-indexer.yaml
- docker-compose-api.yaml

services:
yaci-cli:
Expand Down
7 changes: 3 additions & 4 deletions docker/.env.dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# In offline mode there will be no synchronization with the network
# and the following components will be disabled: Node, Submit-api, Mithril, Yaci Indexer
# Set to false if you want to start everything needed to synchronize with the network
OFFLINE_MODE=false
# Set to offline for offline mode
# Set to online for online mode
API_SPRING_PROFILES_ACTIVE=online

## Main variables
LOG=INFO
Expand Down Expand Up @@ -37,8 +38,6 @@ CARDANO_NODE_SUBMIT_HOST=localhost
NODE_SUBMIT_API_PORT=8090
CARDANO_NODE_SOCKET_PATH=/node/node.socket
## Api env
API_SPRING_PROFILES_ACTIVE=dev
# staging, h2, test. Additional profiles: mempool (if mempool should be activated)
API_PORT=8082

ROSETTA_VERSION=1.4.13
Expand Down
Loading

0 comments on commit 7396473

Please sign in to comment.