Update 2023/3/30
public void notify(final TransactionHashesNotification notification, final BlockNotificationContext context) { 如果 (NotificationTrigger.Execute == context.getTrigger()) { this.transactionHashCache.putAll(notification.getPairs()); } ...
protected void notifyTransactionHashes() { final List<HashMetaDataPair> 对 = BlockExtensions.streamDefault(this.block) .map(t -> new HashMetaDataPair(HashUtils.calculateHash(t), new HashMetaData(this.block.getHeight(), t.getTimeStamp()))) .collect(Collectors.toList()); this.observer.notify(new TransactionHashesNotification(pairs)); }
BatchUniqueHashTransactionValidator
检查 H(MT') 不在 HashTransactionsCache 中,因此它被添加到 UnconfirmedTransactionsCache ✅public ValidationResult validate(final List<TransactionsContextPair> groupedTransactions) { ... 最终 List<Hash> hashes = groupedTransactions.stream().flatMap(pair -> pair.getTransactions().stream()) .map(HashUtils::calculateHash).collect(Collectors.toList()); 返回 this.validate(hashes); }
pair.getTransactions()
返回仅包含外部交易的 Collection<Transaction>
。 结果,检查了 H(MT') != H(MT) 但未检查 H(X)。BlockUniqueHashTransactionValidator
和BatchUniqueHashTransactionValidator
的逻辑是一样的,所以只检查外层 MT 的 hash。 结果,交易被包含在收获的区块中 ✅公共 ValidationResult 验证(最终块 ... final List<Hash> hashes = block.getTransactions().stream().map(HashUtils::calculateHash).collect(Collectors.toList()); 返回 this.transactionHashCache.anyHashExists(hashes) ? ValidationResult.NEUTRAL : ValidationResult.SUCCESS; }
TransactionHashesObserver
尝试在进行状态更改的部分块处理期间将 H(MT') 和 H(X) 添加到 HashTransactionsCache
。 这失败了,因为 H(X) 已经存在于 UnconfirmedTransactionsCache
中,所以收获的块被拒绝 🛑UnconfirmedTransactionsCache
中过期public ValidationResult validate(final List<TransactionsContextPair> groupedTransactions) { 如果(groupedTransactions.isEmpty()){ 返回 ValidationResult.SUCCESS; } 最终 List<Hash> hashes = groupedTransactions.stream().flatMap(pair -> pair.getTransactions().stream()) .flatMap(事务 -> TransactionExtensions.streamDefault(事务)).map(HashUtils::calculateHash) .collect(Collectors.toList()); 返回 this.validate(hashes); }
公共 ValidationResult 验证(最终块块){ 如果 (block.getTransactions().isEmpty()) { 返回 ValidationResult.SUCCESS; } 最终 List<Hash> hashes = block.getTransactions().stream().flatMap(transaction -> TransactionExtensions.streamDefault(transaction)) .map(HashUtils::calculateHash).collect(收集ors.toList()); 返回 this.transactionHashCache.anyHashExists(hashes) ? ValidationResult.NEUTRAL : ValidationResult.SUCCESS; }