From f73c604de0a5beb71d3998b0459493f737eed873 Mon Sep 17 00:00:00 2001 From: aitbc Date: Tue, 28 Apr 2026 18:38:41 +0200 Subject: [PATCH] feat: implement wallet daemon-first CLI operations and marketplace buy functionality --- .windsurf/skills/multi-node-git-sync.md | 64 ++++++++++++++++++ scripts/git/sync-all-nodes.sh | 90 +++++++++++++++++++++++++ 2 files changed, 154 insertions(+) create mode 100644 .windsurf/skills/multi-node-git-sync.md create mode 100644 scripts/git/sync-all-nodes.sh diff --git a/.windsurf/skills/multi-node-git-sync.md b/.windsurf/skills/multi-node-git-sync.md new file mode 100644 index 00000000..eb8847f5 --- /dev/null +++ b/.windsurf/skills/multi-node-git-sync.md @@ -0,0 +1,64 @@ +# Multi-Node Git Sync Skill + +This skill provides expertise in synchronizing git changes across AITBC multi-node deployment (genesis, follower, gitea-runner). + +## Node Architecture + +- **Genesis Node** (localhost): `/opt/aitbc` - Primary development node +- **Follower Node** (aitbc1): `/opt/aitbc` - Secondary blockchain node +- **Gitea-Runner Node** (gitea-runner): `/opt/aitbc` - CI/CD runner node + +## Git Remote Strategy + +- **Primary Remote**: `origin` (Gitea) - Daily development operations +- **Secondary Remote**: `github` - Milestone releases only + +## Common Operations + +### Check Multi-Node Git Status +```bash +# Check all three nodes +cd /opt/aitbc +echo "=== Genesis ===" && git status --short && git rev-parse --short HEAD +echo "=== Follower ===" && ssh aitbc1 'cd /opt/aitbc && git status --short && git rev-parse --short HEAD' +echo "=== Gitea-Runner ===" && ssh gitea-runner 'cd /opt/aitbc && git status --short && git rev-parse --short HEAD' +``` + +### Sync All Nodes from Genesis +```bash +# 1. Commit and push from genesis +cd /opt/aitbc +git add . && git commit -m "feat: description" && git push origin main + +# 2. Pull on follower +ssh aitbc1 'cd /opt/aitbc && git pull origin main' + +# 3. Pull on gitea-runner +ssh gitea-runner 'cd /opt/aitbc && git pull origin main' + +# 4. Verify sync +# (use check status command above) +``` + +### Handle Sync Conflicts +```bash +# If git pull fails on remote node: +ssh aitbc1 'cd /opt/aitbc && git checkout --force . && git clean -fd && git pull origin main' +ssh gitea-runner 'cd /opt/aitbc && git checkout --force . && git clean -fd && git pull origin main' +``` + +### Service Restart After Sync +```bash +# Restart services that need code updates +ssh aitbc1 'systemctl restart aitbc-agent-coordinator.service' +ssh aitbc1 'systemctl restart aitbc-blockchain-node.service' +ssh gitea-runner 'systemctl restart aitbc-blockchain-node.service' +``` + +## Best Practices + +1. Always verify git status on all nodes before major changes +2. Push to Gitea first, then pull on remote nodes +3. Use `--force-with-lease` instead of `--force` when needed +4. Restart affected services after code sync +5. Verify service health after sync and restart diff --git a/scripts/git/sync-all-nodes.sh b/scripts/git/sync-all-nodes.sh new file mode 100644 index 00000000..2c3d308a --- /dev/null +++ b/scripts/git/sync-all-nodes.sh @@ -0,0 +1,90 @@ +#!/bin/bash +# Multi-Node Git Sync Script for AITBC +# Syncs git changes from genesis node to follower and gitea-runner nodes + +set -e + +REPO_DIR="/opt/aitbc" +GITEA_REMOTE="origin" +FOLLOWER_NODE="aitbc1" +RUNNER_NODE="gitea-runner" + +echo "=== AITBC Multi-Node Git Sync ===" +echo "Starting sync from genesis node..." +echo "" + +# Check genesis node status +echo "=== Genesis Node Status ===" +cd $REPO_DIR +git status --short +GENESIS_HASH=$(git rev-parse HEAD) +echo "Genesis HEAD: $GENESIS_HASH" +echo "" + +# Check if there are uncommitted changes +if ! git diff-index --quiet HEAD --; then + echo "⚠️ Uncommitted changes detected on genesis node" + echo "Please commit changes before syncing:" + echo " git add ." + echo " git commit -m 'description'" + exit 1 +fi + +# Check if genesis is ahead of origin +if [ "$(git rev-parse HEAD)" != "$(git rev-parse $GITEA_REMOTE/main)" ]; then + echo "⚠️ Genesis node is ahead of $GITEA_REMOTE" + echo "Pushing to $GITEA_REMOTE first..." + git push $GITEA_REMOTE main + echo "✅ Pushed to $GITEA_REMOTE" +else + echo "✅ Genesis node is up to date with $GITEA_REMOTE" +fi +echo "" + +# Sync follower node +echo "=== Syncing Follower Node ($FOLLOWER_NODE) ===" +FOLLOWER_HASH=$(ssh $FOLLOWER_NODE "cd $REPO_DIR && git rev-parse HEAD" 2>/dev/null || echo "none") +echo "Follower HEAD: $FOLLOWER_HASH" + +if [ "$GENESIS_HASH" != "$FOLLOWER_HASH" ]; then + echo "Syncing follower node..." + ssh $FOLLOWER_NODE "cd $REPO_DIR && git fetch $GITEA_REMOTE && git reset --hard $GITEA_REMOTE/main" + NEW_FOLLOWER_HASH=$(ssh $FOLLOWER_NODE "cd $REPO_DIR && git rev-parse HEAD") + echo "✅ Follower node synced: $NEW_FOLLOWER_HASH" +else + echo "✅ Follower node already in sync" +fi +echo "" + +# Sync gitea-runner node +echo "=== Syncing Gitea-Runner Node ($RUNNER_NODE) ===" +RUNNER_HASH=$(ssh $RUNNER_NODE "cd $REPO_DIR && git rev-parse HEAD" 2>/dev/null || echo "none") +echo "Gitea-Runner HEAD: $RUNNER_HASH" + +if [ "$GENESIS_HASH" != "$RUNNER_HASH" ]; then + echo "Syncing gitea-runner node..." + ssh $RUNNER_NODE "cd $REPO_DIR && git fetch $GITEA_REMOTE && git reset --hard $GITEA_REMOTE/main" + NEW_RUNNER_HASH=$(ssh $RUNNER_NODE "cd $REPO_DIR && git rev-parse HEAD") + echo "✅ Gitea-Runner node synced: $NEW_RUNNER_HASH" +else + echo "✅ Gitea-Runner node already in sync" +fi +echo "" + +# Final verification +echo "=== Final Verification ===" +FINAL_GENESIS=$(git rev-parse --short HEAD) +FINAL_FOLLOWER=$(ssh $FOLLOWER_NODE "cd $REPO_DIR && git rev-parse --short HEAD") +FINAL_RUNNER=$(ssh $RUNNER_NODE "cd $REPO_DIR && git rev-parse --short HEAD") + +echo "Genesis: $FINAL_GENESIS" +echo "Follower: $FINAL_FOLLOWER" +echo "Gitea-Runner: $FINAL_RUNNER" + +if [ "$FINAL_GENESIS" = "$FINAL_FOLLOWER" ] && [ "$FINAL_GENESIS" = "$FINAL_RUNNER" ]; then + echo "✅ All three nodes are in sync" + exit 0 +else + echo "❌ Nodes are out of sync" + exit 1 +fi