walletnotify not triggered during issuing asset

+3 votes

Dear MC team,

I have the following issue with MC 2.02.
> The following address are in my node wallet:

1Q3SPtj1dfWMTjXkHU3Z3tXq53uRvMUXXh
3PyGbXQ86Jy9C7aujQ2Z9gtmxsnE1XFw4n

> I can doublecheck this:

listaddresses 3PyGbXQ86Jy9C7aujQ2Z9gtmxsnE1XFw4n true
[
    {
        "address" : "3PyGbXQ86Jy9C7aujQ2Z9gtmxsnE1XFw4n",
        "ismine" : false,
        "iswatchonly" : true,
        "isscript" : true,
        "script" : "nonstandard",
        "hex" : "",
        "addresses" : [
        ],
        "account" : "",
        "synchronized" : true
    }
]

listaddresses 1Q3SPtj1dfWMTjXkHU3Z3tXq53uRvMUXXh true
[
    {
        "address" : "1Q3SPtj1dfWMTjXkHU3Z3tXq53uRvMUXXh",
        "ismine" : false,
        "iswatchonly" : true,
        "isscript" : false,
        "account" : "rescan",
        "synchronized" : true
    }
]

> I enable walletnotify my adding the following row in multichain.conf
rpcuser=multichainrpc
rpcpassword=3NLjSZUTvXmQAwLfRiYHCEXGQDNwovBwG6hXAdVq1HDn
walletnotify=/home/fabio/.multichain/testnet04/notary.sh %s %c %n

where:
fabio@ubuntu:~/.multichain/testnet04$ cat notary.sh
#!/bin/sh
echo "["$(date -u)"]" $1 $2 $3>> notary.log


> I set a transaction in order to issue <asset_5> from 1Q3SPtj1dfWMTjXkHU3Z3tXq53uRvMUXXh to 3PyGbXQ86Jy9C7aujQ2Z9gtmxsnE1XFw4n 

> the transaction is mined and confirmed, in fact the balance is the following:
getaddressbalances 3PyGbXQ86Jy9C7aujQ2Z9gtmxsnE1XFw4n
{
        "name" : "asset_5",
        "assetref" : "764-300-40077",
        "qty" : 1
    }

> I can check the wallet transaction
 getaddresstransaction 3PyGbXQ86Jy9C7aujQ2Z9gtmxsnE1XFw4n 8d9c39b2d6435c45983b81d20dd9dd2b2727067d07ff44b5f7a5786df1b7037b

{
    "balance" : {
        "amount" : 0,
        "assets" : [
            {
                "name" : "asset_5",
                "assetref" : "764-300-40077",
                "qty" : 1
            }
        ]
    },
    "myaddresses" : [
        "3PyGbXQ86Jy9C7aujQ2Z9gtmxsnE1XFw4n"
    ],
    "addresses" : [
        "1Q3SPtj1dfWMTjXkHU3Z3tXq53uRvMUXXh"
    ],
    "permissions" : [
    ],
    "issue" : {
        "name" : "asset_5",
        "assetref" : "764-300-40077",
        "multiple" : 1,
        "units" : 1,
        "open" : false,
        "restrict" : {
            "send" : false,
            "receive" : false
        },
        "details" : {
            "origin" : "ApuanaSB"
        },
        "qty" : 1,
        "raw" : 1,
        "addresses" : [
            "3PyGbXQ86Jy9C7aujQ2Z9gtmxsnE1XFw4n"
        ]
    },
    "items" : [
    ],
    "data" : [
    ],
    "confirmations" : 21,
    "blockhash" : "001a70696c86c5d5c37cc14096630447abcac616d5536d0462c81b26324854ab",
    "blockindex" : 1,
    "blocktime" : 1592347424,
    "txid" : "8d9c39b2d6435c45983b81d20dd9dd2b2727067d07ff44b5f7a5786df1b7037b",
    "valid" : true,
    "time" : 1592347413,
    "timereceived" : 1592347413
}


> the problem is that walletnotify was not triggered. It happened other times, usually the event is triggered but sometimes I miss it. In the past I did a stop/start daemon but I need to understand if it is and issue because in my application I need to catch this event in order to trigger external actions.

Thanks for your support.

[June 18th follow-up]

Today I stopped the MC server and start again and I run exactly the same procedure as described above. The event is triggered. So I assume the step above are correct and the bug is related to something different. I really hope you can help me.

Thanks,

  Fabio

 

asked Jun 16, 2020 by Fabio
edited Jun 17, 2020

1 Answer

0 votes

We reviewed the code and can't see any case where the transaction is added to the wallet (and therefore retrievable by an API like getwallettransaction) but the walletnotify script is not triggered. If you see this again, I would like to recommend first checking the problem is not in the script. You can do this with some very simple script that just writes the txid to some file (using an flock()-style mutex of course).

answered Jun 18, 2020 by MultiChain
I doublechecked according to your hint.
The problem was in the script because writing to a file was not protected with a mutex.
I changed the script using mysql db with the following one. It checks %c parameter and store txid only when confirmed:
#!/bin/sh
if [ "$2" = "1" ]
  then
        DATA_TX=$(date +"%D %T")
        mysql --login-path=local  -e "USE my_db; INSERT INTO tx_list values (NULL,'$1','$DATA_TX');"
fi

Thanks for you support.
...