darkfi icon indicating copy to clipboard operation
darkfi copied to clipboard

Cannot broadcast Atomic swaps transactions.

Open silentnoname opened this issue 2 years ago • 23 comments

I followed the testnet instructions.

  1. A initiate the swap and get the half_swap file.
  2. B use the half_swap file to create the full_swap .
  3. A sign the full_swap and get signed_swap
  4. All the above steps are successful, A run .\drk broadcast < signed_swap then get error
Error: Failed to broadcast transaction

Caused by:
    JSON-RPC error: "Failed simulating transaction state change"
  1. I use ./drk otc inspect <full_swap, got error at the bottom
Output[0] value: 4000000000 (40)
Output[0] token ID: DARKfZX1utGbz8ZpnvtCH6i46nSDZEEGa5fMnhoubWPq
Error: Output[0] coin does not match note metadata
Error: Failed to inspect swap

Caused by:
    Inspection failed

Version : v4.0.0 rustc 1.67.0 (fc594f156 2023-01-24)

silentnoname avatar Feb 05 '23 17:02 silentnoname

Are you using different nodes/wallets to execute the steps?

aggstam avatar Feb 05 '23 22:02 aggstam

Yes. A and B are on different VPS and they are different wallet.

silentnoname avatar Feb 06 '23 05:02 silentnoname

You need to spend whole coins in swaps, so you need to have an unspent coin with the balance you want to swap. Use ./drk wallet --coin to check which coins are unspent. When executing ./drk wallet --balance, unspent coins of the same token are getting summed, for example you hold 2 coins of token DARK..... one with value of 1 and another with value of 2, you balance will show DARK..... -> 3. If you don't want to swap the whole coin, you can transfer to your self/wallet so you split up the single coin into multiple ones.

aggstam avatar Feb 06 '23 10:02 aggstam

yes, A and B used whole coins in swap. Actually if I don't use full coin. step 1, 2 below won't succeed.

  1. A initiate the swap and get the half_swap file.
  2. B use the half_swap file to create the full_swap

I use full coin to swap , but still failed to broadcask. I tried many times.

silentnoname avatar Feb 06 '23 10:02 silentnoname

Could you try ./drk scan --reset, to reset the wallet state and then repeat the steps?

aggstam avatar Feb 06 '23 10:02 aggstam

tried again. step A:

./drk wallet --coins
Fetching OwnCoins from the wallet
 Coin                                         | Spent | Token ID                                     | Value 
----------------------------------------------+-------+----------------------------------------------+-----------------
 GFrcwJneShDvxb4RGu2pkdPTt3s4E2EdXNHFmeTAXjZo | false | DARKfZX1utGbz8ZpnvtCH6i46nSDZEEGa5fMnhoubWPq | 6600000000 (66) 
 3d2hQa225Jdn44eRzPoxbwi462koKY5w5bZ7PdNCaC8R | false | BobvfQrDaf32VNhVtX6Adyi3WGfPpPYZPJBn6rnrxHKm | 4400000000 (44) 

B.

./drk wallet --coins
Fetching OwnCoins from the wallet
 Coin                                         | Spent | Token ID                                     | Value 
----------------------------------------------+-------+----------------------------------------------+--------------------
 3d1dRxD2w3hskaH6bk4vrACGdFReVzwE54vHwAu45Efo | true  | DARKfZX1utGbz8ZpnvtCH6i46nSDZEEGa5fMnhoubWPq | 4269000000 (42.69) 
 8ShyBXfuN1JNNywtyZK2acgUQGjoNP7RwStGDUa1YYWN | true  | DARKfZX1utGbz8ZpnvtCH6i46nSDZEEGa5fMnhoubWPq | 4000000000 (40) 
 Gxvz1CAU6hohtVBA9MEDNwzgDL2WH2inFvjsvo97GeKo | false | DARKfZX1utGbz8ZpnvtCH6i46nSDZEEGa5fMnhoubWPq | 3900000000 (39) 
 AiaQtRXgRT8kkD3fREAZWPmL564VdDAP4MeTz2hajHad | false | DARKfZX1utGbz8ZpnvtCH6i46nSDZEEGa5fMnhoubWPq | 100000000 (1) 
 GghzS4j9LwYdD7tDdWM6zS5Z3ZxoeLhMbnDht2eSP2F2 | false | A7f1RKsCUUHrSXA7a9ogmwg8p3bs6F47ggsW826HD4yd | 9000000000 (90) 

