View Issue Details

IDProjectCategoryView StatusLast Update
0006758Talermerchant backend API (C)public2021-02-19 17:50
Reportersebasjm Assigned ToChristian Grothoff  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product Versiongit (master) 
Fixed in Versiongit (master) 
Summary0006758: creating an instance with multiple payto uris fails
DescriptionTrying to create an instance with multiple instance fails in the merchant backend side.
Editing the instance after creating it to add more accounts works


Postgres Log

ERROR: duplicate key value violates unique constraint "merchant_accounts_merchant_serial_key"
DETAIL: Key (merchant_serial)=(2) already exists.
STATEMENT: INSERT INTO merchant_accounts(merchant_serial,h_wire,salt,payto_uri,active) SELECT merchant_serial, $2, $3, $4, $5 FROM merchant_instances WHERE merchant_id=$1

Example request:

curl 'http://localhost:9966/private/instances' \
  -H 'Authorization: Bearer secret-token:super_secret' \
  --data-raw '{"default_wire_transfer_delay":{"d_ms":2000},"default_pay_delay":{"d_ms":1000},"jurisdiction":{},"address":{},"default_wire_fee_amortization":10,"default_max_wire_fee":"COL:2","default_max_deposit_fee":"COL:1","payto_uris":["payto://x-taler-bank/bank.taler:5882/blogger3","payto://x-taler-bank/bank.taler:5882/blogger2","payto://x-taler-bank/bank.taler:5882/blogger1"],"name":"qwe","id":"qwe"}' \
  
Response:

HTTP/1.1 500 Internal Server Error
{
  "code": 54,
  "hint": "The service encountered an error event to commit the database transaction (hard, unrecoverable error).",
  "detail": null
}
TagsNo tags attached.

Activities

sebasjm

2021-02-18 14:59

developer   ~0017549

Adding here related issue, instead of creating new ticket

Creating instance with one instance works, but updating it to add 3 more doesnt work as expected. Just add one at a time.

To reproduce:
 1.- create instance with one account
 2.- query to get state, everytings ok
 3.- patch
 4.- query, two instance are missing
 5.- patch, same request than 3
 6.- query, one instance is missing

$ curl -v 'http://localhost:9966/private/instances' -H 'Authorization: Bearer secret-token:super_secret' --data-raw '{"default_wire_transfer_delay":{"d_ms":2000},"default_pay_delay":{"d_ms":1000},"jurisdiction":{},"address":{},"default_wire_fee_amortization":10,"default_max_wire_fee":"COL:2","default_max_deposit_fee":"COL:1","payto_uris":["payto://x-taler-bank/bank.taler:5882/blogger3"],"name":"qwe","id":"qwe"}' --compressed
< HTTP/1.1 204 No Content

$ curl 'http://localhost:9966/private/instances/qwe'
{
  "accounts": [
    {
      "payto_uri": "payto://x-taler-bank/bank.taler:5882/blogger3",
      "h_wire": "75Y4A3J52STN1GZ7EW075BACBS0XZBTSB4WBP6TP0RQRMNQBK13D7PBT8Z544MZBBKE3XYSDB2J9MZ3T1YBRKSF8X1TSNJ1XTQ94ZF0",
      "salt": "Z6A92K3W3C96C44MMC26D7MESG9Y9J08Z43ET8ZY03TRHAWVGD32X09PAJTX5TM8R5FCQS19V53J4WQPGYZBZ7DZRXM0HGFR26HYM3R",
      "active": true
    }
  ],
  ... everything else
}

$ curl 'http://localhost:9966/private/instances/qwe' -X 'PATCH' -H 'Authorization: Bearer secret-token:super_secret' -H 'Content-Type: application/json;charset=UTF-8' --data-raw '{"default_pay_delay":{"d_ms":1000},"name":"www","merchant_pub":"3N4SC26BXAAF4QM9VJ1T6FQK074JN0YCXQK6CJ4MYXPS4TJYN4N0","address":{},"jurisdiction":{},"default_max_wire_fee":"COL:2","default_max_deposit_fee":"COL:1","default_wire_fee_amortization":10,"default_wire_transfer_delay":{"d_ms":2000},"id":"qwe","payto_uris":["payto://x-taler-bank/bank.taler:5882/one","payto://x-taler-bank/bank.taler:5882/two","payto://x-taler-bank/bank.taler:5882/three"]}'

