Восстанавливать blockchain state free-пользователей

This commit is contained in:
AidarKC
2026-10-28 19:16:01 +03:00
parent 7b88b61b22
commit c0257f4be2
3 changed files with 51 additions and 2 deletions
@@ -103,6 +103,21 @@ public final class VerifiedFreeRegistrationImporter {
insert.setString(8, login.toLowerCase(java.util.Locale.ROOT) + "-001"); insert.setLong(9, now); insert.setLong(10, now); insert.setString(8, login.toLowerCase(java.util.Locale.ROOT) + "-001"); insert.setLong(9, now); insert.setLong(10, now);
insert.executeUpdate(); insert.executeUpdate();
} }
// blockchain_state — обязательная runtime-проекция новой цепочки.
// Без неё первый пользовательский AddBlock (например, «О себе») будет
// отклонён ещё до проверки подписи.
try (PreparedStatement insert = c.prepareStatement("""
INSERT INTO blockchain_state_store (
login, fork_number, blockchain_key, size_limit, file_size_bytes,
last_block_number, last_block_hash, updated_at_ms)
VALUES (?, 1, ?, 100000, 0, -1, ?, ?)
""")) {
insert.setString(1, login);
insert.setString(2, Base58Util.encode(cert.blockchainKey()));
insert.setBytes(3, new byte[32]);
insert.setLong(4, now);
insert.executeUpdate();
}
try (PreparedStatement insert = c.prepareStatement(""" try (PreparedStatement insert = c.prepareStatement("""
INSERT INTO free_registration_certificate ( INSERT INTO free_registration_certificate (
data_item_id, login, namespace, email_sha256, inner_signature, data_item_id, login, namespace, email_sha256, inner_signature,
@@ -37,11 +37,13 @@ import shine.db.dao.BlockchainStateDAO;
import shine.db.dao.BlocksDAO; import shine.db.dao.BlocksDAO;
import shine.db.dao.CanonicalChainResolver; import shine.db.dao.CanonicalChainResolver;
import shine.db.dao.ChannelNameStateDAO; import shine.db.dao.ChannelNameStateDAO;
import shine.db.dao.CurrentUsersDAO;
import shine.db.dao.UserNotificationsStateDAO; import shine.db.dao.UserNotificationsStateDAO;
import shine.db.dao.UserParamsDAO; import shine.db.dao.UserParamsDAO;
import shine.db.entities.BlockchainStateEntry; import shine.db.entities.BlockchainStateEntry;
import shine.db.entities.BlockEntry; import shine.db.entities.BlockEntry;
import shine.db.entities.ChannelNameStateEntry; import shine.db.entities.ChannelNameStateEntry;
import shine.db.entities.CurrentUserEntry;
import shine.db.entities.UserNotificationEntry; import shine.db.entities.UserNotificationEntry;
import shine.db.entities.UserParamEntry; import shine.db.entities.UserParamEntry;
import utils.blockchain.BlockchainNameUtil; import utils.blockchain.BlockchainNameUtil;
@@ -68,6 +70,7 @@ public final class Net_AddBlock_Handler implements JsonMessageHandler {
private final BlocksDAO blocksDAO = BlocksDAO.getInstance(); private final BlocksDAO blocksDAO = BlocksDAO.getInstance();
private final CanonicalChainResolver canonicalChain = CanonicalChainResolver.getInstance(); private final CanonicalChainResolver canonicalChain = CanonicalChainResolver.getInstance();
private final BlockchainStateDAO stateDAO = BlockchainStateDAO.getInstance(); private final BlockchainStateDAO stateDAO = BlockchainStateDAO.getInstance();
private final CurrentUsersDAO currentUsersDAO = CurrentUsersDAO.getInstance();
private final UserParamsDAO userParamsDAO = UserParamsDAO.getInstance(); private final UserParamsDAO userParamsDAO = UserParamsDAO.getInstance();
private final ChannelNameStateDAO channelNameStateDAO = ChannelNameStateDAO.getInstance(); private final ChannelNameStateDAO channelNameStateDAO = ChannelNameStateDAO.getInstance();
@@ -255,7 +258,7 @@ public final class Net_AddBlock_Handler implements JsonMessageHandler {
} }
// 1) state обязателен // 1) state обязателен
final BlockchainStateEntry st; BlockchainStateEntry st;
try { try {
st = stateDAO.getByBlockchainName(blockchainName); st = stateDAO.getByBlockchainName(blockchainName);
} catch (Exception e) { } catch (Exception e) {
@@ -264,6 +267,37 @@ public final class Net_AddBlock_Handler implements JsonMessageHandler {
return new AddBlockResult(WireCodes.Status.INTERNAL_ERROR, "db_error", 0, ""); return new AddBlockResult(WireCodes.Status.INTERNAL_ERROR, "db_error", 0, "");
} }
if (st == null) {
// Runtime-проекция могла отсутствовать у пользователей, зарегистрированных
// ранней версией free-регистрации. Восстанавливаем только для точно
// существующего владельца этой цепочки; сам блок всё равно проходит
// полную проверку ключа и подписи ниже.
try {
CurrentUserEntry user = currentUsersDAO.getByBlockchainName(blockchainName);
if (user != null) {
BlockchainStateEntry recovered = new BlockchainStateEntry();
recovered.setBlockchainName(user.getBlockchainName());
recovered.setLogin(user.getLogin());
recovered.setBlockchainKey(user.getBlockchainKey());
recovered.setSizeLimit(100_000L);
recovered.setFileSizeBytes(0L);
recovered.setLastBlockNumber(-1);
recovered.setLastBlockHash(new byte[32]);
recovered.setUpdatedAtMs(System.currentTimeMillis());
stateDAO.insertIfMissing(recovered);
st = stateDAO.getByBlockchainName(blockchainName);
if (st != null) {
log.warn("AddBlock: восстановлена отсутствующая blockchain_state для login={}, blockchainName={}",
user.getLogin(), blockchainName);
}
}
} catch (Exception e) {
log.error("AddBlock: не удалось восстановить blockchain_state (login={}, blockchainName={})",
login, blockchainName, e);
return new AddBlockResult(WireCodes.Status.INTERNAL_ERROR, "db_error", 0, "");
}
}
if (st == null) { if (st == null) {
log.warn("AddBlock: blockchain_state_not_found (login={}, blockchainName={}, reqGlobalNumber={})", log.warn("AddBlock: blockchain_state_not_found (login={}, blockchainName={}, reqGlobalNumber={})",
login, blockchainName, globalNumberFromReq); login, blockchainName, globalNumberFromReq);
+1 -1
View File
@@ -1,2 +1,2 @@
client.version=1.20.7 client.version=1.20.7
server.version=1.16.6 server.version=1.16.7