operate-bsv / op_agent-js

Operate JavaScript agent used to load and run Bitcoin programs.
https://www.operatebsv.org
MIT License
4 stars 3 forks source link

loadTape() throws an exception when loading my customized tape #8

Closed virtual-serenity closed 4 years ago

virtual-serenity commented 4 years ago

When I call the tape using javascript agent, I got this:

(node:3108) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'out' of undefined
    at Function.fromBPU (/Users/gulu/Documents/operate_ops/node_modules/@operate/agent/lib/operate/tape.js:41:20)
    at Agent._prepTape (/Users/gulu/Documents/operate_ops/node_modules/@operate/agent/lib/operate/agent.js:103:19)
    at Agent.loadTape (/Users/gulu/Documents/operate_ops/node_modules/@operate/agent/lib/operate/agent.js:48:23)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async foo (/Users/gulu/Documents/operate_ops/auto.js:15:15)
(node:3108) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:3108) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

The test op: https://www.operatebsv.org/library/op/?ref=5bf3bef5 The test tape txid: 441e7c82573217f92fd084c29e52870f6b92382f9cba77bda15561dbbc80179d

It works well with the example tape given on official website. I suspect I made something wrong in creating the op/tape steps. Can you help me to look into it, please?

virtual-serenity commented 4 years ago

The code I was using to load and run the tape is:

const Operate = require('@operate/agent')

const txid = '441e7c82573217f92fd084c29e52870f6b92382f9cba77bda15561dbbc80179d'

async function foo() {

    const tape = await Operate.loadTape(txid)
    const result = await Operate.runTape(tape)

    console.log("==============")
    console.log(result)
    console.log("==============")

    const data = Operate.util.mapToObject(result)
    console.log(data)
}

foo()
libitx commented 4 years ago

Thanks for reporting this. Unfortunately the transaction has not been indexed by the Planaria API which is being used to load the tx: https://bob.planaria.network/query/1GgmC7Cg782YtQ6R9QkM58voyWeQJmJJzG/ewogICJ2IjogMywKICAicSI6IHsKICAgICJmaW5kIjogewogICAgICAidHguaCI6ICI0NDFlN2M4MjU3MzIxN2Y5MmZkMDg0YzI5ZTUyODcwZjZiOTIzODJmOWNiYTc3YmRhMTU1NjFkYmJjODAxNzlkIgogICAgfSwKICAgICJsaW1pdCI6IDEwCiAgfQp9

This is a problem as the legacy Planarias have become increasingly unreliable. There's not a lot I can do other than give unwriter a nudge whenever I notice transactions not syncing... but its happening a bit too frequently now.

The Elixir version ships with a new adapter that uses the latest Bitbus/Bitsocket APIs which are much more reliable. I tested your transaction there and it works fine - so nothing wrong with how you put the tx together.

Screenshot 2020-09-07 at 12 30 32

Unfortunately the JavaScript agent is a little bit behind the Elixir version so the new adapter hasn't been ported across yet, but it will have to be done.

virtual-serenity commented 4 years ago

@libitx

Thanks for your quick replying.

I was thinking that maybe I should try to create another 'Tape' which uses hex-ed sha256-function-hash instead of utf8-encoded hash. Now I'm happy that it worked in the first place. It could still be an opportunity to emit a better-formed error message.

operate library has a neat and clean design which is terrific. I (dev of SatoPlay.com) tend to use it heavily in the near future as the on-chain game-logic solution in our future titles, and would do some Chinese introduction materials in Chinese BSV community to help others to realize we have such a powerful tool already to program on-chain in a different style (There is still a strong view that only bitcoin script which is fully backed by POW is legitimate for on-chain computing). I would do it in a public technical presentation this month (Sep. 19) which probably has a lot of Chinese BSV-devs attending.

I need to work on js-agent for a while, because pretty much lines of our existing codebase (>= 95%) are written in golang/javascript/python. I have to keep the inter-operation layer to be thin enough to lower the overall workload, and ensure that once I complete the prototyping and have some of our logic relying on operate, my teammates can put their hands on it without fearing to learn a new programming language in a hard way by twisting code in a production environment. So if js-agent can be improved to be reliable, I will definitely choose to integrate the library into the main constructs of our product to help it succeeds.

Lua is especially great for game developer like me. But python is probably also a good alternative because it has well-maintained standard library and comparably much widely covered spectrum of different domains.

Thank you very much for delivering such a great piece of design and implementation.

Gu Lu SatoPlay

libitx commented 4 years ago

@mc-gulu thanks for the kind words. That would be great to see satoplay adopting it and I fully appreciate you talking about this to a chinese audience. If there's anything I can do to support you just let me know.

Regarding creating an adapter for the new bitbus/bitsocket APIs, do you know if there is already a library that interfaces with those APIs? Preferably one that can query both APIs concurrently? If so, it should be simple to create a new adapter that uses that library. Hopefully I dont have to create that library :)

virtual-serenity commented 4 years ago

it seems the transaction syncing by Planaria you mentioned hasn't been recovered after the tape tx being mined 2 days later. In this way I'm afraid I cannot demonstrate the workflow of operate this time.

We didn't depend on unwriter's constructs (because some robustness reasons) so I don't know if there is any js-lib which can query bitbus/bitsocket APIs. But I do suggest you consider using API of (whatsonchain) or/and (metasv).

libitx commented 4 years ago

In theory an "adapter" can be created for any data source, it just needs to fetch the tx and convert it to the appropriate internal format. That format is very close to unwriters "BOB" format - which is why I use that. But could take a raw tx from whatsonchain - just involves more work to map the data.

I'll give unwriter a nudge to see if I can get the bob endpoint resynced today. But obviously this isn't a long time solution

virtual-serenity commented 4 years ago

Alright, I'll figure out what I can do this weekend.

virtual-serenity commented 4 years ago

Did you get any response from unwriter (because I still got the same error this morning)? I tried to run the elixir version but it looks harder than I thought to get it working properly.

Or, since you have a working elixir instance, I'm thinking that maybe creating a wrapping service (/load_and_run_tape) could be much simpler:

In this way we can make it run with existing working pieces and minimum additional efforts from our collaboration.

The DotCamp in next week is the only BSV dev event in rest of 2020 in China. I'll present our next bsv game alongside the near future planning (with operate in a prominent place), and I see it a great opportunity to introduce operate to other developers in China. I also see it a great monetization chance for operate, at least I'm happy to pay for using the service.

Let's make it happen.

virtual-serenity commented 4 years ago

ok. never mind.

aaronrussell commented 3 years ago

Hi @mc-gulu - please accept my apologies I didn't see your message on the 12 Sept. I don't think I have Github notifications set up very well 😔

You might be interested to know there have been some recent commits to the js agent that introduce a new Adapter that fetches tx data from Bitcoin Files API. This works very well and doesn't require an API key.

I haven't released a new version yet as I want to make some further changes to reduce the bundle size of the package (it is HUGE in browser) but if you set you project dependency to pull from GitHub you should be able to use these latest fixes.

I'm very sorry I didn't see and respond to the message above in time for the event.

virtual-serenity commented 3 years ago

alright, please never mind about it. Great to talk with you in the virtual meetup (I didn't know you are actually the developer of operate by that time)

I would use operate and advocate for it and will let you know if I have further issues :)