HathorNetwork / hathor-core

Hathor core is the official and reference client for operating a full node in Hathor Network.
https://hathor.network
Apache License 2.0
83 stars 26 forks source link

Error: { success: false, message: 'Transaction has invalid data ( ..<)..', can_force: true } #245

Closed Wangmmx closed 3 years ago

Wangmmx commented 3 years ago

Hello. Excuse me again. I often get this error when I broadcast tx. How to verify the POW? How should I avoid it? I hope to send it successfully every time. At present, my transaction body data is instantaneous, timestamp and parents are also taken from the chain, I look forward to replying, thank you

msbrogli commented 3 years ago

Hi @Wangmmx . You need to solve the PoW of the transaction. I'd recommend you to use our public Tx Mining Service (testnet: https://txmining.testnet.hathor.network/, or mainnet: https://txmining.mainnet.hathor.network/).

Here is an example to calculate the minimum tx weight and send to the tx-mining-service:

from hathorlib.daa import minimum_tx_weight
tx = Transaction(...)
tx.weight = minimum_tx_weight(tx)
# Tx is ready to be mined.

# Create the job in the tx mining service.
response = requests.post(urljoin(TXMINING_BASEURL, 'submit-job'), json={
    'tx': bytes(tx).hex(),
    'propagate': False,
    'add_parents': True,
})
print()
print('tx-mining response', response.text)
job_id = response.json()['job_id']

# Wait until the job is done.
while True:
    response = requests.get(urljoin(TXMINING_BASEURL, 'job-status'), params={'job-id': job_id})
    data = response.json()
    if data['status'] not in ('pending', 'mining'):
        break
    print('Still waiting...')
    time.sleep(1)

if data['status'] != 'done':
    print('Error mining tx. Try again.')
    print('debug', data)
    os.exit(-1)

# Update tx with the mining results.
tx.nonce = int(data['tx']['nonce'], 16)
tx.parents = [bytes.fromhex(parent) for parent in data['tx']['parents']]
tx.timestamp = data['tx']['timestamp']
tx.update_hash()

# Tx is ready to be relayed to the network.
Wangmmx commented 3 years ago

Do you mean that I need to send a request to tx-mining-service before I send the transaction? Can it be avoided?

sometimes I can send it without error. I am now using nodejs to create the tx, and I have successfully calculated the weight. can I directly use push_tx to complete the request without sending request to tx-mining-service?

msbrogli commented 3 years ago

@Wangmmx You don't have to send to the tx-mining-service, but I feel it is the easiest way to mine your transaction. You can also mine locally before propagating. We have many mine tools if you'd like to use. I can help you to set up your own environment. Or you can also easily run your own tx-mining-service. We have a Docker image for it and you can start it very easily. Let me know if you need the details.

As I explained in Discord, you were using one of our full-nodes that was accepting your transaction by mistake. This full-node was running in TEST_MODE_TX_WEIGHT and it shouldn't. After we got it fixed, you should have started getting only error messages.

Wangmmx commented 3 years ago

Is mining transaction necessary? I just want to build the transaction body and broadcast it to the chain. Is there no miner to help me package the transaction? In addition, how does Kucoin do it?? Is it also necessary for them to mine transactions?

msbrogli commented 3 years ago

@Wangmmx Don't be confused with the terms. Mining a tx is very different from mining a block. The difficulty for transactions is small and you can do it in either CPU or GPU.

As transactions do not have fees, mining transactions is a form of preventing spams. If you'd like to generate a high number of transactions, you have to mine all of them.

Finally, yes, KuCoin does mine the transactions when someone withdraws HTR tokens from them. The rules are the same for all participants in the network.

I can help you set up your own tx-mining-service if you'd like. But you can use our public tx-mining-service for testing your code while yours is not ready.

Wangmmx commented 3 years ago

Okay, if this is necessary, then I will find a way to do it. It may be special, so I asked a little bit, thank you very much, let me try the demo you mentioned first, is there nodejs demo that I can refer to?

msbrogli commented 3 years ago

@Wangmmx After your transaction is prepared, you can do the following:

tx = Transaction(...)

import MineTransaction from "@hathor/wallet-lib/wallet/mineTransaction";
miner = MineTransaction(tx)
miner.on("success", (data) => {
  tx.nonce = data.nonce;
  tx.parents = data.parents;
  tx.timestamp = data.timestamp;
  console.log("Tx ready to be pushed to the network");
});
miner.submitJob()

Notice that, in this example, the parents will be returned the tx-mining-service and you don't have to worry about it.

Wangmmx commented 3 years ago

Ok, I’m trying, but my program doesn’t go inminer.on("success", (data)

Wangmmx commented 3 years ago

I used the method you mentioned to conduct mining transaction, but there is a new error

  message: 'Failed to verify if elements are equal',
  can_force: true }

I will try again, but maybe there is something wrong with my code

msbrogli commented 3 years ago

Hi @Wangmmx . Sorry for the silence. Can you send the hex of the tx here? There might be something wrong with it and I'll find it out for you.

Wangmmx commented 3 years ago

Yes, I've put the tx hex here #247 now the error is message: 'Transaction has invalid data (18332059465910239228681416254062703611103529083556222934557747009481983890405 < 108027803784545311754337236167909446549342735521936038117293293089849344)', can_force: true } at the time I send the tx , it was Failed to verify if elements are equal

panfeilei commented 3 years ago

Is it necessary to build data?

Wangmmx commented 3 years ago

Is it necessary to build data?

what data?

Wangmmx commented 3 years ago

Close the issue

panfeilei commented 3 years ago

Close the issue

Is it necessary to build data?

what data?

inputs.data

panfeilei commented 3 years ago

Can I not construct input.data?

panfeilei commented 3 years ago

@Wangmmx Don't be confused with the terms. Mining a tx is very different from mining a block. The difficulty for transactions is small and you can do it in either CPU or GPU.

As transactions do not have fees, mining transactions is a form of preventing spams. If you'd like to generate a high number of transactions, you have to mine all of them.

Finally, yes, KuCoin does mine the transactions when someone withdraws HTR tokens from them. The rules are the same for all participants in the network.

I can help you set up your own tx-mining-service if you'd like. But you can use our public tx-mining-service for testing your code while yours is not ready.

How do I run tx-minning-server? I send tx to minning-server but the status is timeout

Wangmmx commented 3 years ago

Can I not construct input.data?

You should ask the project team, you can raise an issue yourself