A:

./drk otc init -v  44:90 -t BobvfQrDaf32VNhVtX6Adyi3WGfPpPYZPJBn6rnrxHKm:A7f1RKsCUUHrSXA7a9ogmwg8p3bs6F47ggsW826HD4yd  > half_swap
Fetching OwnCoins from the wallet
Querying zkas bincode for 9EUgjxrMd7g3CTP47pj8gumaFCNsziXLFC4sKHH5WLen
Creating Mint circuit proving key
Creating Burn circuit proving key
Building first half of the swap transaction

thansfer half_swap file to B B:

./drk otc join < half_swap > full_swap
Fetching OwnCoins from the wallet
Querying zkas bincode for 9EUgjxrMd7g3CTP47pj8gumaFCNsziXLFC4sKHH5WLen
Creating Mint circuit proving key
Creating Burn circuit proving key
Building second half of the swap transaction
Signing swap transaction

transfer full_swap to A

A:

./drk otc sign < full_swap > signed_swap
Trying to decrypt note in outputs[0]
Successfully decrypted and found an ephemeral secret
Signing swap transaction
./drk broadcast < signed_swap
Reading transaction from stdin...
Broadcasting transaction...
Error: Failed to broadcast transaction

Caused by:
    JSON-RPC error: "Failed simulating transaction state change"

The final result is same error.

silentnoname avatar Feb 06 '23 15:02 silentnoname

Hey there is a fix pushed about syncing, so I would recommend to do a hard reset of the blockchain. So you have to stop your node, remove the blockchain folder(probably at ~/.config/darkfi/darkfid/blockchain), pull, recompile, let the node sync, and finally force wallet reset with ./drk scan --reset. This way all the states will be synced correctly and the performing the steps(hopefully last time) will result in success!

aggstam avatar Feb 06 '23 16:02 aggstam

removed the blockchain folder, pulled the latest commit, rebuild. I wanna resync the blockchain but got this error now.

 ./darkfid
17:29:56 [INFO] wallet::walletdb: Creating path to wallet database: /home/darkfi/.config/darkfi
17:29:56 [INFO] wallet::walletdb: Opened wallet Sqlite connection at path sqlite:///home/darkfi/.config/darkfi/darkfid_wallet_testnet.db
17:29:59 [INFO] consensus::validator: Deploying native wasm contracts
17:29:59 [INFO] consensus::validator: Deploying Money Contract with ContractID 9EUgjxrMd7g3CTP47pj8gumaFCNsziXLFC4sKHH5WLen
17:29:59 [INFO] runtime::vm_runtime: Instantiating a new runtime
17:29:59 [INFO] runtime::vm_runtime: [wasm-runtime] Running deploy
17:29:59 [INFO] consensus::validator: Successfully deployed Money Contract
17:29:59 [INFO] consensus::validator: Creating ZK verifying keys for Money Contract zkas circuits
17:29:59 [INFO] consensus::validator: Looking up zkas db for Money Contract (ContractID: 9EUgjxrMd7g3CTP47pj8gumaFCNsziXLFC4sKHH5WLen)
17:29:59 [INFO] consensus::validator: Iterating over zkas db
17:29:59 [INFO] consensus::validator: Deserializing namespace
17:29:59 [INFO] consensus::validator: Creating VerifyingKey for zkas circuit with namespace Burn_V1
17:30:02 [INFO] consensus::validator: Iterating over zkas db
17:30:02 [INFO] consensus::validator: Deserializing namespace
17:30:02 [INFO] consensus::validator: Creating VerifyingKey for zkas circuit with namespace Mint_V1
17:30:05 [INFO] consensus::validator: Iterating over zkas db
17:30:05 [INFO] consensus::validator: Deserializing namespace
17:30:05 [INFO] consensus::validator: Creating VerifyingKey for zkas circuit with namespace Lead_Burn_V1
17:30:07 [INFO] consensus::validator: Iterating over zkas db
17:30:07 [INFO] consensus::validator: Deserializing namespace
17:30:07 [INFO] consensus::validator: Creating VerifyingKey for zkas circuit with namespace Lead_Mint_V1
17:30:10 [INFO] consensus::validator: Iterating over zkas db
17:30:10 [INFO] consensus::validator: Deserializing namespace
17:30:10 [INFO] consensus::validator: Creating VerifyingKey for zkas circuit with namespace TokenMint_V1
17:30:13 [INFO] consensus::validator: Finished creating VerifyingKey objects for Money Contract (ContractID: 9EUgjxrMd7g3CTP47pj8gumaFCNsziXLFC4sKHH5WLen)
17:30:13 [INFO] consensus::validator: Deploying DAO Contract with ContractID 9qiynXwcrF5LJz3veTPmvZHmDcQRhCchVnEZSR1TJ39f
17:30:13 [INFO] runtime::vm_runtime: Instantiating a new runtime
17:30:13 [INFO] runtime::vm_runtime: [wasm-runtime] Running deploy
Error: ContractError(IoError("Unknown"))

