leapdao / leap-node

LeapDAO validation node
https://docs.leapdao.org
Mozilla Public License 2.0
15 stars 11 forks source link

Read heartbeat token color from Operator contract #413

Closed troggy closed 4 years ago

troggy commented 4 years ago

Bounty

There is a heartbeat service in leap-node. It periodically publishes a transfer tx for Heartbeat NFT token to signal liveness of the node. Heartbeat NFT is a normal ERC721 token, registered with Leap Network Plasma contract as usual. All tokens registered on Leap Network receive a color, a number by which you can address the token on plasma network.

Currently, a color for heartbean token is specified as a node option. This is redundant and error-prone as the heartbeat color is already specified in operator contract.

Scope / What's need to be done

Deliverables

Gain for the project

easier and less error-prone configuration for the node

Roles

bounty gardener: @troggy / 30 DAI bounty worker: @PumpkingWok / share bounty reviewer: name / share

Funded by

Dev Circle

PumpkingWok commented 4 years ago

Hi there, I could try to fix it during the week, if this issue is still free. It seems not so difficult. Thanks in advance.

troggy commented 4 years ago

@PumpkingWok that's great. Good luck

PumpkingWok commented 4 years ago

Hi @troggy, I'm trying to sync a node from scratch, on testnet, but it retrieves an error. I did yarn and DEBUG=tendermint,leap-node* node index.js --config=https://testnet-node.leapdao.org but at some height it retrieves Trying to spend non-existing output error. It seems that expect a different hash. Did i do something wrong ? Thanks.

Screen Shot 2020-02-08 at 3 21 04 PM
troggy commented 4 years ago

@PumpkingWok you don't need testnet for this task. Use local network pls — https://github.com/leapdao/leap-sandbox

troggy commented 4 years ago

With local network you are in control of heartbeatColor param on PoaOperator contract, it will mint a token for you etc

PumpkingWok commented 4 years ago

Hi @troggy , thanks for the advice. Just to know, leap-sandbox does not work with node 12 too, i thinks. I had to downgrade node to version 10.

troggy commented 4 years ago

yes, not working on node12 so far. I use nvm with node 10 for now.

Don't spend much time on setting up infrastructure. Start with code and unit tests (mock contract calls). It should be a single integration test — I can assist with that, once there is something to test.

troggy commented 4 years ago

Setting up local network:

  1. Checkout https://github.com/leapdao/leap-sandbox/pull/81 (it supports hearteats out of the box)
  2. yarn
  3. In build/config set leap-node path to your local folder
  4. yarn build
  5. yarn start — you should have a running network with two nodes, each pushing their own heartbeat NFTs successfully (check output/node-1.log for 32769 token transfers. 32769 is a Heartbeat Token color on local network)
troggy commented 4 years ago

Once you stuck for more then 20 minutes — ping me pls

PumpkingWok commented 4 years ago

Hi @troggy , I'm so sorry for the delay, i was very busy unfortunately, i followed your instruction above and i'm testing now. In theory there should be a getter method, created automatically, to retrieve heartbeatColor public variable from operatorContract, right ? i'm trying to access it using call and other web3 methods but nothing.thanks in advance.

troggy commented 4 years ago

In theory there should be a getter method, created automatically, to retrieve heartbeatColor public variable from operatorContract, right

heartbeatColor is a public field, so the getter is heartbeatColor() (e.g. like this)

PumpkingWok commented 4 years ago

Hi @troggy, thanks a lot for the info. I was trying via operatorContract.methods.heartBeatColor() and not directly calling operatorContract.heartbeatColor(), stupid question. I'm going to open a PR this evening.

PumpkingWok commented 4 years ago

Hi @troggy , I resolved it, i had to add heartbeatColor() getter function into operator abi (operator.js), as in leap-guardian operator ABI (the repo that you linked to me). Also i had to call it using web3.js methods before the method name.

bridgeState.operatorContract.methods .heartbeatColor() .call((error, result) => { logNode(result); });

leap-guardian uses web3.1.0.0-beta.37 version, i think that web3 introduced some changes since beta38 (ported to ES6, web3-core-method module, ecc) https://github.com/ethereum/web3.js/releases?after=v1.0.0-beta.46

I'm going to open a WIP PR tomorrow. thanks in advance.

troggy commented 4 years ago

👏

Note that we are using async/await in leap-node, so you can actually do something like this:

const heartbeatColor = await bridgeState.operatorContract.methods
.heartbeatColor().call();

Regarding leap-guardian and web3. We are not using leap-guardian in leap-node, so don't worry about that.