$ curl 'http://localhost:9966/private/instances/qwe'
{
  "accounts": [
    {
      "payto_uri": "payto://x-taler-bank/bank.taler:5882/one",
      "h_wire": "2PG2VV0KCYTYW5EGK7SWWJ9WBGZV0ZBN85E2XVZXD68DJFWAAKSXEHRK826M4QJS0H8XHTGVH1EEAMMS393T0R7Y85FZSWHKHCWWYE0",
      "salt": "PVXBBJB7VV71549Q3W7RNMJDX7E8VH86J6FB7ENHDQPMGRB8MAGYD8J3593ZYEEQ1ZPZDBD58C9AX8YEC7WJ4Y2D2YJMZGE597ERJW0",
      "active": true
    },
    {
      "payto_uri": "payto://x-taler-bank/bank.taler:5882/blogger3",
      "h_wire": "75Y4A3J52STN1GZ7EW075BACBS0XZBTSB4WBP6TP0RQRMNQBK13D7PBT8Z544MZBBKE3XYSDB2J9MZ3T1YBRKSF8X1TSNJ1XTQ94ZF0",
      "salt": "Z6A92K3W3C96C44MMC26D7MESG9Y9J08Z43ET8ZY03TRHAWVGD32X09PAJTX5TM8R5FCQS19V53J4WQPGYZBZ7DZRXM0HGFR26HYM3R",
      "active": false
    }
  ],
  ... everything else
}

$ curl 'http://localhost:9966/private/instances/qwe' -X 'PATCH' -H 'Authorization: Bearer secret-token:super_secret' -H 'Content-Type: application/json;charset=UTF-8' --data-raw '{"default_pay_delay":{"d_ms":1000},"name":"www","merchant_pub":"3N4SC26BXAAF4QM9VJ1T6FQK074JN0YCXQK6CJ4MYXPS4TJYN4N0","address":{},"jurisdiction":{},"default_max_wire_fee":"COL:2","default_max_deposit_fee":"COL:1","default_wire_fee_amortization":10,"default_wire_transfer_delay":{"d_ms":2000},"id":"qwe","payto_uris":["payto://x-taler-bank/bank.taler:5882/one","payto://x-taler-bank/bank.taler:5882/two","payto://x-taler-bank/bank.taler:5882/three"]}'

$ curl 'http://localhost:9966/private/instances/qwe'
{
  "accounts": [
    {
      "payto_uri": "payto://x-taler-bank/bank.taler:5882/two",
      "h_wire": "HC77QDJVWEVAPKNXSXN5AZT5DPMDKKEDNWSYFWN09PDC4DCH278AJHBASG5NAYWC5MBDC7Q3Q1JKRWQX6R8AGTQYBC2Y2GKWBX0MSBG",
      "salt": "1RYDTKMDQVZ7YKW0WWJP6P7B4NC0YCSME20ZAM5ZCN2MYGVN4T29P3RGT756K8YVTGA6P5N9PJVAZSSG7SZN2VFV50RZCCB363320MR",
      "active": true
    },
    {
      "payto_uri": "payto://x-taler-bank/bank.taler:5882/one",
      "h_wire": "2PG2VV0KCYTYW5EGK7SWWJ9WBGZV0ZBN85E2XVZXD68DJFWAAKSXEHRK826M4QJS0H8XHTGVH1EEAMMS393T0R7Y85FZSWHKHCWWYE0",
      "salt": "PVXBBJB7VV71549Q3W7RNMJDX7E8VH86J6FB7ENHDQPMGRB8MAGYD8J3593ZYEEQ1ZPZDBD58C9AX8YEC7WJ4Y2D2YJMZGE597ERJW0",
      "active": true
    },
    {
      "payto_uri": "payto://x-taler-bank/bank.taler:5882/blogger3",
      "h_wire": "75Y4A3J52STN1GZ7EW075BACBS0XZBTSB4WBP6TP0RQRMNQBK13D7PBT8Z544MZBBKE3XYSDB2J9MZ3T1YBRKSF8X1TSNJ1XTQ94ZF0",
      "salt": "Z6A92K3W3C96C44MMC26D7MESG9Y9J08Z43ET8ZY03TRHAWVGD32X09PAJTX5TM8R5FCQS19V53J4WQPGYZBZ7DZRXM0HGFR26HYM3R",
      "active": false
    }
  ],
  ... everything else
}

sebasjm

2021-02-18 15:04

developer   ~0017550

Trying to inactivate all the payto_uris just deactivate one of the array

$ curl 'http://localhost:9966/private/instances/qwe' -X 'PATCH' -H 'Authorization: Bearer secret-token:super_secret' -H 'Content-Type: application/json;charset=UTF-8' --data-raw '{"default_pay_delay":{"d_ms":1000},"name":"www","merchant_pub":"3N4SC26BXAAF4QM9VJ1T6FQK074JN0YCXQK6CJ4MYXPS4TJYN4N0","address":{},"jurisdiction":{},"default_max_wire_fee":"COL:2","default_max_deposit_fee":"COL:1","default_wire_fee_amortization":10,"default_wire_transfer_delay":{"d_ms":2000},"id":"qwe","payto_uris":[]}'

