Struggling with ExecuteScriptAtBlockHeight

Hey everyone!

I have been enjoying learning about Flow and all of the intricacies in accessing data on the blockchain.

So far I have been successfully able to execute scripts on the recent block and on specific block IDs. I have not been able to successfully execute it when attempting to execute the script across a range of block heights.

The error I am getting is:

%GRPC.RPCError{message: "3 errors occurred:%0A%09* rpc error: code = Internal desc = failed to execute the script on the execution node execution-0ca407c1da940952ebcc02283b60cd97c9a008e111a48ea6cf1ce8f36f1e0153@execution-004.mainnet5.nodes.onflow.org:3569=1000: rpc error: code = Internal desc = failed to execute script: failed to execute script (internal error): ledger returns unsuccessful: error getting register (account_address_state) value at 96801fb014ff11a1274d4d317c4d11f1b62014553dc29d26134e9dfe97e10527: trie with the given rootHash [96801fb014ff11a1274d4d317c4d11f1b62014553dc29d26134e9dfe97e10527] not found%0A%09* rpc error: code = Internal desc = failed to execute the script on the execution node execution-4ab025ab974e7ad7f344fbd16e5fbcb17fb8769fc8849b9d241ae518787695bd@execution-003.mainnet5.nodes.onflow.org:3569=1000: rpc error: code = Internal desc = failed to execute script: failed to execute script (internal error): ledger returns unsuccessful: error getting register (account_address_state) value at 96801fb014ff11a1274d4d317c4d11f1b62014553dc29d26134e9dfe97e10527: trie with the given rootHash [96801fb014ff11a1274d4d317c4d11f1b62014553dc29d26134e9dfe97e10527] not found%0A%09* rpc error: code = Internal desc = failed to execute the script on the execution node execution-9686399a8a5418a12e762cfaeff2ea348c2137f554560917760e0d47acf2cda4@execution-001.mainnet5.nodes.onflow.org:3569=1000: rpc error: code = Internal desc = failed to execute script: failed to execute script (internal error): ledger returns unsuccessful: error getting register (account_address_state) value at 96801fb014ff11a1274d4d317c4d11f1b62014553dc29d26134e9dfe97e10527: trie with the given rootHash [96801fb014ff11a1274d4d317c4d11f1b62014553dc29d26134e9dfe97e10527] not found%0A%0A", status: 2}

I am using Elixir and generated the gRPC client using the flow protobuf files.

Any advice on getting past this would be helpful.

For reference, the script I am trying to use is passing an Address as an argument and I think that is where this is failing. From what I can see, I have been able to GetAccountAtLatestBlock just fine with an sending bytes from the gRPC generated client to the blockchain. Trying to send the address to a script has been giving me headaches however.

Thanks!

Hey @phereford!

Out of curiosity, is this error happening every time? The error message actually looks more like a bug in the node rather than your code.

Can you let me know how easy it is to reproduce?

BTW, cool to hear that you’re using Elixir!

Hi,

I’m experiencing the same issue here.
I was wondering if you were able to recover from it?

Thanks!

Hey @pete !

So, the error message happens when I am trying to pass in an address to the script.

From the protobuf source, I was able to generate the following client: GitHub - phereford/flow

Here is a gist of the code I have been toying with to get it working:

What works in the gist:

  • Getting latest block
  • Getting events for a specific height range
  • Getting an Account at the Latest block

What doesnt work:

  • ExecuteScriptAtLatestBlockRequest
  • ExecuteScriptAtBlockHeightRequest
  • Getting an account at a specific block height

In the gist I have put the error messages that I have been receiving. the ** MatchError is an elixir error stating that my tuple doesnt match as it is expecting {:ok, Struct} and instead getting {:error, GRPC.Error}.

Any advice here would be super helpful!

Last note: I have been able to execute a script against a block height that takes no arguments. As soon as I add arguments to the function, it fails.

Hey @bigoper ,

I havent quite gotten past it yet. My hunch as to what is happening is that the script is expecting something in a specific type but the generated gRPC client only allows us to send :binary as arguments. Whats tricky is I have converted the address from a string to bytes and that doesnt work quite as expected.

Hey @bigoper

I get a similar issue using python’s grpc_tools.protoc on the proto files. I can run Ping, GetLatestBlockHeader, and GetEventsForHeightRange without an issue.

When I run ExecuteScriptAtBlockHeight I get a very similar error:

block_height = int(12408061)
script = """
pub fun main(): String {
  return "Hello World"
}
"""

req = ExecuteScriptAtBlockHeightRequest()
req.block_height = block_height
req.script = str.encode(script)
resp = stub.ExecuteScriptAtBlockHeight(req)

Error:

grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
	status = StatusCode.UNKNOWN
	details = "3 errors occurred:
	* rpc error: code = Internal desc = failed to execute the script on the execution node execution-160241f88cbfaa0f361cf64adb0a1c9fc19dec1daf4b96550cd67b7a9fb26cd9@execution-002.mainnet5.nodes.onflow.org:3569=1000: rpc error: code = Internal desc = failed to execute script: failed to execute script (internal error): ledger returns unsuccessful: error getting register (account_address_state) value at 48af0cb285c1b2a2761f05fac4c113d75a3aff0a26425ba97415d2f78f8a4b9b: trie with the given rootHash [48af0cb285c1b2a2761f05fac4c113d75a3aff0a26425ba97415d2f78f8a4b9b] not found
	* rpc error: code = Internal desc = failed to execute the script on the execution node execution-0ca407c1da940952ebcc02283b60cd97c9a008e111a48ea6cf1ce8f36f1e0153@execution-004.mainnet5.nodes.onflow.org:3569=1000: rpc error: code = Internal desc = failed to execute script: failed to execute script (internal error): ledger returns unsuccessful: error getting register (account_address_state) value at 48af0cb285c1b2a2761f05fac4c113d75a3aff0a26425ba97415d2f78f8a4b9b: trie with the given rootHash [48af0cb285c1b2a2761f05fac4c113d75a3aff0a26425ba97415d2f78f8a4b9b] not found
	* rpc error: code = Internal desc = failed to execute the script on the execution node execution-9686399a8a5418a12e762cfaeff2ea348c2137f554560917760e0d47acf2cda4@execution-001.mainnet5.nodes.onflow.org:3569=1000: rpc error: code = Internal desc = failed to execute script: failed to execute script (internal error): ledger returns unsuccessful: error getting register (account_address_state) value at 48af0cb285c1b2a2761f05fac4c113d75a3aff0a26425ba97415d2f78f8a4b9b: trie with the given rootHash [48af0cb285c1b2a2761f05fac4c113d75a3aff0a26425ba97415d2f78f8a4b9b] not found

"
	debug_error_string = "{"created":"@1614739406.441909678","description":"Error received from peer ipv4:35.226.224.190:9000","file":"src/core/lib/surface/call.cc","file_line":1067,"grpc_message":"3 errors occurred:\n\t* rpc error: code = Internal desc = failed to execute the script on the execution node execution-160241f88cbfaa0f361cf64adb0a1c9fc19dec1daf4b96550cd67b7a9fb26cd9@execution-002.mainnet5.nodes.onflow.org:3569=1000: rpc error: code = Internal desc = failed to execute script: failed to execute script (internal error): ledger returns unsuccessful: error getting register (account_address_state) value at 48af0cb285c1b2a2761f05fac4c113d75a3aff0a26425ba97415d2f78f8a4b9b: trie with the given rootHash [48af0cb285c1b2a2761f05fac4c113d75a3aff0a26425ba97415d2f78f8a4b9b] not found\n\t* rpc error: code = Internal desc = failed to execute the script on the execution node execution-0ca407c1da940952ebcc02283b60cd97c9a008e111a48ea6cf1ce8f36f1e0153@execution-004.mainnet5.nodes.onflow.org:3569=1000: rpc error: code = Internal desc = failed to execute script: failed to execute script (internal error): ledger returns unsuccessful: error getting register (account_address_state) value at 48af0cb285c1b2a2761f05fac4c113d75a3aff0a26425ba97415d2f78f8a4b9b: trie with the given rootHash [48af0cb285c1b2a2761f05fac4c113d75a3aff0a26425ba97415d2f78f8a4b9b] not found\n\t* rpc error: code = Internal desc = failed to execute the script on the execution node execution-9686399a8a5418a12e762cfaeff2ea348c2137f554560917760e0d47acf2cda4@execution-001.mainnet5.nodes.onflow.org:3569=1000: rpc error: code = Internal desc = failed to execute script: failed to execute script (internal error): ledger returns unsuccessful: error getting register (account_address_state) value at 48af0cb285c1b2a2761f05fac4c113d75a3aff0a26425ba97415d2f78f8a4b9b: trie with the given rootHash [48af0cb285c1b2a2761f05fac4c113d75a3aff0a26425ba97415d2f78f8a4b9b] not found\n\n","grpc_status":2}"
>

This works fine but doesn’t happen over gRPC.

HelloWorld.cdc

pub fun main(): String {
  return "Hello World"
}

shell:

$ flow scripts execute HelloWorld.cdc --host access.mainnet.nodes.onflow.org:9000
{"type":"String","value":"Hello World"}

@weaver1045

I was able to resolve it (using some help)
https://github.com/rrrkren/topshot-sales/pull/4

Due to the increasing amount of transactions, the current “window” (block height) is not valid anymore.
You must use a “smaller sized window” (500 -> 100), which will be valid (exists).

I hope this helps.

P.S
Can you share a link to your implementation on Git?

@weaver1045 I was able to do the same as above to get some successful queries working. I was still unable to execute scripts that took arguments though.

@bigoper I was able to get the Go code to work using a 100 window.

@phereford I have the same problem now on the python side. I can get ExecuteScriptAtBlockHeight to work if I don’t pass any arguments. Getting “error: invalid argument at index 0” back from all 3 execution nodes if I try to send arguments.

Code:

