核验完成时已经超过23:16:54,租期已结束,这个要添加冗余时间,应为实际链上操作是需要时间的,默认冗余时间是3分钟,可以配置

This commit is contained in:
lu7213 committed 2026-10-31 20:09:36 -04:00
1 parent 1538cd0819
commit 90e74603bb
4 files changed
+19 -3

No files matched your search

@@ -13,6 +13,8 @@ rental:
queue-capacity: ${RENT_DELIVERY_QUEUE_CAPACITY:200} queue-capacity: ${RENT_DELIVERY_QUEUE_CAPACITY:200}
dispatch-interval-ms: ${RENT_DELIVERY_DISPATCH_INTERVAL_MS:3000} dispatch-interval-ms: ${RENT_DELIVERY_DISPATCH_INTERVAL_MS:3000}
push-interval-ms: ${RENT_DELIVERY_PUSH_INTERVAL_MS:2000} push-interval-ms: ${RENT_DELIVERY_PUSH_INTERVAL_MS:2000}
# 链上委托确认可能晚于业务租期;仅放宽履约核验,不延长用户实际租期。
verification-grace-seconds: ${RENT_DELIVERY_VERIFICATION_GRACE_SECONDS:180}
payment: payment:
# 新增表见sql/rent_topup_init.sql;支付库先执行sql/payment_topup_upgrade.sql。 # 新增表见sql/rent_topup_init.sql;支付库先执行sql/payment_topup_upgrade.sql。
enabled: ${RENT_PAYMENT_ENABLED:false} enabled: ${RENT_PAYMENT_ENABLED:false}
@@ -19,6 +19,15 @@ final class RentalDeliveryDiagnostics {
} }
static String explain(boolean proven, Long verified, long target, Instant expires, Instant checked) { static String explain(boolean proven, Long verified, long target, Instant expires, Instant checked) {
return explain(proven, verified, target, expires, checked, 0L);
}
/**
* 履约核验允许在业务租期结束后保留一个链上确认宽限期;宽限期只影响核验,
* 不会延长 service_expires_at,也不会延长用户实际可用租期。
*/
static String explain(boolean proven, Long verified, long target, Instant expires, Instant checked,
long verificationGraceSeconds) {
List<String> reasons = new ArrayList<>(); List<String> reasons = new ArrayList<>();
if (!proven) { if (!proven) {
reasons.add("缺少完整历史履约证明,无法确认委托区块的实际资源数量"); reasons.add("缺少完整历史履约证明,无法确认委托区块的实际资源数量");
@@ -29,7 +38,7 @@ final class RentalDeliveryDiagnostics {
} }
if (expires == null || checked == null) { if (expires == null || checked == null) {
reasons.add("缺少租期或核验时间,无法确认是否在有效租期内完成核验"); reasons.add("缺少租期或核验时间,无法确认是否在有效租期内完成核验");
} else if (!expires.isAfter(checked)) { } else if (!checked.isBefore(expires.plusSeconds(Math.max(0L, verificationGraceSeconds)))) {
reasons.add("核验完成时租期已结束:租期截止=" + expires + ",核验时间=" + checked); reasons.add("核验完成时租期已结束:租期截止=" + expires + ",核验时间=" + checked);
} }
return String.join(";", reasons); return String.join(";", reasons);
@@ -9,6 +9,8 @@ import java.util.*;
/** 查询层显式沿关联关系确定用户归属,绝不对没有user_id的表直接拼用户过滤。 */ /** 查询层显式沿关联关系确定用户归属,绝不对没有user_id的表直接拼用户过滤。 */
@Service @Service
public class RentalQueries { public class RentalQueries {
@org.springframework.beans.factory.annotation.Value("${rental.delivery.verification-grace-seconds:180}")
private long verificationGraceSeconds = 180L;
private final RentalStore store; private final RentalStore store;
public RentalQueries(RentalStore store) { public RentalQueries(RentalStore store) {
@@ -155,7 +157,7 @@ public class RentalQueries {
String reason = RentalDeliveryDiagnostics.explain(proof.path("delivery_proven").asBoolean(false), String reason = RentalDeliveryDiagnostics.explain(proof.path("delivery_proven").asBoolean(false),
verified, number(row, "target_resource_quantity"), verified, number(row, "target_resource_quantity"),
row.get("service_expires_at") == null ? null : time(row.get("service_expires_at")), row.get("service_expires_at") == null ? null : time(row.get("service_expires_at")),
checked == null ? null : time(checked)); checked == null ? null : time(checked), verificationGraceSeconds);
row.put("fulfillment_reason", reason.isEmpty() row.put("fulfillment_reason", reason.isEmpty()
? "历史核验未通过,现有归档未记录明确失败项,请核对原任务及订单事件" : reason); ? "历史核验未通过,现有归档未记录明确失败项,请核对原任务及订单事件" : reason);
return; return;
@@ -13,6 +13,8 @@ import java.util.function.Supplier;
@Service @Service
@lombok.extern.slf4j.Slf4j @lombok.extern.slf4j.Slf4j
public class RentalTasks { public class RentalTasks {
@org.springframework.beans.factory.annotation.Value("${rental.delivery.verification-grace-seconds:180}")
private long verificationGraceSeconds = 180L;
@org.springframework.beans.factory.annotation.Autowired(required = false) @org.springframework.beans.factory.annotation.Autowired(required = false)
private org.springframework.context.ApplicationEventPublisher deliveryEvents; private org.springframework.context.ApplicationEventPublisher deliveryEvents;
private final RentalStore store; private final RentalStore store;
@@ -692,7 +694,8 @@ public class RentalTasks {
Boolean.TRUE.equals(proof.get("delivery_proven")), Boolean.TRUE.equals(proof.get("delivery_proven")),
proof.get("verified_resource_quantity") == null ? null proof.get("verified_resource_quantity") == null ? null
: number(proof, "verified_resource_quantity"), : number(proof, "verified_resource_quantity"),
number(order, "target_resource_quantity"), expires, checkedAt); number(order, "target_resource_quantity"), expires, checkedAt,
verificationGraceSeconds);
String gap = RentalDeliveryDiagnostics.evidenceGap(text(proof, "delivery_evidence_gap")); String gap = RentalDeliveryDiagnostics.evidenceGap(text(proof, "delivery_evidence_gap"));
if (!gap.isEmpty() && !Boolean.TRUE.equals(proof.get("delivery_proven"))) { if (!gap.isEmpty() && !Boolean.TRUE.equals(proof.get("delivery_proven"))) {
reviewReason += ";" + gap; reviewReason += ";" + gap;