IBM-Blockchain-Archive / marbles

WARNING: This repository is no longer maintained ⚠️ This repository will not be updated. The repository will be kept available in read-only mode.
Apache License 2.0
1.03k stars 979 forks source link

Error:Failed to execute transaction or query(Timeout expired while executing transaction) #107

Closed suffiasameera closed 7 years ago

suffiasameera commented 7 years ago

I get this response when I query my chaincode on Bluemix.

Error when querying chaincode: Error:Failed to execute transaction or query(Timeout expired while executing transaction)

The chaincode I've deployed has a table. Are there any changes due to migration of version in the table format?

dshuffma-ibm commented 7 years ago

unfortunately this can be caused by a lot of different things. since you modified the chaincode it makes me lean towards the situation where your chaincode container fails to start. the chaincode is probably syntactically correct since you did not get a build error, but the Init() function may be throwing an error that the chaincode didn't catch. therefore the chaincode container is crashing. this also means you can't get logs for it...

there is no clear fix, other than to make sure the init function has no reason to unexpectedly fail. as a sanity check try deploying the vanilla marbles chaincode and querying against it. if that doesn't work either, then your error is something different entirely.

one low hanging fruit thing to check is if the timeout is not high enough. if your blockchain network or your application has high latency/slow internet access then try bumping up the timeouts

suffiasameera commented 7 years ago

@dshuffma-ibm I'm actually not using the hfc. Instead I'm directly using a node.js code to make REST calls to the chaincode. How do I increase the timeout in such a case?

suffiasameera commented 7 years ago

And the logs for Query don't even appear

dshuffma-ibm commented 7 years ago

I think we need to start from the beginning.

Did deploy work? What response did you get back. Also is this a local network or one on Bluemix.

suffiasameera commented 7 years ago

@dshuffma-ibm Yes, deploy worked. The network is on Bluemix. When querying, the timeout error response is coming. When I checked the logs I realized that Invoke didn't really get completed. Trying to figure out that. I'll get back to you.

Thanks:)

On Wed, May 31, 2017 at 7:21 PM, dshuffma-ibm notifications@github.com wrote:

I think we need to start from the beginning.

Did deploy work? What response did you get back. Also is this a local network or one on Bluemix.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/IBM-Blockchain/marbles/issues/107#issuecomment-305192761, or mute the thread https://github.com/notifications/unsubscribe-auth/AYklFMaHNLCShZNgMSUqfPjiGC853b4Rks5r_XBHgaJpZM4Np8eQ .

suffiasameera commented 7 years ago

What should the format of the arguments be for invoke function, if my blockchain code should accept a JSON structure?

Eg: type Foo struct { Number int json:"number" Title string json:"title" }

For the above JSON struct, how should I enter args in the form of 1 string for an invoke?

dshuffma-ibm commented 7 years ago

You need to stringify the object since chaincode arguments must be a string.

JSON.stringify({"testing": "things", "string": "me"});

It should have \ to escape the inner quotes. Like:

"{\"testing\": \"things\", \"string\": \"me\"}"
suffiasameera commented 7 years ago

@dshuffma-ibm Thank you so much! :)

suffiasameera commented 7 years ago

But, I'm still getting this error message : Error:Failed to execute transaction or query(Timeout expired while executing transaction) for the Query function

suffiasameera commented 7 years ago

On querying, the result returns an empty Row from the table. Any idea why this happens? Followed by that I get the "Timeout expired" response.

dshuffma-ibm commented 7 years ago

To solve the timeout you should look into the logs of the chaincode container and see if it received the query. If not, then look at the peer'r logs. Hopefully one of these two places gives you an idea of whats going on. Since you are using the Bluemix service, you can get to the logs via the UI.

As for an empty row, this will happen with any query who's key doesn't exist. You can add debug print statements to your chaincode to help debug whats going on. I'd some debug prints to they query part of your chaincode to see if its getting the right input, and what output its sending.

suffiasameera commented 7 years ago

@dshuffma-ibm Thanks! I figured that out. If the table has more than one key, then it throws an error. Is there any alternative, if I have to retrieve a record based on different fields, because setting more than one field as key is giving the timeout error response.

dshuffma-ibm commented 7 years ago

oh, well that sucks. I'm not familiar with the table queries. I prefer to use the key/value pair options. Where the value is JSON.

ie I can store:

{ 
 "this": "here",
 "as": false,
 "and": 5
}

in the key testing. when I read the key testing i'll get that JSON as a string. Then in JS I can JSON.parse(theString) to convert it to an object.

this does have the downside of having to write the entire thing when you want to edit it.

suffiasameera commented 7 years ago

Oh okay! How if I have to store the table's data into a map? For example:

+------+-----------------------+--------+ | NAME | SIGN | RATING | +------+-----------------------+--------+ | A | The Good | 500 | | B | The Very very Bad Man | 288 | | C | The Ugly | 120 | | D | The Gopher | 800 | +------+-----------------------+--------+

If this is my table, how can I visualize it as a map?

suffiasameera commented 7 years ago

Also, if I store the data redundantly in a map, then will I be able to query it based on different fields? Please guide me through this.

