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

Persistent storage solution #132

Merged
merged 34 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
4ddba50
Merge branch 'quorum-calc' into persistent-storage-solution
Sarahtonein Jan 15, 2025
d801f2a
Basic db implementation / migration with basic test. Update commands …
Sarahtonein Jan 16, 2025
12bf369
Update README, Changelog, and .env.example
Sarahtonein Jan 17, 2025
9c52de0
Add database models, service and test script
Sarahtonein Jan 17, 2025
f21884c
update docker-compose, tasks, utils, proposals, events to work wtih d…
Sarahtonein Jan 17, 2025
ed87eec
Update .env.example, tests and emoji processing for contributors
Sarahtonein Jan 17, 2025
7dc6ddc
fmt
Sarahtonein Jan 17, 2025
f121fc3
logs for service and db querying
Sarahtonein Jan 17, 2025
7033942
Update serivce.py for tests
Sarahtonein Jan 17, 2025
c1e3ea5
resolve merge conflict, merge in scrape-props after quorum calc merge
Sarahtonein Jan 19, 2025
76a688c
update tag validation
Sarahtonein Jan 20, 2025
cd0da70
Merge branch 'dev' into persistent-storage-solution
bagelface Jan 20, 2025
2adac5b
Remove requirements.txt, adjut to config_data volume name in docker-c…
Sarahtonein Jan 20, 2025
6a56174
revert to 30 min timer
Sarahtonein Jan 22, 2025
624b106
Remove alembic usage
Sarahtonein Jan 22, 2025
27c77a3
Change CI action to not test migrations repeatedly
Sarahtonein Jan 22, 2025
983d571
create pytest.ini and consolidate test logic
Sarahtonein Jan 22, 2025
ecee15b
Update README, and CHANGELOG
Sarahtonein Jan 22, 2025
7351005
Add server ID for contributors
Sarahtonein Jan 22, 2025
f3b6051
Update database models, service and associated scripts
Sarahtonein Jan 22, 2025
98fdcb8
Update task time, and tests cripts
Sarahtonein Jan 22, 2025
cc81b07
Update utils to work with db
Sarahtonein Jan 22, 2025
56220c5
Update Docker compatability
Sarahtonein Jan 22, 2025
36cee77
Remove alembic.ini
Sarahtonein Jan 22, 2025
f1ec229
Update README to reflect dev / prod and test suite
Sarahtonein Jan 22, 2025
0822a3f
Remove packages pipfile, update Dockerfile to be streamlined, and .gi…
Sarahtonein Jan 29, 2025
d10bd16
Update to resolve runtime errors
Sarahtonein Jan 29, 2025
04541db
cogs logic and additional logging
Sarahtonein Feb 3, 2025
097e2e4
Remove old JSON file paths
Sarahtonein Feb 3, 2025
35b02e9
sqlalchmey import for models, relocate utils logic to service
Sarahtonein Feb 3, 2025
76520c8
Reorg logic of functions
Sarahtonein Feb 3, 2025
9fa1104
Update tests, proposals using DB, reorg task
Sarahtonein Feb 3, 2025
8a9c184
Readme update, simplify Dockerfile, update piplock and main
Sarahtonein Feb 3, 2025
9926692
Update github workflow and proposal comments
Sarahtonein Feb 3, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
DISCORD_BOT_TOKEN=MTE3
ETH_ADDRESS=0x5B3eADC3
ETH_PRIVATE_KEY=0x834q5nmsgkseg4wg4
PRIMARY_RPC_URL=https://sepolia.drpc.org
SECONDARY_RPC_URL=https://1rpc.io/sepolia
DISCORD_BOT_TOKEN=your_discord_bot_token_here
ETH_ADDRESS=your_eth_address
ETH_PRIVATE_KEY=your_eth_private_key
PRIMARY_RPC_URL=your_primary_RPC-url
SECONDARY_RPC_URL=your_secondary_rpc_url

# Database Configuration
DB_USER=bloom
DB_PASSWORD=bloom
DB_NAME=bloombot

# Environment
ENV=DEV
29 changes: 29 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Tests