$ curl 'http://localhost:9966/private/instances/qwe'
{
  "accounts": [
    {
      "payto_uri": "payto://x-taler-bank/bank.taler:5882/three",
      "h_wire": "736YCS08F23VWG5526HHECF51RPV1V1BHZB4D12T1HRA039V31QNXWAQ5C1MWB2GDX8BXQ7XKNZ502JJR0MEN3CH8JNSYP5JYHXC3TG",
      "salt": "109WT8GFTE23W40Y2KX473TRH5Z6E6KW2GZY42ASS2FGCA0S9WPMTY15F8GG5QV6F77K8GFV029NMWYDB9V242XNVKDR2NDP5NJ8SRG",
      "active": false
    },
    {
      "payto_uri": "payto://x-taler-bank/bank.taler:5882/two",
      "h_wire": "HC77QDJVWEVAPKNXSXN5AZT5DPMDKKEDNWSYFWN09PDC4DCH278AJHBASG5NAYWC5MBDC7Q3Q1JKRWQX6R8AGTQYBC2Y2GKWBX0MSBG",
      "salt": "1RYDTKMDQVZ7YKW0WWJP6P7B4NC0YCSME20ZAM5ZCN2MYGVN4T29P3RGT756K8YVTGA6P5N9PJVAZSSG7SZN2VFV50RZCCB363320MR",
      "active": true
    },
    {
      "payto_uri": "payto://x-taler-bank/bank.taler:5882/one",
      "h_wire": "2PG2VV0KCYTYW5EGK7SWWJ9WBGZV0ZBN85E2XVZXD68DJFWAAKSXEHRK826M4QJS0H8XHTGVH1EEAMMS393T0R7Y85FZSWHKHCWWYE0",
      "salt": "PVXBBJB7VV71549Q3W7RNMJDX7E8VH86J6FB7ENHDQPMGRB8MAGYD8J3593ZYEEQ1ZPZDBD58C9AX8YEC7WJ4Y2D2YJMZGE597ERJW0",
      "active": true
    },
    {
      "payto_uri": "payto://x-taler-bank/bank.taler:5882/blogger3",
      "h_wire": "75Y4A3J52STN1GZ7EW075BACBS0XZBTSB4WBP6TP0RQRMNQBK13D7PBT8Z544MZBBKE3XYSDB2J9MZ3T1YBRKSF8X1TSNJ1XTQ94ZF0",
      "salt": "Z6A92K3W3C96C44MMC26D7MESG9Y9J08Z43ET8ZY03TRHAWVGD32X09PAJTX5TM8R5FCQS19V53J4WQPGYZBZ7DZRXM0HGFR26HYM3R",
      "active": false
    }
  ],
  ...everything else
}

Christian Grothoff

2021-02-18 18:59

manager   ~0017551

Can you please attach a (complete) shell script that, starting from a fresh merchant backend, reproduces the issue?

sebasjm

2021-02-18 20:40

developer   ~0017552

This scripts reproduce the first two issues with demo.taler.net
script-patch.sh (2,709 bytes)   
#/bin/bash

ID=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 16 | head -n 1)

echo create instance

curl https://backend.demo.taler.net/private/instances -H 'Authorization: ApiKey sandbox' --data-raw '{"default_wire_transfer_delay":{"d_ms":2000},"default_pay_delay":{"d_ms":1000},"jurisdiction":{},"address":{},"default_wire_fee_amortization":10,"default_max_wire_fee":"KUDOS:2","default_max_deposit_fee":"KUDOS:1","payto_uris":["payto://x-taler-bank/bank.taler:5882/blogger3"],"name":"qwe","id":"'$ID'"}'

echo add 3 accounts

curl -X PATCH https://backend.demo.taler.net/private/instances/$ID -H 'Authorization: ApiKey sandbox' --data-raw '{"default_pay_delay":{"d_ms":1000},"name":"www","merchant_pub":"3N4SC26BXAAF4QM9VJ1T6FQK074JN0YCXQK6CJ4MYXPS4TJYN4N0","address":{},"jurisdiction":{},"default_max_wire_fee":"KUDOS:2","default_max_deposit_fee":"KUDOS:1","default_wire_fee_amortization":10,"default_wire_transfer_delay":{"d_ms":2000},"id":"qwe","payto_uris":["payto://x-taler-bank/bank.taler:5882/one","payto://x-taler-bank/bank.taler:5882/two","payto://x-taler-bank/bank.taler:5882/three"]}'