silentnoname avatar Feb 06 '23 17:02 silentnoname

If you had removed the folder there should be an error that the contract is not there, maybe first deleted then stopped? Retry stopping then removing the folder again just for sanity sake.

aggstam avatar Feb 06 '23 17:02 aggstam

I know the problem now. the folder should be darkfid_blockchain_testnet. After remove that , my node start to sync from start. I will try atomic swap again

silentnoname avatar Feb 06 '23 18:02 silentnoname

Thank you ! This time broadcast signed_swap successfully finally. but ./drk otc inspect <full_swap this command still get this error at buttom

Error: Output[0] coin does not match note metadata
Error: Failed to inspect swap

silentnoname avatar Feb 06 '23 19:02 silentnoname

And another problem I found. ./drk wallet --coins will show dao balances as coin.

./drk wallet --coins
Fetching OwnCoins from the wallet
 Coin                                         | Spent | Token ID                                     | Value 
----------------------------------------------+-------+----------------------------------------------+--------------------
 3d1dRxD2w3hskaH6bk4vrACGdFReVzwE54vHwAu45Efo | true  | DARKfZX1utGbz8ZpnvtCH6i46nSDZEEGa5fMnhoubWPq | 4269000000 (42.69) 
 8ShyBXfuN1JNNywtyZK2acgUQGjoNP7RwStGDUa1YYWN | true  | DARKfZX1utGbz8ZpnvtCH6i46nSDZEEGa5fMnhoubWPq | 4000000000 (40) 
 Gxvz1CAU6hohtVBA9MEDNwzgDL2WH2inFvjsvo97GeKo | true  | DARKfZX1utGbz8ZpnvtCH6i46nSDZEEGa5fMnhoubWPq | 3900000000 (39) 
 AiaQtRXgRT8kkD3fREAZWPmL564VdDAP4MeTz2hajHad | false | DARKfZX1utGbz8ZpnvtCH6i46nSDZEEGa5fMnhoubWPq | 100000000 (1) 

The last one

 AiaQtRXgRT8kkD3fREAZWPmL564VdDAP4MeTz2hajHad | false | DARKfZX1utGbz8ZpnvtCH6i46nSDZEEGa5fMnhoubWPq | 100000000 (1) 

is from dao balance

./drk dao balance 1
Fetching OwnCoins from the wallet
 Token ID                                     | Balance 
----------------------------------------------+---------
 DARKfZX1utGbz8ZpnvtCH6i46nSDZEEGa5fMnhoubWPq | 1 

I cannot atomic swap this coin as well.

./drk otc init -v 1:2 -t DARKfZX1utGbz8ZpnvtCH6i46nSDZEEGa5fMnhoubWPq:BobvfQrDaf32VNhVtX6Adyi3WGfPpPYZPJBn6rnrxHKm
Fetching OwnCoins from the wallet
Error: Failed to create swap transaction half

Caused by:
    Did not find any unspent coins of value 100000000 and token_id DARKfZX1utGbz8ZpnvtCH6i46nSDZEEGa5fMnhoubWPq

I think this may make people misunderstand. should not show dao balances as coin when run ./drk wallet --coins

silentnoname avatar Feb 06 '23 19:02 silentnoname

Error: ContractError(IoError("Unknown")) is fixed now, rest stuff we'll look tomorrow and update you! Thanks again for the detailed errors.

aggstam avatar Feb 07 '23 00:02 aggstam

Update: we are fixing a lot of testnet findings and will tag a new hotfix version and reset network in couple of days. We'll update this ticket to let you know when everything is ready. Cheers!

