Skip to content

Commit

Permalink
Refactor Steem Account Data Updater: Configuration, Error Handling, a…
Browse files Browse the repository at this point in the history
…nd Performance Improvements (#14)

* Update README.md
* Optimize Block Fetching for Faster Blockchain Sync

Modified code to fetch historical blocks in batches of 50 and, once reaching the head block, switch to fetching one block every 3 seconds with retry logic on RPC failure. This approach significantly speeds up the blockchain synchronization process, achieving up to 60% faster sync times in test scenarios.

Changes include:
- Implemented batch fetching of historical blocks, processing up to 50 blocks per batch.
- Added logic to switch to single block fetching mode with a 3-second interval once the head block is reached.
- Introduced retry mechanism on RPC failures to ensure robustness and continuous operation.

These enhancements provide a more efficient and reliable syncing process, allowing for quicker catching up with the latest blocks.

* Batching Operations
Batching Operations and change Dockerfile

* Update history.py

Import re module: Added the import statement for the re module.
Fixed logger.error call: Corrected the logger.error call to ensure proper formatting of the error message.

Fixed the TypeError: Updated the get_batch_account_details function to use next(rpc.nodes) to get the current node from the cycle instead of using indexing.

* Update history script to support configuration via both config.json and environment variables

- Modified Dockerfile to install necessary dependencies and Python packages.
- Updated history.py to load configuration from config.json if present, otherwise fallback to environment variables.
- Added detailed README.md to document the setup, configuration, and usage of the Steem account data updater.

* Renamed config.jsot to config.jsob.example

Renamed config.json to config.jsob.example   . Developers can Decide to use config.json or directly pass env variables

---------

Co-authored-by: BottoSteem <>
  • Loading branch information
BottoStm authored Jul 20, 2024
1 parent 419f7ef commit 7e90248
Show file tree
Hide file tree
Showing 8 changed files with 425 additions and 910 deletions.
21 changes: 15 additions & 6 deletions docker/history/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
FROM python:3.6.2-slim
# Use an official Python runtime as a parent image
FROM python:3.9-slim

# Install system dependencies
RUN apt-get update && \
apt-get install -y git make gcc libssl-dev libgmp-dev python-dev libxml2-dev libxslt1-dev zlib1g-dev
apt-get install -y --no-install-recommends git make gcc libssl-dev libgmp-dev python3-dev libxml2-dev libxslt1-dev zlib1g-dev && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

RUN pip3 install steem pymongo apscheduler
# Install Python packages
RUN pip install --no-cache-dir steem pymongo apscheduler requests tenacity

COPY ./docker/history /src
ADD ./rds-combined-ca-bundle.pem /src/rds-combined-ca-bundle.pem
# Copy the application code into the container
COPY . /src

CMD ["python", "/src/history.py"]
# Set the working directory
WORKDIR /src

# Command to run the application
CMD ["python", "history.py"]
79 changes: 79 additions & 0 deletions docker/history/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@

# 🌟 Steem Account Data Updater

This repository contains a sophisticated script designed to update and maintain Steem account data and associated properties within MongoDB. It retrieves data from the Steem blockchain and ensures its currency through scheduled updates.

## ✨ Features
- **Efficient Data Retrieval**: Leverages batch requests to the Steem API for optimal data fetching.
- **Comprehensive Data Storage**: Stores detailed Steem account information and global properties in MongoDB.
- **Structured Logging and Error Handling**: Provides robust mechanisms for logging and error management.
- **Automated Scheduling**: Utilizes APScheduler to perform regular updates, ensuring data remains current.

## 📋 Requirements
- Python 3.9
- MongoDB
- Docker (for containerized deployment)

## ⚙️ Configuration
Create a `config.json` file in the root directory with the following structure:

```json
{
"STEEMD_URLS": ["https://api.steemit.com"],
"MONGODB": "your_mongodb_connection_string"
}
```

Alternatively, configure via environment variables when running the Docker container:

- `STEEMD_URLS`: A comma-separated list of Steem node URLs.
- `MONGODB`: The MongoDB connection string.

## 🚀 Installation

1. Clone the repository:
```sh
git clone https://github.com/your-repo/steem-account-updater.git
cd steem-account-updater
```

2. Build the Docker image:
```sh
docker build -t steem-history .
```

3. Rename `config.json.example` to `config.json` if using the file for configuration:
```sh
mv config.json.example config.json
```

4. Run the Docker container using environment variables (if not using `config.json`):
```sh
docker run -d --name steem-history -e STEEMD_URLS="http://10.10.100.12:8080" -e MONGODB="mongodb://10.10.100.30:27017" steem-history
```

5. Run the Docker container with `config.json`:
```sh
docker run -d --name steem-history -v $(pwd)/config.json:/src/config.json steem-history
```

## 📚 Usage
The script executes the following tasks:
1. **Client Information Update**: Refreshes the client data to maintain accuracy.
2. **Global Properties Update**: Keeps global blockchain properties up-to-date.
3. **Account MVests Load**: Fetches and updates the MVests (Million Vests) per account.
4. **Transaction History Update**: Ensures the transaction history is current.
5. **Account Details Processing**: Processes and inserts comprehensive account details into MongoDB.

Monitor logs using:
```sh
docker logs --follow steem-history
```

## 🤝 Contributing
Pull requests are welcome. For substantial changes, please open an issue to discuss your proposed modifications.

Please ensure that you update tests as necessary.

## 📜 License
This project is licensed under the MIT License - see the [LICENSE](https://choosealicense.com/licenses/mit/) file for details.
5 changes: 5 additions & 0 deletions docker/history/config.json.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"STEEMD_URL": "http://10.10.100.12:8080",
"MONGODB": "mongodb://10.10.100.30:27017/"
}

35 changes: 0 additions & 35 deletions docker/history/fix.py

This file was deleted.

Loading

0 comments on commit 7e90248

Please sign in to comment.