on: [push, pull_request]

jobs:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.11'

- name: Install pipenv
run: |
python -m pip install --upgrade pip
pip install pipenv

- name: Install dependencies
run: pipenv install --dev

- name: Run tests
env:
DB_PASSWORD: test_password
ENV: TEST
run: pipenv run python -m pytest tests/ -v
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#env
.env

# Custom
testing.py

Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed
- Migration script from JSON file storage to PostgreSQL database
- Added database models for Contributors, Events, OngoingVotes, and ConcludedVotes
- Updated configuration to use environment variables for database credentials
- Added database query script for viewing stored data

## [0.2.1] - 28-2-2024

### Added
Expand Down
8 changes: 1 addition & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
FROM python:3.11

# Install pipenv and compilation dependencies
RUN pip install pipenv
RUN apt-get update && apt-get install -y --no-install-recommends gcc

# Install Node.js and npm
RUN curl -sL https://deb.nodesource.com/setup_18.x | bash -
RUN apt-get install -y nodejs

WORKDIR /app

# Copy Pipfile and install dependencies
COPY Pipfile .
RUN pipenv install --deploy

# Copy JavaScript dependencies files and install
COPY snapshot/package*.json /app/snapshot/
RUN cd /app/snapshot && npm install

# Copy the entire application
COPY . /app

# Command to run the application
CMD ["pipenv", "run", "python", "main.py"]
CMD ["pipenv", "run", "python", "main.py"]
11 changes: 7 additions & 4 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ name = "pypi"

[packages]
"discord.py" = "*"
"pytz" = "*"
"requests" = "*"
"configparser" = "*"
"Web3" = "*"
requests = "*"
configparser = "*"
web3 = "*"
sqlalchemy = "*"
psycopg2-binary = "*"

[dev-packages]
pytest = "*"
pytest-asyncio = "*"

[requires]
python_version = "3.11"
330 changes: 292 additions & 38 deletions Pipfile.lock

Large diffs are not rendered by default.

74 changes: 45 additions & 29 deletions README.md
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docs need a little clean up. There is inconsistent stylizing throughout and probably is a bit wordier than it needs to be. If you agree, can you make a separate issue for that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docs need a little clean up. There is inconsistent stylizing throughout and probably is a bit wordier than it needs to be. If you agree, can you make a separate issue for that.

Agree it can be reduced in size. Will create an issue for this.

Original file line number Diff line number Diff line change
Expand Up @@ -255,49 +255,65 @@ Contributor added successfully!

# Manually publishing proposals via the bot

In the event that the bot goes down, or there is some other issue with a proposal being pushed to Snapshot, the following steps can be taken. These steps can be done locally, utilizing the test server
In the event that the bot goes down, or there is some other issue with a proposal being pushed to Snapshot, the following steps can be taken. These steps can be done locally, utilizing the test server:

1. Replicate the proposal locally with the bot (Copy / Paste the text & Markdown from the posted proposal in Discord)

2. Create / Publish the proposal. by using /vote_draft & /publish_draft locally.
2. Create / Publish the proposal by using /vote_draft & /publish_draft locally.

3. Stop the local running of the bot in the test server

4. Access ./data/ongoing_votes.json, copy the proposal object

**Example:**

4. Use the query_db.py script to verify the proposal data:
```bash
python scripts/query_db.py --table ongoing_votes
```