dshuffma-ibm commented 7 years ago

Nope, you can't query on based on fields inside the object. Well at least with the default setup. If thats not a problem then you can store it like:

{
    "entries": [{
            "name": "A",
            "sign": "The Good",
            "rating": 500
        },
        {
            "name": "B",
            "sign": "The Very very Bad Man",
            "rating": 288
        },
        {
            "name": "C",
            "sign": "The Ugly ",
            "rating": 120
        },
        {
            "name": "D",
            "sign": "The Gopher ",
            "rating": 800
        }
    ]
}

or

{
    "A": {
        "sign": "The Good",
        "rating": 500
    },
    "B": {
        "sign": "The Very very Bad Man",
        "rating": 288
    },
    "C": {
        "sign": "The Ugly ",
        "rating": 120
    },
    "D": {
        "sign": "The Gopher ",
        "rating": 800
    }
}
mochechan commented 7 years ago

I faced the same problem too. When my chaincode attempt to run stub.GetState(key), where key does not exist, the chaincode crashes. However, there is no function like stub.ExistState(), so I have no way to avoid crashing. Is there any method to avoid chaincode crashing even if reading a non-existing key?

Last error message of my chaincode container is: 2017-07-12 07:46:02.062 UTC [chaincode] afterGetState -> DEBU 482 [5e7285e7]Received GET_STATE, invoking get state from ledger 2017-07-12 07:46:02.062 UTC [chaincode] filterError -> DEBU 483 Ignoring NoTransitionError: no transition 2017-07-12 07:46:02.063 UTC [chaincode] func1 -> DEBU 484 [5e7285e7] getting state for chaincode mycc, key FIDtest0@test.com_UNO, channel mychannel 2017-07-12 07:46:02.063 UTC [stateleveldb] GetState -> DEBU 485 GetState(). ns=mycc, key=FIDtest0@test.com_UNO 2017-07-12 07:46:02.063 UTC [chaincode] func1 -> DEBU 486 [5e7285e7]No state associated with key: FIDtest0@test.com_UNO. Sending RESPONSE with an empty payload 2017-07-12 07:46:02.063 UTC [chaincode] 1 -> DEBU 487 [5e7285e7]handleGetState serial send RESPONSE 2017-07-12 07:46:02.072 UTC [chaincode] processStream -> ERRO 488 Error handling chaincode support stream: rpc error: code = Canceled desc = context canceled 2017-07-12 07:46:02.072 UTC [chaincode] deregisterHandler -> DEBU 489 Deregister handler: mycc:v0 2017-07-12 07:46:02.072 UTC [chaincode] deregisterHandler -> DEBU 48a Deregistered handler with key: mycc:v0 2017-07-12 07:46:32.054 UTC [chaincode] Execute -> DEBU 48b Exit 2017-07-12 07:46:32.054 UTC [chaincode] ExecuteChaincode -> ERRO 48c Error executing chaincode: Failed to execute transaction (Timeout expired while executing transaction) 2017-07-12 07:46:32.054 UTC [endorser] callChaincode -> DEBU 48d Exit 2017-07-12 07:46:32.054 UTC [endorser] simulateProposal -> ERRO 48e failed to invoke chaincode name:"mycc" on transaction 5e7285e78ad46427b04ead3ecb0893a33a8992a5a3ade3e833a303bca57db9ba, error: Error executing chaincode: Failed to execute transaction (Timeout expired while executing transaction) 2017-07-12 07:46:32.055 UTC [endorser] simulateProposal -> DEBU 48f Exit 2017-07-12 07:46:32.055 UTC [lockbasedtxmgr] Done -> DEBU 490 Done with transaction simulation / query execution [3fcc026c-ba2b-4b00-a97b-3a2530436711] 2017-07-12 07:46:32.055 UTC [endorser] ProcessProposal -> DEBU 491 Exit

dshuffma-ibm commented 7 years ago

@mochechan are you using the alpha version of fabric, or alpha2, or rc1? I have not noticed it crashing if a key does not exists. it simply returns null.

mochechan commented 7 years ago

I'm sure that the "problem" occurs in alpha2, rc1 and 1.0.0, but I'm not sure what is the exact reason to crash my chaincode so far. According to my observation, the previous error messages I posted appear when running the following code:

var err error
var UNO []byte

UNO, err = stub.GetState("FID" + FID + "_UNO")
if err != nil {
    return false
}

if UNO == nil {
    fmt.Println("ERROR: non-existing FID ")
    return false
}

The error message hints that "Error executing chaincode: Failed to execute transaction (Timeout expired while executing transaction)".
All of my chaincode can pass unit test by "go test". In real Fabric, stub.PutState() is no problem as well. In fact, the key "FID" + FID + "_UNO" is usually not existing in my scenario, so I guess that the stub.GetState() can pass unit test, but cannot pass real Fabric.

I traced the logs of the chaincode container and each of peer containers, but I still cannot resolve this problem. Can you give me more information to debug this problem? Thanks a lot.

dshuffma-ibm commented 7 years ago

@mochechan were you able to fix this?

dshuffma-ibm commented 7 years ago

closing, inactivity