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

中本聪,2010 年 12 月 8 日

SN-3752 已核对来源,附原文与上下文。

阅读语言
中文译文

如此使用 listtransactions 是不安全的。

我知道我一直因为对 listtransactions 迟迟不肯松口而挨批。让我解释一下我为什么犹豫。

交易是动态的。过去的交易或许会失去确认、消失又回来、失效并彻底消失,或者被另一笔双重支出取代。它们的日期或许会变,顺序亦或许会变。

程序员自然而然地想如此用 listtransactions:从我上次询问之后,把新交易喂给我,我自己记账或保存静态记录。这在一切常规使用中似乎都没问题,然而倘若你把金额用于任何用途,它就极具被利用的空间: 1) 你怎么知道一笔过去的交易失效并消失了? 2) 发生区块链重组时,交易重新确认后很容易被重复计数。 3) 一笔交易或许被 txid 不同的双重支出取代。你会把两笔支出都算进去。

「我仅仅需要看新交易、因之前的交易我已然看过了」这个假设模型不成立。旧交易随时可能改变。

每当你基于收到的支付金额采取行动,你都务必回到比特币那里请求当前余额总额(或使用 move 或 sendfrom),并做好余额可能下降的准备。

现在我们有了账户功能,能够更容易地按正确方式做事,因而推出 listtransactions 的时机更成熟了。

ORIGINAL · 英文原文
It's not safe to use listtransactions this way.

I know I've been criticized for being reluctant about listtransactions.  Let me explain my reluctance.

Transactions are dynamic.  Past transactions can become unconfirmed, go away and come back, become invalid and disappear, or be replaced by a different double-spend.  Their date can change, their order can change.

Programmers are naturally inclined to want to use listtransactions like this: feed me the new transactions since I last asked, and I'll keep my own tally or static record of them.  This will seem to work in all regular use, but if you use the amounts for anything, it is highly exploitable:
1) How do you know if a past transaction becomes invalid and disappears?
2) When there's a block-chain reorg, it would be easy to double-count transactions when they get confirmed again.
3) A transaction can be replaced by a double-spend with a different txid.  You would count both spends.

The model where you assume you only need to see new transactions because you've already seen previous transactions is not true.  Old transactions can change at any time.

Any time you take an action based on payment amounts received, you always need to go back to bitcoin and ask for a current balance total (or use move or sendfrom), and be ready for the possibility that it can go down.

Now that we have the Accounts feature making it easier to do it the right way, we're better prepared to have listtransactions.
来源
Bitcointalk 原始链接 ↗ 记录编号 SN-3752