Example proposal data structure:
```python
{
"1232974623113744386": {
"draft": {
"member_id": 316765092689608706,
"title": "Annual BVI Services Fee",
"type": "budget",
"abstract": "**Authors**\nSarahtonein\n\n**Type**\nImbursement\n\n**Definitions**\n**British Virgin Islands LTD (BVI LTD):** Refers to a limited liability company formed and registered in the British Virgin Islands.\n\n**Flag Theory:** A strategic framework used for globalizing personal and business operations. The term refers to the service provider engaged by Bloom Studio to assist in the establishment, maintenance, and legal compliance of the BVI LTD.\n\n**EVM Address:** Ethereum Virtual Machine Address. A unique identifier associated with the blockchain wallet used for transactions.\n\n**Abstract**\nThis proposal seeks approval for the annual service fee payment to Flag Theory, essential for the maintenance and compliance of the British Virgin Islands LTD associated with Bloom Studio. The document details the service fee amount and the necessary payment details, providing a basis for members to vote on the continued support of these essential corporate services.",
"background": "**Background**\nBloom Studio has engaged Flag Theory for the establishment and ongoing maintenance of a corporate entity in the British Virgin Islands (BVI). This strategic partnership ensures compliance with BVI legal and regulatory requirements, which is crucial for maintaining our corporate presence and operational efficiency in the region. To uphold these standards and continue benefiting from Flag Theory's expert services, an annual payment is necessary. This proposal outlines the specifics of the payment and the value derived from this continued collaboration.\n\n**Imbursement Specifics**\n- Amount - $1925\n- EVM Address - 0x9970ff60d7924d4cbaa161c6334fcab9fd859050\n- Invoice details - https://bafybeidujjzbmtiwxhmgpzlxf6bj4gt736vb4ojyhgq6s2qsxkfwew3eie.ipfs.w3s.link/Invoice_INV-7037.pdf",
"additional": "**Voting Options**\n```\nAdopt\nReassess\nAbstain\n```"
},
"end_time": 1713962888,
"yes_count": 0,
"title": "Bloom Budget Proposal (BBP) #2: Annual BVI Services Fee",
"channel_id": "1191283982768287795",
"thread_id": "1232152965490413630",
"message_id": "1232152968225357895"
}
"proposal_id": "1232974623113744386",
"draft": {
"member_id": 316765092689608706,
"title": "Annual BVI Services Fee",
"type": "budget",
"abstract": "...",
"background": "...",
"additional": "..."
},
"end_time": 1713962888,
"title": "Bloom Budget Proposal (BBP) #2: Annual BVI Services Fee",
"channel_id": "1191283982768287795",
"thread_id": "1232152965490413630",
"message_id": "1232152968225357895"
}

```

5. Modify the end_time value so that it is *any* time in the past as long as it is 48+ hours from when the proposal that failed to be published concluded.
5. If needed, you can modify the proposal data using the database CLI:
- Modify `end_time` to any time in the past (48+ hours from when the proposal concluded)
- Update channel_id to match the correct channel (improvement-props: 1191283932096905307 or budgetary-props: 1191283982768287795)
- Update `thread_id` and `message_id` to match the Discord thread

6. Modify channel_id, thread_id, message_id so that it matches the channel ID (improvement-props OR budgetary-props 1191283932096905307 and 1191283982768287795 respectively), thread_id (the thread_id of the thread the discord bot created within the forum channel), and the message_id (the message the bot sent that contains the voting options (yes / reasses / abstain))
6. Build & run the bot

7. Modify the BGP / BBP # under the title property, as it will be a default of 0 most likely. Check the Discord thread for the BGP / BBP # if you do not know what number we are up to.
The bot will run the scheduled task check_concluded_proposals_task in 5 minutes time. If all has been done correctly, you should see:
- The concluded message in the bot logs
- The conclusion message under the Discord proposal thread
- The proposal created in Snapshot

8. Copy & paste the updated json object into the VM repository ./data/ongoing_votes.json
## Database Environment Setup

Required environment variables:
- `DB_PASSWORD`: Database password for PostgreSQL
- `ENV`: Set to "DEV" for testing/development

Example `.env`:
```bash
DB_PASSWORD=your_password_here
ENV=DEV
```

9. Build & run the bot
The bot connects to PostgreSQL using:
- `DATABASE_URL` if provided (e.g., Heroku's database URL)
- Default URL `postgresql://bloom:{DB_PASSWORD}@localhost:5432/bloombot` if only `DB_PASSWORD` is set

The bot should run the scheduled task check_concluded_proposals_task in 5 minutes time, if all has been done correctly you should see the concluded message in the bot logs, and under the thread that has the Discord proposal. You should also see the proposal created in Snapshot.
Note: PostgreSQL is required for both development and production environments. Only test suites use SQLite in-memory databases.
Loading