尽量服用,和优化采样区块,交易所在区块的资源参数 获取不需要每次获取有下单租赁订单都获取一遍,应该是全局异步获取是不是就可以,帮我设计合理方案。 和清理逻辑

This commit is contained in:
lu7213 committed 2026-10-31 19:10:27 -04:00
1 parent 13665668ac
commit 1538cd0819
24 files changed
+1894 -230

No files matched your search

@@ -118,29 +118,21 @@ public class RentalChain {
}
public Map<String, Object> snapshot(String network, String address) {
long before = block(call(network, "/wallet/getnowblock", map()));
JsonNode beforeBlock = call(network, "/wallet/getnowblock", map());
long before = block(beforeBlock);
JsonNode resources =
call(
network,
"/wallet/getaccountresource",
map("address", address, "visible", true));
long energy =
call(
network,
"/wallet/getcandelegatedmaxsize",
map("owner_address", address, "type", 1, "visible", true))
.path("max_size")
.asLong(-1);
long bandwidth =
call(
network,
"/wallet/getcandelegatedmaxsize",
map("owner_address", address, "type", 0, "visible", true))
.path("max_size")
.asLong(-1);
long after = block(call(network, "/wallet/getnowblock", map()));
long energy = delegatable(network, address, 1);
long bandwidth = delegatable(network, address, 0);
JsonNode afterBlock = call(network, "/wallet/getnowblock", map());
long after = block(afterBlock);
require(
before >= 0 && before == after && energy >= 0 && bandwidth >= 0,
before >= 0 && before == after && energy >= 0 && bandwidth >= 0
&& beforeBlock.path("blockID").asText().matches("[0-9a-fA-F]{64}")
&& beforeBlock.path("blockID").asText().equalsIgnoreCase(afterBlock.path("blockID").asText()),
"快照跨区块或本金查询不完整,请重试");
Map<String, Object> result =
map(
@@ -178,9 +170,30 @@ public class RentalChain {
&& number(result, "total_bandwidth_limit") > 0
&& number(result, "total_bandwidth_weight") > 0,
"全网参数不完整");
if (embeddedHistory && historyService != null) {
// 复用本次夹读,不再为每个订单额外请求全网资源参数;不读取旧rent_wallet快照。
try {
historyService.getObject().offerParameters(network, beforeBlock, afterBlock, resources);
} catch (RuntimeException ex) {
log.warn("钱包全局参数采样未入库 network={},独立采样器将继续重试", network);
}
}
return result;
}
/** protobuf省略零字段的空对象表示0;显式错误和非整数绝不能当作0。 */
private long delegatable(String network, String address, int type) {
JsonNode row = call(network, "/wallet/getcandelegatedmaxsize",
map("owner_address", address, "type", type, "visible", true));
require(row.isObject() && (row.size() == 0 || row.has("max_size"))
&& !row.has("Error") && !row.has("error") && !row.has("code") && !row.has("result"),
"可代理本金查询失败");
JsonNode value = row.path("max_size");
require(value.isMissingNode() || (value.isIntegralNumber() && value.canConvertToLong()
&& value.longValue() >= 0), "可代理本金响应无效");
return value.isMissingNode() ? 0 : value.longValue();
}
public long relation(String network, String owner, String receiver, String resource) {
JsonNode rows =
call(
@@ -278,6 +291,8 @@ public class RentalChain {
Map<String, Object> archived = historyService.getObject().proof(
network, txId, height, owner, receiver, text(task, "resource_type"));
if (archived == null) {
result.put("delivery_evidence_gap", historyService.getObject().missingProofCode(
network, height, owner, receiver, text(task, "resource_type")));
// 参数漏采或缺少派单前基线:保留原有MANUAL_REVIEW路径,绝不降级为当前快照。
return result;
}