添加快照日志
This commit is contained in:
1 parent
547a04d12b
commit
b84675df3c
4 files changed
+133
-63
No files matched your search
@@ -107,6 +107,10 @@ rental:
|
|||||||
|
|
||||||
### 节点在线但未收到地址上链订单
|
### 节点在线但未收到地址上链订单
|
||||||
|
|
||||||
|
快照更新时间长期不变时,先检查启动日志“租赁快照定时扫描已启用”。扫描每轮结束后延迟15秒再次运行,每批最多20个ACTIVE且快照缺失/过期的钱包;游标走到末尾后下一轮从头开始,因此不是每个钱包严格每15秒更新。刷新成功输出INFO(walletId、网络、旧快照时间、耗时),失败输出WARN及安全异常因果链;批次汇总输出成功/失败数量。无候选和区块夹读明细为DEBUG。失败不会推进snapshot_at或有效期。
|
||||||
|
|
||||||
|
链上采集失败日志stage含义:BEFORE_BLOCK/AFTER_BLOCK为区块RPC,ACCOUNT_RESOURCE为资源RPC,ENERGY_DELEGATABLE/BANDWIDTH_DELEGATABLE为对应可委托本金RPC,BLOCK_CONSISTENCY为前后区块一致性检查,GLOBAL_PARAMETERS为全网参数检查。BLOCK_CHANGED_OR_INVALID显示前后高度;STALE_OR_CONCURRENT显示钱包版本、新旧高度及快照屏障。RPC另记录路径和非成功HTTP状态码,不记录认证头或响应原文。请按walletId、网络、地址和相邻时间关联日志。
|
||||||
|
|
||||||
地址上链不依赖能量/带宽出租开关、可委托质押本金、历史资源证明或资源快照有效期。供应钱包必须在订单对应网络、状态为ACTIVE且已完成控制权验证;节点必须ACTIVE、ONLINE、心跳未过期,并由Agent在连接恢复同步时上报转账授权。仅打开能量/带宽出租并不会授予转账权限。
|
地址上链不依赖能量/带宽出租开关、可委托质押本金、历史资源证明或资源快照有效期。供应钱包必须在订单对应网络、状态为ACTIVE且已完成控制权验证;节点必须ACTIVE、ONLINE、心跳未过期,并由Agent在连接恢复同步时上报转账授权。仅打开能量/带宽出租并不会授予转账权限。
|
||||||
|
|
||||||
Agent配置 `RENT_TRANSFER_ENABLED=true` 后需重启或重连;数据库中的 `rent_node.transfer_enabled` 应由Agent同步上报,不应手工改成1绕过本地授权。Java Agent还需要打开总广播授权。云端实时查询余额至少覆盖固定1TRX与订单快照中的fee-limit-sun,Agent执行前还会检查实际创建费、带宽费用及本地留存。
|
Agent配置 `RENT_TRANSFER_ENABLED=true` 后需重启或重连;数据库中的 `rent_node.transfer_enabled` 应由Agent同步上报,不应手工改成1绕过本地授权。Java Agent还需要打开总广播授权。云端实时查询余额至少覆盖固定1TRX与订单快照中的fee-limit-sun,Agent执行前还会检查实际创建费、带宽费用及本地留存。
|
||||||
|
|||||||
@@ -80,14 +80,18 @@ public class RentalChain {
|
|||||||
json.writeValueAsString(body)))
|
json.writeValueAsString(body)))
|
||||||
.build();
|
.build();
|
||||||
try (Response response = client.newCall(request).execute()) {
|
try (Response response = client.newCall(request).execute()) {
|
||||||
|
if (!response.isSuccessful()) {
|
||||||
|
// 不记录完整URL、认证头或响应原文;状态码足以区分限流、路径错误和服务故障。
|
||||||
|
log.warn("租赁RPC返回非成功状态 path={} httpStatus={}", path, response.code());
|
||||||
|
}
|
||||||
boolean fullBlock = path.endsWith("/getnowblock") || path.endsWith("/getblockbynum")
|
boolean fullBlock = path.endsWith("/getnowblock") || path.endsWith("/getblockbynum")
|
||||||
|| path.endsWith("/gettransactioninfobyblocknum");
|
|| path.endsWith("/gettransactioninfobyblocknum");
|
||||||
return json.readTree(RentalHttp.body(response,
|
return json.readTree(RentalHttp.body(response,
|
||||||
(fullBlock ? 16 : 1) * 1024 * 1024));
|
(fullBlock ? 16 : 1) * 1024 * 1024));
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
log.error(ex.getMessage(), ex);
|
log.error("租赁RPC查询失败 path={} diagnostic={}", path, RentalDiagnostics.describe(ex));
|
||||||
throw new IllegalStateException("链上查询失败,保留原业务状态 " + base + path);
|
throw new IllegalStateException("链上查询失败,保留原业务状态", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,67 +122,100 @@ public class RentalChain {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, Object> snapshot(String network, String address) {
|
public Map<String, Object> snapshot(String network, String address) {
|
||||||
JsonNode beforeBlock = call(network, "/wallet/getnowblock", map());
|
long started = System.nanoTime();
|
||||||
long before = block(beforeBlock);
|
String stage = "BEFORE_BLOCK";
|
||||||
JsonNode resources =
|
try {
|
||||||
call(
|
JsonNode beforeBlock = call(network, "/wallet/getnowblock", map());
|
||||||
network,
|
long before = block(beforeBlock);
|
||||||
"/wallet/getaccountresource",
|
stage = "ACCOUNT_RESOURCE";
|
||||||
map("address", address, "visible", true));
|
JsonNode resources =
|
||||||
long energy = delegatable(network, address, 1);
|
call(
|
||||||
long bandwidth = delegatable(network, address, 0);
|
network,
|
||||||
JsonNode afterBlock = call(network, "/wallet/getnowblock", map());
|
"/wallet/getaccountresource",
|
||||||
long after = block(afterBlock);
|
map("address", address, "visible", true));
|
||||||
require(
|
stage = "ENERGY_DELEGATABLE";
|
||||||
before >= 0 && before == after && energy >= 0 && bandwidth >= 0
|
long energy = delegatable(network, address, 1);
|
||||||
&& beforeBlock.path("blockID").asText().matches("[0-9a-fA-F]{64}")
|
stage = "BANDWIDTH_DELEGATABLE";
|
||||||
&& beforeBlock.path("blockID").asText().equalsIgnoreCase(afterBlock.path("blockID").asText()),
|
long bandwidth = delegatable(network, address, 0);
|
||||||
"快照跨区块或本金查询不完整,请重试");
|
stage = "AFTER_BLOCK";
|
||||||
Map<String, Object> result =
|
JsonNode afterBlock = call(network, "/wallet/getnowblock", map());
|
||||||
map(
|
long after = block(afterBlock);
|
||||||
"snapshot_block_height",
|
stage = "BLOCK_CONSISTENCY";
|
||||||
after,
|
log.debug("租赁快照区块夹读 network={} address={} beforeHeight={} afterHeight={} sameBlockId={} elapsedMs={}",
|
||||||
"energy_delegatable_sun",
|
network, address, before, after,
|
||||||
energy,
|
beforeBlock.path("blockID").asText().equalsIgnoreCase(afterBlock.path("blockID").asText()),
|
||||||
"bandwidth_delegatable_sun",
|
TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - started));
|
||||||
bandwidth,
|
if (before < 0 || before != after
|
||||||
"energy_available",
|
|| !beforeBlock.path("blockID").asText().matches("[0-9a-fA-F]{64}")
|
||||||
Math.max(
|
|| !beforeBlock.path("blockID").asText().equalsIgnoreCase(afterBlock.path("blockID").asText())) {
|
||||||
0,
|
log.warn("租赁快照区块不一致 network={} address={} beforeHeight={} afterHeight={}"
|
||||||
resources.path("EnergyLimit").asLong()
|
+ " reason=BLOCK_CHANGED_OR_INVALID;本次不更新,禁止混用不同区块资源",
|
||||||
- resources.path("EnergyUsed").asLong()),
|
network, address, before, after);
|
||||||
"bandwidth_available",
|
|
||||||
Math.max(
|
|
||||||
0,
|
|
||||||
resources.path("NetLimit").asLong()
|
|
||||||
- resources.path("NetUsed").asLong()),
|
|
||||||
"total_energy_limit",
|
|
||||||
resources.path("TotalEnergyLimit").asLong(),
|
|
||||||
"total_energy_weight",
|
|
||||||
resources.path("TotalEnergyWeight").asLong(),
|
|
||||||
"total_bandwidth_limit",
|
|
||||||
resources.path("TotalNetLimit").asLong(),
|
|
||||||
"total_bandwidth_weight",
|
|
||||||
resources.path("TotalNetWeight").asLong(),
|
|
||||||
"snapshot_at",
|
|
||||||
now(),
|
|
||||||
"snapshot_expires_at",
|
|
||||||
after(15));
|
|
||||||
require(
|
|
||||||
number(result, "total_energy_limit") > 0
|
|
||||||
&& number(result, "total_energy_weight") > 0
|
|
||||||
&& 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);
|
|
||||||
}
|
}
|
||||||
|
require(
|
||||||
|
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(
|
||||||
|
"snapshot_block_height",
|
||||||
|
after,
|
||||||
|
"energy_delegatable_sun",
|
||||||
|
energy,
|
||||||
|
"bandwidth_delegatable_sun",
|
||||||
|
bandwidth,
|
||||||
|
"energy_available",
|
||||||
|
Math.max(
|
||||||
|
0,
|
||||||
|
resources.path("EnergyLimit").asLong()
|
||||||
|
- resources.path("EnergyUsed").asLong()),
|
||||||
|
"bandwidth_available",
|
||||||
|
Math.max(
|
||||||
|
0,
|
||||||
|
resources.path("NetLimit").asLong()
|
||||||
|
- resources.path("NetUsed").asLong()),
|
||||||
|
"total_energy_limit",
|
||||||
|
resources.path("TotalEnergyLimit").asLong(),
|
||||||
|
"total_energy_weight",
|
||||||
|
resources.path("TotalEnergyWeight").asLong(),
|
||||||
|
"total_bandwidth_limit",
|
||||||
|
resources.path("TotalNetLimit").asLong(),
|
||||||
|
"total_bandwidth_weight",
|
||||||
|
resources.path("TotalNetWeight").asLong(),
|
||||||
|
"snapshot_at",
|
||||||
|
now(),
|
||||||
|
"snapshot_expires_at",
|
||||||
|
after(15));
|
||||||
|
stage = "GLOBAL_PARAMETERS";
|
||||||
|
if (number(result, "total_energy_limit") <= 0 || number(result, "total_energy_weight") <= 0
|
||||||
|
|| number(result, "total_bandwidth_limit") <= 0 || number(result, "total_bandwidth_weight") <= 0) {
|
||||||
|
log.warn("租赁快照全网参数不完整 network={} address={} energyLimit={} energyWeight={}"
|
||||||
|
+ " bandwidthLimit={} bandwidthWeight={}", network, address,
|
||||||
|
result.get("total_energy_limit"), result.get("total_energy_weight"),
|
||||||
|
result.get("total_bandwidth_limit"), result.get("total_bandwidth_weight"));
|
||||||
|
}
|
||||||
|
require(
|
||||||
|
number(result, "total_energy_limit") > 0
|
||||||
|
&& number(result, "total_energy_weight") > 0
|
||||||
|
&& 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;
|
||||||
|
} catch (RuntimeException ex) {
|
||||||
|
log.warn("租赁链上快照采集失败 network={} address={} stage={} elapsedMs={} diagnostic={}",
|
||||||
|
network, address, stage, TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - started),
|
||||||
|
RentalDiagnostics.describe(ex));
|
||||||
|
throw ex;
|
||||||
}
|
}
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** protobuf省略零字段的空对象表示0;显式错误和非整数绝不能当作0。 */
|
/** protobuf省略零字段的空对象表示0;显式错误和非整数绝不能当作0。 */
|
||||||
|
|||||||
@@ -50,6 +50,16 @@ public class RentalTasks {
|
|||||||
tx(
|
tx(
|
||||||
() -> {
|
() -> {
|
||||||
Map<String, Object> current = store.get("wallet", id, true);
|
Map<String, Object> current = store.get("wallet", id, true);
|
||||||
|
if (number(previous, "version") != number(current, "version")
|
||||||
|
|| number(snapshot, "snapshot_block_height") < number(current, "snapshot_min_block_height")
|
||||||
|
|| (current.get("snapshot_block_height") != null
|
||||||
|
&& number(snapshot, "snapshot_block_height") < number(current, "snapshot_block_height"))) {
|
||||||
|
log.warn("租赁钱包快照写入被拒绝 walletId={} network={} reason=STALE_OR_CONCURRENT"
|
||||||
|
+ " previousVersion={} currentVersion={} sampledHeight={} storedHeight={} minHeight={}",
|
||||||
|
id, current.get("network"), previous.get("version"), current.get("version"),
|
||||||
|
snapshot.get("snapshot_block_height"), current.get("snapshot_block_height"),
|
||||||
|
current.get("snapshot_min_block_height"));
|
||||||
|
}
|
||||||
require(
|
require(
|
||||||
number(previous, "version") == number(current, "version")
|
number(previous, "version") == number(current, "version")
|
||||||
&& number(snapshot, "snapshot_block_height")
|
&& number(snapshot, "snapshot_block_height")
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ public class RentalWorkers {
|
|||||||
"任务推送间隔必须为500到60000毫秒");
|
"任务推送间隔必须为500到60000毫秒");
|
||||||
LOG.info("租赁交付调度配置 dispatchIntervalMs={} pushIntervalMs={}",
|
LOG.info("租赁交付调度配置 dispatchIntervalMs={} pushIntervalMs={}",
|
||||||
dispatchIntervalMs, pushIntervalMs);
|
dispatchIntervalMs, pushIntervalMs);
|
||||||
|
LOG.info("租赁快照定时扫描已启用 intervalMs=15000 batchSize=20,刷新ACTIVE且快照缺失或过期的钱包");
|
||||||
}
|
}
|
||||||
|
|
||||||
@org.springframework.beans.factory.annotation.Autowired
|
@org.springframework.beans.factory.annotation.Autowired
|
||||||
@@ -158,28 +159,46 @@ public class RentalWorkers {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 仅刷新ACTIVE且缺失/过期的快照;失败不推进快照时间,避免将旧数据伪装成新数据。 */
|
||||||
@Scheduled(fixedDelay = 15000)
|
@Scheduled(fixedDelay = 15000)
|
||||||
public void snapshots() {
|
public void snapshots() {
|
||||||
// 按主键轮转,不能让最早20个故障RPC钱包永久阻塞后续供应钱包。
|
// 按主键轮转,不能让最早20个故障RPC钱包永久阻塞后续供应钱包。
|
||||||
List<Map<String, Object>> rows =
|
List<Map<String, Object>> rows =
|
||||||
store.rows(
|
store.rows(
|
||||||
"SELECT id FROM rent_wallet WHERE id>? AND status='ACTIVE' AND"
|
"SELECT id,node_id,network,snapshot_at,snapshot_expires_at FROM rent_wallet WHERE id>? AND status='ACTIVE' AND"
|
||||||
+ " (snapshot_expires_at IS NULL OR snapshot_expires_at<=?) ORDER BY id"
|
+ " (snapshot_expires_at IS NULL OR snapshot_expires_at<=?) ORDER BY id"
|
||||||
+ " LIMIT 20",
|
+ " LIMIT 20",
|
||||||
walletCursor,
|
walletCursor,
|
||||||
now());
|
now());
|
||||||
if (rows.isEmpty()) {
|
if (rows.isEmpty()) {
|
||||||
|
LOG.debug("租赁快照扫描无候选 cursor={},下一轮从头扫描;仅处理ACTIVE且快照过期的钱包", walletCursor);
|
||||||
walletCursor = 0;
|
walletCursor = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
long batchStarted = System.nanoTime();
|
||||||
|
int succeeded = 0;
|
||||||
for (Map<String, Object> row : rows) {
|
for (Map<String, Object> row : rows) {
|
||||||
walletCursor = number(row, "id");
|
walletCursor = number(row, "id");
|
||||||
|
long started = System.nanoTime();
|
||||||
try {
|
try {
|
||||||
tasks.refresh(walletCursor);
|
tasks.refresh(walletCursor);
|
||||||
|
succeeded++;
|
||||||
|
LOG.info("租赁钱包快照刷新成功 walletId={} nodeId={} network={} previousSnapshotAt={} elapsedMs={}",
|
||||||
|
walletCursor, row.get("node_id"), row.get("network"), row.get("snapshot_at"),
|
||||||
|
java.util.concurrent.TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - started));
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
LOG.warn("租赁钱包快照暂不可用,walletId={}", walletCursor);
|
// 异常原文可能包含RPC地址、认证参数或SQL值,只输出安全因果链和代码位置。
|
||||||
|
LOG.warn("租赁钱包快照暂不可用 walletId={} nodeId={} network={} previousSnapshotAt={}"
|
||||||
|
+ " previousExpiresAt={} elapsedMs={} diagnostic={};保留旧快照及原时间,后续轮次重试",
|
||||||
|
walletCursor, row.get("node_id"), row.get("network"), row.get("snapshot_at"),
|
||||||
|
row.get("snapshot_expires_at"),
|
||||||
|
java.util.concurrent.TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - started),
|
||||||
|
RentalDiagnostics.describe(ex));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
LOG.info("租赁快照扫描完成 candidates={} succeeded={} failed={} cursor={} elapsedMs={}",
|
||||||
|
rows.size(), succeeded, rows.size() - succeeded, walletCursor,
|
||||||
|
java.util.concurrent.TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - batchStarted));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void each(String sql, Consumer<Long> action) {
|
private void each(String sql, Consumer<Long> action) {
|
||||||
|
|||||||
Reference in new issue
Block a user