原始文献 / 论坛帖 / Re: JSON-RPC method idea: list transactions newer than a given txid

Re: JSON-RPC method idea: list transactions newer than a given txid

Bitcointalk · 2010-12-09 00:12:17 UTC

AuthorSatoshi Nakamoto
TitleRe: JSON-RPC method idea: list transactions newer than a given txid
Date2010-12-09 00:12:17 UTC
ForumBitcointalk · 原文

我说的不是给定 minconf 级别的正常风险,我说的是这样用 listtransactions 的额外坑。

引用自 satoshi(2010 年 12 月 8 日 10:36:45 PM)(https://bitcointalk.org/index.php?topic=2151.msg28292#msg28292):2)区块链重组时,交易被重新确认,很容易重复计数交易。
楼主举的 listtransactions <account> [count=10] [txid] 的例子似乎暗示——程序员也很容易想当然——只要把上次调用 listtransactions 返回的最后一个 txid 传进去,就永远不会重复看到同一笔交易,但事实并非如此。如果你没有自己维护持久的 map 或字典来跟踪哪些 txid 已经接受过,很容易把付款重复计数。

一个函数天生就适合某种显而易见的用法,而那种用法是个不明显的陷阱,这不对。

引用自 jgarzik(2010 年 12 月 8 日 11:07:22 PM)(https://bitcointalk.org/index.php?topic=2151.msg28301#msg28301):引用自 satoshi(2010 年 12 月 8 日 10:36:45 PM)(https://bitcointalk.org/index.php?topic=2151.msg28292#msg28292):3)一笔交易可以被一笔 txid 不同的双重支付替换。你会把两笔都数进去。
listtransactions 并没有让这个问题比 listreceivedbyaddress 本来就有的漏洞更严重。
假设两笔支付都打到同一个地址。getreceivedbyaddress 在任何时刻都只会数其中一笔,永远不会两笔都数。

用 listtransactions,很容易两笔都数进去。你看到第一笔,数了;看到第二笔,又数了。总数就重复了。

英文原文

I'm not talking about the normal risk for a given minconf level, I'm talking about additional pitfalls from listtransactions when used this way.

Quote from: satoshi on December 08, 2010, 10:36:45 PM(https://bitcointalk.org/index.php?topic=2151.msg28292#msg28292)2) When there's a block-chain reorg, it would be easy to double-count transactions when they get confirmed again.
The OP's example of listtransactions <account> [count=10] [txid] seems to imply and it would be very easy for programmers to assume that if they pass in the last txid of the previous call to listtransactions, they will never see the same transaction more than once, which is not the case.  It would be very easy to double-count payments if you don't maintain your own persistent map or dictionary to track which txid's you've already accepted.

It doesn't seem right to have a function that seems tailor made to be used a certain obvious way, and that way is a non-obvious trap.

Quote from: jgarzik on December 08, 2010, 11:07:22 PM(https://bitcointalk.org/index.php?topic=2151.msg28301#msg28301)Quote from: satoshi on December 08, 2010, 10:36:45 PM(https://bitcointalk.org/index.php?topic=2151.msg28292#msg28292)3) A transaction can be replaced by a double-spend with a different txid.  You would count both spends.
listtransactions does not add anything to this problem, beyond that which is already vulnerable through listreceivedbyaddress.
Suppose both spends are to the same address.  getreceivedbyaddress would always count only one or the other spend at any given time, never both.

Using listtransactions, it would be very easy to count both.  You see the first spend, you count it.  You see the second spend, you count it.  Total is double counted.