from flow.access.access_pb2 import *
from flow.access.access_pb2_grpc import *
from flow.execution.execution_pb2_grpc import *


channel = grpc.insecure_channel('access.mainnet.nodes.onflow.org:9000')
stub = AccessAPIStub(channel)

r = GetLatestBlockRequest()
response = stub.GetLatestBlock(r)

block_height = response.block.height

script = b"""

pub fun main(m:String): String {
  return m
}

"""

position0 = b"Hello Flow"

req = ExecuteScriptAtBlockHeightRequest()
req.block_height = block_height
req.script = script

req.arguments.extend([position0])
resp = stub.ExecuteScriptAtBlockHeight(req)
print(resp)

Error:

3 errors occurred:
	* rpc error: code = Internal desc = failed to execute the script on the execution node execution-0ca407c1da940952ebcc02283b60cd97c9a008e111a48ea6cf1ce8f36f1e0153@execution-004.mainnet5.nodes.onflow.org:3569=1000: rpc error: code = Internal desc = failed to execute script: failed to execute script at block (138173ab551153d7c2358741dd8154a557c911c2e0878687c9d409643a9861f0): Execution failed:
error: invalid argument at index 0
--> 55733026e070dd4719e8fbc17976cdbef1f3543cc66b99b33a7a6d0ecdf5adf2

	* rpc error: code = Internal desc = failed to execute the script on the execution node execution-160241f88cbfaa0f361cf64adb0a1c9fc19dec1daf4b96550cd67b7a9fb26cd9@execution-002.mainnet5.nodes.onflow.org:3569=1000: rpc error: code = Internal desc = failed to execute script: failed to execute script at block (138173ab551153d7c2358741dd8154a557c911c2e0878687c9d409643a9861f0): Execution failed:
error: invalid argument at index 0
--> 55733026e070dd4719e8fbc17976cdbef1f3543cc66b99b33a7a6d0ecdf5adf2

	* rpc error: code = Internal desc = failed to execute the script on the execution node execution-4ab025ab974e7ad7f344fbd16e5fbcb17fb8769fc8849b9d241ae518787695bd@execution-003.mainnet5.nodes.onflow.org:3569=1000: rpc error: code = Internal desc = failed to execute script: failed to execute script at block (138173ab551153d7c2358741dd8154a557c911c2e0878687c9d409643a9861f0): Execution failed:
error: invalid argument at index 0
--> 55733026e070dd4719e8fbc17976cdbef1f3543cc66b99b33a7a6d0ecdf5adf2


"
	debug_error_string = "{"created":"@1614804245.123604012","description":"Error received from peer ipv4:35.226.224.190:9000","file":"src/core/lib/surface/call.cc","file_line":1067,"grpc_message":"3 errors occurred:\n\t* rpc error: code = Internal desc = failed to execute the script on the execution node execution-0ca407c1da940952ebcc02283b60cd97c9a008e111a48ea6cf1ce8f36f1e0153@execution-004.mainnet5.nodes.onflow.org:3569=1000: rpc error: code = Internal desc = failed to execute script: failed to execute script at block (138173ab551153d7c2358741dd8154a557c911c2e0878687c9d409643a9861f0): Execution failed:\nerror: invalid argument at index 0\n--> 55733026e070dd4719e8fbc17976cdbef1f3543cc66b99b33a7a6d0ecdf5adf2\n\n\t* rpc error: code = Internal desc = failed to execute the script on the execution node execution-160241f88cbfaa0f361cf64adb0a1c9fc19dec1daf4b96550cd67b7a9fb26cd9@execution-002.mainnet5.nodes.onflow.org:3569=1000: rpc error: code = Internal desc = failed to execute script: failed to execute script at block (138173ab551153d7c2358741dd8154a557c911c2e0878687c9d409643a9861f0): Execution failed:\nerror: invalid argument at index 0\n--> 55733026e070dd4719e8fbc17976cdbef1f3543cc66b99b33a7a6d0ecdf5adf2\n\n\t* rpc error: code = Internal desc = failed to execute the script on the execution node execution-4ab025ab974e7ad7f344fbd16e5fbcb17fb8769fc8849b9d241ae518787695bd@execution-003.mainnet5.nodes.onflow.org:3569=1000: rpc error: code = Internal desc = failed to execute script: failed to execute script at block (138173ab551153d7c2358741dd8154a557c911c2e0878687c9d409643a9861f0): Execution failed:\nerror: invalid argument at index 0\n--> 55733026e070dd4719e8fbc17976cdbef1f3543cc66b99b33a7a6d0ecdf5adf2\n\n\n","grpc_status":2}

Script arguments are formatted as JSON-CDC values. You can see the spec here: JSON-Cadence Data Interchange Format - Flow Documentation

@phereford In your case you’ll want to change the address to this:

address = "{ \"type\": \"Address\", \"value\": \"0x7b0aac240b2bacda\" }"

@weaver1045 Same goes for Python. We might have some code that helps with this, though – I’ll check!

@weaver1045

1 Like

@pete Thank you so much!!! Verified this works.

I knew I was missing something.