echo should be 4, but is 2

curl -H "Authorization: ApiKey sandbox" https://backend.demo.taler.net/private/instances/$ID | jq '.accounts|length'

echo try again

curl -X PATCH https://backend.demo.taler.net/private/instances/$ID -H 'Authorization: ApiKey sandbox' --data-raw '{"default_pay_delay":{"d_ms":1000},"name":"www","merchant_pub":"3N4SC26BXAAF4QM9VJ1T6FQK074JN0YCXQK6CJ4MYXPS4TJYN4N0","address":{},"jurisdiction":{},"default_max_wire_fee":"KUDOS:2","default_max_deposit_fee":"KUDOS:1","default_wire_fee_amortization":10,"default_wire_transfer_delay":{"d_ms":2000},"id":"qwe","payto_uris":["payto://x-taler-bank/bank.taler:5882/one","payto://x-taler-bank/bank.taler:5882/two","payto://x-taler-bank/bank.taler:5882/three"]}'

echo should be 4, but is 3

curl -H "Authorization: ApiKey sandbox" https://backend.demo.taler.net/private/instances/$ID | jq '.accounts|length'

echo one more time

curl -X PATCH https://backend.demo.taler.net/private/instances/$ID -H 'Authorization: ApiKey sandbox' --data-raw '{"default_pay_delay":{"d_ms":1000},"name":"www","merchant_pub":"3N4SC26BXAAF4QM9VJ1T6FQK074JN0YCXQK6CJ4MYXPS4TJYN4N0","address":{},"jurisdiction":{},"default_max_wire_fee":"KUDOS:2","default_max_deposit_fee":"KUDOS:1","default_wire_fee_amortization":10,"default_wire_transfer_delay":{"d_ms":2000},"id":"qwe","payto_uris":["payto://x-taler-bank/bank.taler:5882/one","payto://x-taler-bank/bank.taler:5882/two","payto://x-taler-bank/bank.taler:5882/three"]}'

echo should be 4

curl -H "Authorization: ApiKey sandbox" https://backend.demo.taler.net/private/instances/$ID | jq '.accounts|length'

script-patch.sh (2,709 bytes)   
script-database.sh (543 bytes)   
#/bin/bash
set -x

ID=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 16 | head -n 1)

curl https://backend.demo.taler.net/private/instances -H 'Authorization: ApiKey sandbox' --data-raw '{"default_wire_transfer_delay":{"d_ms":2000},"default_pay_delay":{"d_ms":1000},"jurisdiction":{},"address":{},"default_wire_fee_amortization":10,"default_max_wire_fee":"KUDOS:2","default_max_deposit_fee":"KUDOS:1","payto_uris":["payto://x-taler-bank/bank.taler:5882/blogger3","payto://x-taler-bank/bank.taler:5882/blogger2"],"name":"qwe","id":"'$ID'"}'
script-database.sh (543 bytes)   

Christian Grothoff

2021-02-19 00:22

manager   ~0017553

c3b8735..a1265a0 fixes the issue discovered by script-database: it removes a bogus UNIQUE constraint.

Christian Grothoff

2021-02-19 00:25

manager   ~0017554

Looks like the script-patch.sh is also fixed by the same patch.

sebasjm

2021-02-19 17:48

developer   ~0017555

confirmed, the three issues were fixed

sebasjm

2021-02-19 17:50

developer   ~0017556

tested on a1265a05

Issue History

Date Modified Username Field Change
2021-02-18 14:49 sebasjm New Issue
2021-02-18 14:49 sebasjm Status new => assigned
2021-02-18 14:49 sebasjm Assigned To => Christian Grothoff
2021-02-18 14:59 sebasjm Note Added: 0017549
2021-02-18 15:04 sebasjm Note Added: 0017550
2021-02-18 18:59 Christian Grothoff Note Added: 0017551
2021-02-18 20:40 sebasjm Note Added: 0017552
2021-02-18 20:40 sebasjm File Added: script-patch.sh
2021-02-18 20:40 sebasjm File Added: script-database.sh
2021-02-19 00:22 Christian Grothoff Note Added: 0017553
2021-02-19 00:25 Christian Grothoff Note Added: 0017554
2021-02-19 17:48 sebasjm Note Added: 0017555
2021-02-19 17:50 sebasjm Status assigned => resolved
2021-02-19 17:50 sebasjm Resolution open => fixed
2021-02-19 17:50 sebasjm Fixed in Version => git (master)
2021-02-19 17:50 sebasjm Note Added: 0017556