This guide provides step-by-step instructions for running your Hyperledger Fabric project with the priority-based transaction gateway and batcher.
β Fabric Network: Running (31 minutes uptime)
- Orderer:
orderer.example.com(Port 7050) - Peer:
peer0.org1.example.com(Port 7051)
β Chaincode: Not deployed yet (namespace 'wallet' not defined)
The chaincode must be deployed before you can submit transactions. Run the deployment script:
cd /Users/sathvikcustiv/fabric-dev/priority-fabric-project
./deploy-chaincode.shWhat this does:
- Verifies Fabric network is running
- Packages the wallet chaincode
- Installs on Org1 and Org2 peers
- Approves for both organizations
- Commits to the mychannel channel
- Verifies deployment
Expected output:
π SUCCESS! Chaincode deployed successfully!
π Deployment Summary:
Chaincode Name: wallet
Version: 1.5
Channel: mychannel
Package ID: wallet_1.5:xxxxx
Once chaincode is deployed, start the gateway server that includes the batcher:
# Option A: Using the convenience script
./start.sh --fabric --port 8080
# Option B: Direct Go execution
go run . --port=8080 --use-fabric --batch-size=100 --batch-timeout=2sCommand-line flags:
--port=8080- HTTP server port--use-fabric- Connect to Fabric network (REQUIRED for real transactions)--batch-size=100- Number of transactions per batch--batch-timeout=2s- Maximum time before processing batch--mempool-size=1000- Maximum mempool capacity--verbose- Enable detailed logging
What the batcher does:
- Collects transactions from the mempool
- Groups them into batches based on size/timeout triggers
- Alternates between priority-only and anti-starvation modes
- Submits batches to Fabric for consensus and commitment
Server will start on: http://localhost:8080
Now you can submit transactions through the HTTP API. The gateway will queue them in the mempool, and the batcher will process them.
curl -X POST http://localhost:8080/submit \
-H "Content-Type: application/json" \
-d '{
"from": "wallet1",
"to": "wallet2",
"amount": "100",
"txType": "swap"
}'Response:
{
"transactionId": "abc123...",
"status": "queued",
"priority": 0,
"message": "Transaction queued with priority 0"
}curl -X POST http://localhost:8080/submit \
-H "Content-Type: application/json" \
-d '{
"from": "wallet3",
"to": "wallet4",
"amount": "500",
"txType": "borrow"
}'curl -X POST http://localhost:8080/submit \
-H "Content-Type: application/json" \
-d '{
"from": "wallet5",
"to": "wallet6",
"amount": "50",
"txType": "transfer"
}'swap- Priority 0 (highest) - Processed firstborrow- Priority 1 (high)lend- Priority 2 (medium)transfer- Priority 3 (lowest)
curl http://localhost:8080/mempool/statusResponse shows:
{
"totalTransactions": 15,
"byPriority": {
"0": 5, // swap
"1": 3, // borrow
"2": 4, // lend
"3": 3 // transfer
},
"oldestTransaction": "2024-11-27T12:20:00Z"
}curl http://localhost:8080/batcher/statusResponse shows:
{
"currentBatchNumber": 5,
"mode": "anti-starvation",
"transactionsProcessed": 450,
"batchesCompleted": 4,
"averageBatchSize": 112.5
}curl http://localhost:8080/transactions/completedcurl http://localhost:8080/transaction/status?id=abc1231. Client submits transaction via curl
β
2. Gateway receives and validates transaction
β
3. Transaction added to Priority Mempool (sorted by priority)
β
4. Batcher monitors mempool for batch triggers:
- Size threshold (e.g., 100 transactions)
- Time threshold (e.g., 2 seconds)
β
5. Batcher extracts batch (alternates priority/anti-starvation modes)
β
6. For each transaction in batch:
- Sent to Fabric peer via gRPC
- Peer endorses (executes chaincode)
- Endorsement returned to gateway
β
7. Gateway submits endorsed transactions to orderer
β
8. Orderer creates block and broadcasts to peers
β
9. Peers validate and commit block to ledger
β
10. Transaction confirmed β
(permanently on blockchain)
Use the provided test script to see how the batcher handles priority and anti-starvation:
cd /Users/sathvikcustiv/fabric-dev/priority-fabric-project
./test_anti_starvation.sh http://localhost:8080What the test does:
- Submits 10+ transactions with mixed priorities
- Shows batch 1 (priority-only): High-priority transactions processed first
- Shows batch 2 (anti-starvation): Fair quota for all priority levels
- Demonstrates that low-priority transactions aren't starved
Solution: Chaincode not deployed. Run:
./deploy-chaincode.shSolution: Check network status:
docker ps | grep peer0.org1.example.comIf not running:
cd /Users/sathvikcustiv/fabric-dev/fabric-samples/test-network
./network.sh up createChannelSolution: Kill existing process or use different port:
# Option 1: Kill process on port 8080
lsof -ti:8080 | xargs kill -9
# Option 2: Use different port
go run . --port=8081 --use-fabricCheck:
- Batch size threshold: Have enough transactions been queued?
- Batch timeout: Has enough time passed?
- Server logs: Look for error messages
- Fabric connection: Ensure
--use-fabricflag is set
Solution: Check batcher logs and verify:
- Fabric network is running
- Chaincode is deployed
- No endorsement failures in logs
docker psdocker logs peer0.org1.example.com -fdocker logs orderer.example.com -fcd /Users/sathvikcustiv/fabric-dev/fabric-samples/test-network
export PATH=${PWD}/../bin:$PATH
export FABRIC_CFG_PATH=$PWD/../config/
export CORE_PEER_TLS_ENABLED=true
export CORE_PEER_LOCALMSPID="Org1MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
export CORE_PEER_ADDRESS=localhost:7051
peer lifecycle chaincode querycommitted -C mychannel -n wallet# Terminal 1: Deploy chaincode (one-time setup)
cd /Users/sathvikcustiv/fabric-dev/priority-fabric-project
./deploy-chaincode.sh
# Terminal 1: Start gateway with batcher
./start.sh --fabric --port 8080
# Terminal 2: Submit transactions
curl -X POST http://localhost:8080/submit \
-H "Content-Type: application/json" \
-d '{"from":"wallet1","to":"wallet2","amount":"100","txType":"swap"}'
# Terminal 2: Monitor status
curl http://localhost:8080/mempool/status
curl http://localhost:8080/batcher/status
curl http://localhost:8080/transactions/completed- Full README:
priority-fabric-project/README.md - Dashboard Guide:
priority-fabric-project/DASHBOARD_README.md - Test Script:
priority-fabric-project/test_anti_starvation.sh - Fabric Docs: https://hyperledger-fabric.readthedocs.io/
To run your project:
- Deploy chaincode (one-time):
./deploy-chaincode.sh - Start server with batcher:
./start.sh --fabric --port 8080 - Submit transactions: Use curl with POST to
/submitendpoint - Monitor: Check
/mempool/status,/batcher/status,/transactions/completed