use of com.radixdlt.atom.SubstateTypeId in project radixdlt by radixdlt.
the class BerkeleyLedgerEntryStore method open.
private void open() {
var primaryConfig = buildPrimaryConfig();
var rriConfig = buildRriConfig();
var pendingConfig = buildPendingConfig();
try {
// This SuppressWarnings here is valid, as ownership of the underlying
// resource is not changed here, the resource is just accessed.
@SuppressWarnings("resource") var env = dbEnv.getEnvironment();
txnDatabase = env.openDatabase(null, TXN_DB_NAME, primaryConfig);
resourceDatabase = env.openDatabase(null, RESOURCE_DB_NAME, rriConfig);
mapDatabase = env.openDatabase(null, MAP_DB_NAME, rriConfig);
substatesDatabase = env.openDatabase(null, SUBSTATE_DB_NAME, primaryConfig);
indexedSubstatesDatabase = env.openSecondaryDatabase(null, INDEXED_SUBSTATE_DB_NAME, substatesDatabase, (SecondaryConfig) new SecondaryConfig().setKeyCreator((secondary, key, data, result) -> {
if (entryToSpin(data) != REOp.UP) {
return false;
}
var substateTypeId = data.getData()[data.getOffset()];
final int prefixIndexSize;
if (substateTypeId == SubstateTypeId.TOKENS.id()) {
// Indexing not necessary for verification at the moment but useful
// for construction
// 0: Type Byte
// 1: Reserved Byte
// 2-37: Account Address
prefixIndexSize = 2 + (1 + ECPublicKey.COMPRESSED_BYTES);
} else if (substateTypeId == SubstateTypeId.STAKE_OWNERSHIP.id()) {
// Indexing not necessary for verification at the moment but useful
// for construction
// This should have had validator keys and account addresses switched
// so that
// prefix indexing could be done against account addresses rather than
// validators
// so that actions like "Unstake Everything" could be implemented and
// queries against
// accounts. A later to do...
// 0: Type Byte
// 1: Reserved Byte
// 2-36: Validator Key
// 37-69: Account Address
prefixIndexSize = 2 + ECPublicKey.COMPRESSED_BYTES + (1 + ECPublicKey.COMPRESSED_BYTES);
} else if (substateTypeId == SubstateTypeId.EXITING_STAKE.id()) {
// 0: Type Byte
// 1: Reserved Byte
// 2-5: Epoch
// 6-40: Validator Key
// 41-73: Account Address
prefixIndexSize = 2 + Long.BYTES + ECPublicKey.COMPRESSED_BYTES + (1 + ECPublicKey.COMPRESSED_BYTES);
} else if (substateTypeId == SubstateTypeId.PREPARED_STAKE.id()) {
// 0: Type Byte
// 1: Reserved Byte
// 2-36: Validator Key
// 37-69: Account Address
prefixIndexSize = 2 + ECPublicKey.COMPRESSED_BYTES + (1 + ECPublicKey.COMPRESSED_BYTES);
} else if (substateTypeId == SubstateTypeId.PREPARED_UNSTAKE.id()) {
// 0: Type Byte
// 1: Reserved Byte
// 2-36: Validator Key
// 37-69: Account Address
prefixIndexSize = 2 + ECPublicKey.COMPRESSED_BYTES + (1 + ECPublicKey.COMPRESSED_BYTES);
} else if (substateTypeId == SubstateTypeId.VALIDATOR_OWNER_COPY.id()) {
// 0: Type Byte
// 1: Reserved Byte
// 2: Optional flag
// 3-6: Epoch
// 7-41: Validator Key
prefixIndexSize = 3 + Long.BYTES + ECPublicKey.COMPRESSED_BYTES;
} else if (substateTypeId == SubstateTypeId.VALIDATOR_REGISTERED_FLAG_COPY.id()) {
// 0: Type Byte
// 1: Reserved Byte
// 2: Optional flag
// 3-6: Epoch
// 7-41: Validator Key
prefixIndexSize = 3 + Long.BYTES + ECPublicKey.COMPRESSED_BYTES;
} else if (substateTypeId == SubstateTypeId.VALIDATOR_RAKE_COPY.id()) {
// 0: Type Byte
// 1: Reserved Byte
// 2: Optional flag
// 3-6: Epoch
// 7-41: Validator Key
prefixIndexSize = 3 + Long.BYTES + ECPublicKey.COMPRESSED_BYTES;
} else if (substateTypeId == SubstateTypeId.VALIDATOR_STAKE_DATA.id()) {
// 0: Type Byte
// 1: Reserved Byte
// 2: Registered Byte
// 3-34: Stake amount
// 35-67: Validator key
prefixIndexSize = 3 + UInt256.BYTES + ECPublicKey.COMPRESSED_BYTES;
} else {
// 0: Type Byte
prefixIndexSize = 1;
}
// Index by substate type
result.setData(data.getData(), data.getOffset(), prefixIndexSize);
return true;
}).setBtreeComparator(lexicographicalComparator()).setSortedDuplicates(true).setAllowCreate(true).setTransactional(true));
proofDatabase = env.openDatabase(null, PROOF_DB_NAME, primaryConfig);
vertexStoreDatabase = env.openDatabase(null, VERTEX_STORE_DB_NAME, pendingConfig);
epochProofDatabase = env.openSecondaryDatabase(null, EPOCH_PROOF_DB_NAME, proofDatabase, buildEpochProofConfig());
forkConfigDatabase = env.openDatabase(null, FORK_CONFIG_DB, primaryConfig);
forksVotingResultsDatabase = env.openDatabase(null, FORKS_VOTING_RESULTS_DB, primaryConfig.clone().setSortedDuplicates(true));
txnLog = AppendLog.openCompressed(new File(env.getHome(), LEDGER_NAME).getAbsolutePath(), systemCounters);
} catch (Exception e) {
throw new BerkeleyStoreException("Error while opening databases", e);
}
this.additionalStores.forEach(b -> b.open(dbEnv));
if (System.getProperty("db.check_integrity", "1").equals("1")) {
// TODO implement integrity check
// TODO perhaps we should implement recovery instead?
// TODO recovering should be integrated with recovering of ClientApiStore
}
}
Aggregations