aggstam avatar Feb 10 '23 22:02 aggstam

Network have been reset! Please stop darkfid process, pull and recompile from master, then remove your local database folder(located at ~/.config/darkfi/blockchain) and start darkfid. After syncing perform a ./drk scan --reset so your wallet is synced to chain! Let us know if any issue persists.

aggstam avatar Feb 13 '23 19:02 aggstam

I often get this in new version. is it normal? in old version ,it was smooth

Error: Failed to fetch default address, perhaps the wallet was not initialized?

Caused by:
    Network operation failed

silentnoname avatar Feb 18 '23 15:02 silentnoname

Did you remove your wallet file? If yes you have to reinit your wallet.

aggstam avatar Feb 18 '23 18:02 aggstam

No I didn't. and sometimes it can succeed. also other operation I often get Network operation failed too

silentnoname avatar Feb 18 '23 18:02 silentnoname

Are you sure this is not OS related? What system are you on?

aggstam avatar Feb 19 '23 12:02 aggstam

ubuntu 20.04 , I will try run node again or on different machine.

silentnoname avatar Feb 19 '23 13:02 silentnoname

I know the problem now. I have old unclosed darkfid process running. It cause Network operation failed happen sometimes due to database occupied.(Maybe ?)

I suggest check if there is a process already running before start the node.

silentnoname avatar Feb 19 '23 17:02 silentnoname

./drk otc inspect <full_swap this command still have error at buttom

Trying to decrypt note in output 0
Successfully decrypted and found an ephemeral secret
Output[0] value: 1337000000 (13.37)
Output[0] token ID: BobvfQrDaf32VNhVtX6Adyi3WGfPpPYZPJBn6rnrxHKm
Error: Output[0] coin does not match note metadata
Error: Failed to inspect swap

Caused by:
    Inspection failed

silentnoname avatar Feb 19 '23 17:02 silentnoname

And another problem I found. ./drk wallet --coins will show dao balances as coin.

./drk wallet --coins
Fetching OwnCoins from the wallet
 Coin                                         | Spent | Token ID                                     | Value 
----------------------------------------------+-------+----------------------------------------------+--------------------
 3d1dRxD2w3hskaH6bk4vrACGdFReVzwE54vHwAu45Efo | true  | DARKfZX1utGbz8ZpnvtCH6i46nSDZEEGa5fMnhoubWPq | 4269000000 (42.69) 
 8ShyBXfuN1JNNywtyZK2acgUQGjoNP7RwStGDUa1YYWN | true  | DARKfZX1utGbz8ZpnvtCH6i46nSDZEEGa5fMnhoubWPq | 4000000000 (40) 
 Gxvz1CAU6hohtVBA9MEDNwzgDL2WH2inFvjsvo97GeKo | true  | DARKfZX1utGbz8ZpnvtCH6i46nSDZEEGa5fMnhoubWPq | 3900000000 (39) 
 AiaQtRXgRT8kkD3fREAZWPmL564VdDAP4MeTz2hajHad | false | DARKfZX1utGbz8ZpnvtCH6i46nSDZEEGa5fMnhoubWPq | 100000000 (1) 

The last one

 AiaQtRXgRT8kkD3fREAZWPmL564VdDAP4MeTz2hajHad | false | DARKfZX1utGbz8ZpnvtCH6i46nSDZEEGa5fMnhoubWPq | 100000000 (1) 

is from dao balance

./drk dao balance 1
Fetching OwnCoins from the wallet
 Token ID                                     | Balance 
----------------------------------------------+---------
 DARKfZX1utGbz8ZpnvtCH6i46nSDZEEGa5fMnhoubWPq | 1 

I cannot atomic swap this coin as well.

./drk otc init -v 1:2 -t DARKfZX1utGbz8ZpnvtCH6i46nSDZEEGa5fMnhoubWPq:BobvfQrDaf32VNhVtX6Adyi3WGfPpPYZPJBn6rnrxHKm
Fetching OwnCoins from the wallet
Error: Failed to create swap transaction half

Caused by:
    Did not find any unspent coins of value 100000000 and token_id DARKfZX1utGbz8ZpnvtCH6i46nSDZEEGa5fMnhoubWPq

I think this may make people misunderstand. should not show dao balances as coin when run ./drk wallet --coins

and I think this issue still exist.

silentnoname avatar Feb 19 '23 18:02 silentnoname