How sylvia969301/blockchain-based-federated-learning works
Project Type and Purpose
• This is a research/prototype system that combines Federated Learning (FL) with a private Ethereum-based blockchain.
• The “BCFL” directory implements federated learning using the Flower (flwr) framework; the top-level files and “geth”/“miner*” directories set up and run a private Ethereum network for model/result storage or audit.
File Structure
• Top Level
• BCFL/ → Federated learning code and artifacts
• geth/, miner1/, miner2/ → Private blockchain nodes (Geth directories, chaindata, keystore, genesis config)
• client_8080.py, server_8080.py, socket_client.py, socket_server.py → Simple socket-based FL demo endpoints
• requirements.txt → Python dependencies (Flower, PyTorch, Web3 libraries)
• BCFL/flwr/
• client/ → FL client implementations (gRPC, numpy interface)
• server/ → FL server orchestrator, strategies (FedAvg, FedOpt, etc.)
• common/, dataset/ → Shared utilities, data loaders (CIFAR-10)
• proto/ → gRPC transport protobufs
• simulation/ → Ray-based simulations
• BCFL/data/ → CIFAR-10 raw data
• BCFL/aggregated_result → Folder for storing the aggregated model
• Key files: mnist_cnn.pt (model), compiled_code.json, task_owner_key (blockchain‐related keys)
README (empty here)
• No explicit architecture section; infer from code organization and directory names.
Main Components & Their Interactions
a. Federated Learning Layer
• FL Server (BCFL/flwr/server/app.py): orchestrates rounds, applies aggregation strategies
• FL Clients (BCFL/flwr/client/app.py): train on local data partitions and send model updates
• Data Store (BCFL/data/…): local datasets on each client node
• gRPC Transport (proto files + grpc_client/ in client & grpc_server/ in server): handles RPC calls
b. Blockchain Layer
• Geth Bootnode / Genesis Node (geth/, genesis.json, boot.key): the entry point of the private chain
• Miner Nodes (miner1/, miner2/): maintain blockchain, mine blocks, validate transactions
• Keystore & Keys (keystore/, task_owner_key/): accounts for submitting transactions
• Smart‐contract Interface (not explicit here—could be in client/server scripts calling Web3)
c. Control & Integration
• Orchestrator Scripts (server_8080.py, client_8080.py, socket_*.py): lightweight HTTP or socket glue
• Aggregation Export (BCFL/aggregated_result): writes final weights to a file; later submitted to blockchain
• JSON Config (compiled_code.json): possibly contains compiled smart‐contract code for deployment
Architectural Patterns & Principles
• Layered: clear separation between FL layer and blockchain layer
• Modular: each FL strategy in its own module; gRPC code separated from core logic
• Distributed: multiple clients and miners; uses network communication (gRPC, sockets, Ethereum P2P)
• Extensibility: strategies folder allows plugging in new aggregation rules