租赁模块-地址上链下单成功,节点在线,设置也都正确,钱包资源也充足,但是节点没有接收这个类型的订单,无法上链成功。问题修复
This commit is contained in:
1 parent
3ca5ff43ea
commit
547a04d12b
3 files changed
+131
-16
No files matched your search
@@ -90,19 +90,29 @@ public class RentalTasks {
|
||||
});
|
||||
return;
|
||||
}
|
||||
List<Map<String, Object>> candidates =
|
||||
store.rows(
|
||||
"SELECT w.* FROM rent_wallet w JOIN rent_node n ON n.id=w.node_id WHERE"
|
||||
+ " w.status='ACTIVE' AND w.ownership_verified_at IS NOT NULL AND"
|
||||
+ " w.network=? AND w.snapshot_expires_at>? AND n.status='ACTIVE' AND"
|
||||
+ " n.connection_status='ONLINE' AND n.heartbeat_expires_at>? ORDER BY"
|
||||
+ " w.id LIMIT 20",
|
||||
text(initial, "network"),
|
||||
now(),
|
||||
now());
|
||||
boolean onchain = RentalOnchain.isOrder(initial);
|
||||
// 转账不使用质押资源换算,不能因资源快照缺失/过期而阻止派单。
|
||||
// 资源租赁仍严格要求新鲜快照;转账余额在候选筛选及 Agent 签名前分别核验。
|
||||
String candidateSql = "SELECT w.* FROM rent_wallet w JOIN rent_node n ON n.id=w.node_id WHERE"
|
||||
+ " w.status='ACTIVE' AND w.ownership_verified_at IS NOT NULL AND w.network=?"
|
||||
+ " AND n.status='ACTIVE' AND n.connection_status='ONLINE' AND n.heartbeat_expires_at>?"
|
||||
+ (onchain ? " AND n.transfer_enabled=1" : " AND w.snapshot_expires_at>?")
|
||||
+ " ORDER BY w.id LIMIT 20";
|
||||
List<Map<String, Object>> candidates = onchain
|
||||
? store.rows(candidateSql, text(initial, "network"), now())
|
||||
: store.rows(candidateSql, text(initial, "network"), now(), now());
|
||||
if (onchain && candidates.isEmpty()) {
|
||||
log.info("地址上链暂无可派单钱包 orderId={} network={} reason=NO_ELIGIBLE_WALLET"
|
||||
+ " 请核对钱包ACTIVE及控制权验证、节点ACTIVE/ONLINE及心跳、Agent的RENT_TRANSFER_ENABLED=true并重连",
|
||||
orderId, initial.get("network"));
|
||||
}
|
||||
for (Map<String, Object> candidate : candidates) {
|
||||
String type = text(initial, "resource_type"), owner = text(candidate, "address");
|
||||
if (owner.equals(text(initial, "receiver_address"))) {
|
||||
if (onchain) {
|
||||
log.info("地址上链跳过同地址转账 orderId={} walletId={} reason=SAME_ADDRESS",
|
||||
orderId, candidate.get("id"));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (RentalOnchain.isOrder(initial)) {
|
||||
@@ -229,7 +239,7 @@ public class RentalTasks {
|
||||
private boolean dispatchOnchain(Map<String, Object> initial, Map<String, Object> candidate) {
|
||||
Map<String, Object> advertised = store.get("node", number(candidate, "node_id"), false);
|
||||
if (number(advertised, "transfer_enabled") != 1) {
|
||||
log.debug("地址上链候选未授权转账 orderId={} nodeId={}", initial.get("id"), advertised.get("id"));
|
||||
log.info("地址上链候选未授权转账 orderId={} nodeId={}", initial.get("id"), advertised.get("id"));
|
||||
return false;
|
||||
}
|
||||
Map<String, Object> price;
|
||||
@@ -242,7 +252,9 @@ public class RentalTasks {
|
||||
long balance = chain.call(text(initial, "network"), "/wallet/getaccount",
|
||||
map("address", text(candidate, "address"), "visible", true)).path("balance").asLong();
|
||||
if (balance < Math.addExact(RentalOnchain.TRANSFER_SUN, number(price, "fee_limit_sun"))) {
|
||||
log.debug("地址上链候选余额不足 orderId={} walletId={} balanceSun={}", initial.get("id"), candidate.get("id"), balance);
|
||||
log.info("地址上链候选余额不足 orderId={} walletId={} balanceSun={} transferSun={} feeLimitSun={}",
|
||||
initial.get("id"), candidate.get("id"), balance, RentalOnchain.TRANSFER_SUN,
|
||||
price.get("fee_limit_sun"));
|
||||
return false;
|
||||
}
|
||||
return Boolean.TRUE.equals(tx(() -> {
|
||||
@@ -251,10 +263,15 @@ public class RentalTasks {
|
||||
Map<String, Object> node = store.get("node", number(wallet, "node_id"), true);
|
||||
if (!"WAITING".equals(text(order, "status")) || !time(order.get("dispatch_deadline")).isAfter(Instant.now())
|
||||
|| !"ACTIVE".equals(text(wallet, "status")) || !"ACTIVE".equals(text(node, "status"))
|
||||
|| wallet.get("ownership_verified_at") == null
|
||||
|| !text(order, "network").equals(text(wallet, "network"))
|
||||
|| number(node, "transfer_enabled") != 1 || !"ONLINE".equals(text(node, "connection_status"))
|
||||
|| node.get("heartbeat_expires_at") == null
|
||||
|| !time(node.get("heartbeat_expires_at")).isAfter(Instant.now())
|
||||
|| store.one("SELECT id FROM rent_task WHERE wallet_id=? AND resource_type='TRX' AND wallet_execution_slot=1",
|
||||
wallet.get("id")) != null) {
|
||||
log.info("地址上链候选状态变化或执行槽占用 orderId={} walletId={} nodeId={}",
|
||||
order.get("id"), wallet.get("id"), node.get("id"));
|
||||
return false;
|
||||
}
|
||||
Map<String, Object> supplier = funds.account(number(node, "user_id"), text(order, "network"));
|
||||
@@ -308,6 +325,9 @@ public class RentalTasks {
|
||||
throw new IllegalArgumentException("订单规则快照损坏");
|
||||
}
|
||||
long fee = number(product, "fee_limit_sun");
|
||||
// 转账无质押换算高度;使用0满足任务表NOT NULL契约,绝不伪造资源证明。
|
||||
long conversionBlockHeight = RentalOnchain.TASK_TYPE.equals(type)
|
||||
? 0L : number(wallet, "snapshot_block_height");
|
||||
Map<String, Object> intent =
|
||||
map(
|
||||
"protocol",
|
||||
@@ -339,7 +359,7 @@ public class RentalTasks {
|
||||
"baseline_sun",
|
||||
!"RECLAIM".equals(type) ? "0" : Long.toString(sun),
|
||||
"conversion_block_height",
|
||||
text(wallet, "snapshot_block_height"),
|
||||
Long.toString(conversionBlockHeight),
|
||||
"delegate_lock",
|
||||
false,
|
||||
"fee_limit_sun",
|
||||
@@ -378,7 +398,7 @@ public class RentalTasks {
|
||||
"conversion_total_weight",
|
||||
weight,
|
||||
"conversion_block_height",
|
||||
wallet.get("snapshot_block_height"),
|
||||
conversionBlockHeight,
|
||||
"conversion_at",
|
||||
now(),
|
||||
"estimated_resource_quantity",
|
||||
|
||||
Reference in new issue
Block a user