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

Execute execution results are not uploaded to the chain #293

Open
ZhaoYP-2001 opened this issue Feb 11, 2025 · 4 comments
Open

Execute execution results are not uploaded to the chain #293

ZhaoYP-2001 opened this issue Feb 11, 2025 · 4 comments

Comments

@ZhaoYP-2001
Copy link

I use the following code to call the chaincode. First, I use client A to write the world state, and then I use client B to read the value from the world state. But the data I read from B is the old value instead of the value just written to the world state. Why?

Doesn't Execute return the result only after receiving the information that the peer node has successfully verified it?

id := "1"
data := "data"

TestWriteReq := channel.Request{
    ChaincodeID: constant.CHAINCODE_ID,
    Fcn:         "WriteWorldState",
    Args:        [][]byte{[]byte(id), []byte(data)},
}
res, err = AClient.Execute(TestWriteReq, channel.WithTargetEndpoints("peer0.org1"))

TestReadReq := channel.Request{
    ChaincodeID: constant.CHAINCODE_ID,
    Fcn:         "ReadWorldState",
    Args:        [][]byte{[]byte(id), []byte(data)},
}

res, err = BClient.Execute(TestReadReq, channel.WithTargetEndpoints("peer0.org2"))

My test chaincode is as follows


import (
	"fmt"
	"github.com/hyperledger/fabric-contract-api-go/contractapi"
)

func main() {

	contract := new(Contract)
	contract.Name = "org.papernet.commercialpaper"
	contract.Info.Version = "0.0.1"

	chaincode, err := contractapi.NewChaincode(contract)

	if err != nil {
		panic(fmt.Sprintf("Error creating chaincode. %w", err))
	}

	chaincode.Info.Title = "CommercialPaperChaincode"
	chaincode.Info.Version = "0.0.1"

	err = chaincode.Start()

	if err != nil {
		panic(fmt.Sprintf("Error starting chaincode. %s", err.Error()))
	}
}

type Contract struct {
	contractapi.Contract
}

func (c *Contract) WriteWorldState(ctx contractapi.TransactionContextInterface, id string, data string) error {
	return ctx.GetStub().PutState(id, []byte(data))
}

func (c *Contract) ReadWorldState(ctx contractapi.TransactionContextInterface, id string, trueData string) error {
	data, err := ctx.GetStub().GetState(id)
	if err != nil {
		return err
	}
	if trueData != string(data) {
		return fmt.Errorf("Origin: %s, Read: %s", trueData, string(data))
	}
	return nil
}

func (c *Contract) WritePrivateDataCollection(ctx contractapi.TransactionContextInterface, id string, prvData string) error {
	return ctx.GetStub().PutPrivateData("USER-PLATFORM", id, []byte(prvData))
}
func (c *Contract) ReadPrivateDataCollection(ctx contractapi.TransactionContextInterface, id string, truePrvData string) error {
	prvData, err := ctx.GetStub().GetPrivateData("USER-PLATFORM", id)
	if err != nil {
		return err
	}
	if truePrvData != string(prvData) {
		return fmt.Errorf("Prv Origin: %s, Read: %s", truePrvData, string(prvData))
	}
	return nil
}```
@ZhaoYP-2001
Copy link
Author

In addition, I found that this situation only occurs when the TPS is > 10.

@pfi79
Copy link
Contributor

pfi79 commented Feb 11, 2025

Note: This API is deprecated and is no longer maintained as of Fabric v2.5. When developing applications for Hyperledger Fabric v2.4 and later, you should use the Fabric Gateway client API.

@ZhaoYP-2001
Copy link
Author

Note: This API is deprecated and is no longer maintained as of Fabric v2.5. When developing applications for Hyperledger Fabric v2.4 and later, you should use the Fabric Gateway client API.

I am using v2.3, do you have any other suggestions?

@pfi79
Copy link
Contributor

pfi79 commented Feb 12, 2025

Note: This API is deprecated and is no longer maintained as of Fabric v2.5. When developing applications for Hyperledger Fabric v2.4 and later, you should use the Fabric Gateway client API.

I am using v2.3, do you have any other suggestions?

version 2.3 is no longer supported

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants