I am confused by how hyperledger fabric stores data .After I read the offical doc,I know there are two parts in Ledger: WORLD_STATE and BLOCKCHAIN .
I start a fabric network in my computer with couchdb , using command like : ./network.sh createChannel -ca -s couchdb, and init some data stored in Ledger.
But there is my confued:
- if I change the data directly in couchdb like : http://localhost:port/_utils/ , I found that query result also changed when i using command :
peer chaincode query -C mychannel -n CC_NAME -c '{"Args":["QueryAll"]}',is that means anyone can change the ledger without approved by half of all peers? - I am using golang to wirte the code, the queryAll is like:
os.Setenv("DISCOVERY_AS_LOCALHOST", "true")
wallet, err := gateway.NewFileSystemWallet("wallet")
if err != nil {
fmt.Printf("ERROR:%s\n", err)
os.Exit(1)
}
if !wallet.Exists("appUser") {
err = populateWallet(wallet)
if err != nil {
fmt.Printf("Wallet wrong : %s\n", err)
os.Exit(1)
}
}
ccpPath := filepath.Join(
"..",
"..",
"network",
"organizations",
"peerOrganizations",
"org1.example.com",
"connection-org1.yaml",
)
gw, err := gateway.Connect(
gateway.WithConfig(config.FromFile(filepath.Clean(ccpPath))),
gateway.WithIdentity(wallet, "appUser"),
)
if err != nil {
fmt.Printf("failed to connect to net : %s\n", err)
os.Exit(1)
}
defer gw.Close()
network, err := gw.GetNetwork("mychannel")
if err != nil {
fmt.Printf("%s\n", err)
os.Exit(1)
}
fmt.Println("Start to query all")
contract := network.GetContract("project_test")
result, err := contract.EvaluateTransaction("queryAllMessage")
if err != nil {
fmt.Printf("ERROR:%s\n", err)
os.Exit(1)
}
fmt.Println(string(result))
I found that After i change the data directly in couchdb, it can't run and the error is like:
Failed to evaluate: endorsement validation failed: Endorser Client Status Code: (3) ENDORSEMENT_MISMATCH. Description: ProposalResponsePayloads do not match exit status 1
It seems doesn't work if one changed his couchdb .
I want to know why these happend ,and how can I avoid others change database , how can I make sure that the data i get is approved by all peers ? any help could be useful ,thank you.