Search in sources :

Example 1 with BufferedKVStorage

use of com.jd.blockchain.storage.service.utils.BufferedKVStorage in project jdchain-core by blockchain-jd-com.

the class LedgerTransactionalEditor method innerGetEventset.

private LedgerEventSetEditor innerGetEventset() {
    if (this.latestLedgerEventSet == null) {
        this.eventsetStorage = new BufferedKVStorage(Crypto.getHashFunction(cryptoSetting.getHashAlgorithm()), baseStorage, baseStorage, false);
        this.latestLedgerEventSet = createEventSetFromLastestSnapshot(eventsetStorage);
    }
    return this.latestLedgerEventSet;
}
Also used : BufferedKVStorage(com.jd.blockchain.storage.service.utils.BufferedKVStorage)

Example 2 with BufferedKVStorage

use of com.jd.blockchain.storage.service.utils.BufferedKVStorage in project jdchain-core by blockchain-jd-com.

the class LedgerTransactionalEditor method innerGetDataset.

private LedgerDataSetEditor innerGetDataset() {
    if (this.latestLedgerDataset == null) {
        this.datasetStorage = new BufferedKVStorage(Crypto.getHashFunction(cryptoSetting.getHashAlgorithm()), baseStorage, baseStorage, false);
        this.latestLedgerDataset = createDatasetFromLastestSnapshot(datasetStorage);
    }
    return this.latestLedgerDataset;
}
Also used : BufferedKVStorage(com.jd.blockchain.storage.service.utils.BufferedKVStorage)

Example 3 with BufferedKVStorage

use of com.jd.blockchain.storage.service.utils.BufferedKVStorage in project jdchain-core by blockchain-jd-com.

the class LedgerTransactionalEditor method createEditor.

/**
 * 创建创世区块的编辑器;
 *
 * @param initSetting
 * @param ledgerKeyPrefix
 * @param ledgerExStorage
 * @param ledgerVerStorage
 * @param verifyTx         是否校验交易请求;当外部调用者在调用前已经实施了验证时,将次参数设置为 false 能够提升性能;
 * @return
 */
public static LedgerTransactionalEditor createEditor(LedgerInitSetting initSetting, String ledgerKeyPrefix, ExPolicyKVStorage ledgerExStorage, VersioningKVStorage ledgerVerStorage, LedgerDataStructure dataStructure) {
    LedgerBlockData genesisBlock = new LedgerBlockData(0, null, null);
    StagedSnapshot startingPoint = new GenesisSnapshot(initSetting);
    // init storage;
    BufferedKVStorage txStagedStorage = new BufferedKVStorage(Crypto.getHashFunction(initSetting.getCryptoSetting().getHashAlgorithm()), ledgerExStorage, ledgerVerStorage, false);
    TransactionSetEditor txset = LedgerRepositoryImpl.newTransactionSet(initSetting.getCryptoSetting(), ledgerKeyPrefix, txStagedStorage, txStagedStorage, dataStructure);
    return new LedgerTransactionalEditor(null, initSetting.getCryptoSetting(), genesisBlock, startingPoint, ledgerKeyPrefix, txset, txStagedStorage, dataStructure);
}
Also used : BufferedKVStorage(com.jd.blockchain.storage.service.utils.BufferedKVStorage)

Example 4 with BufferedKVStorage

use of com.jd.blockchain.storage.service.utils.BufferedKVStorage in project jdchain-core by blockchain-jd-com.

the class LedgerTransactionalEditor method createEditor.

/**
 * 创建账本新区块的编辑器;
 *
 * @param ledgerHash       账本哈希;
 * @param ledgerSetting    账本设置;
 * @param previousBlock    前置区块;
 * @param ledgerKeyPrefix  账本数据前缀;
 * @param ledgerExStorage  账本数据存储;
 * @param ledgerVerStorage 账本数据版本化存储;
 * @param verifyTx         是否校验交易请求;当外部调用者在调用前已经实施了验证时,将次参数设置为 false 能够提升性能;
 * @return
 */
public static LedgerTransactionalEditor createEditor(LedgerBlock previousBlock, LedgerSettings ledgerSetting, String ledgerKeyPrefix, ExPolicyKVStorage ledgerExStorage, VersioningKVStorage ledgerVerStorage, LedgerDataStructure dataStructure) {
    // new block;
    HashDigest ledgerHash = previousBlock.getLedgerHash();
    if (ledgerHash == null) {
        ledgerHash = previousBlock.getHash();
    }
    if (ledgerHash == null) {
        throw new IllegalArgumentException("Illegal previous block was specified!");
    }
    LedgerBlockData currBlock = new LedgerBlockData(previousBlock.getHeight() + 1, ledgerHash, previousBlock.getHash());
    // init storage;
    BufferedKVStorage txStagedStorage = new BufferedKVStorage(Crypto.getHashFunction(ledgerSetting.getCryptoSetting().getHashAlgorithm()), ledgerExStorage, ledgerVerStorage, PARALLEL_DB_WRITE);
    TransactionSetEditor txset = LedgerRepositoryImpl.loadTransactionSet(previousBlock.getHeight(), previousBlock.getTransactionSetHash(), ledgerSetting.getCryptoSetting(), ledgerKeyPrefix, txStagedStorage, txStagedStorage, dataStructure, false);
    StagedSnapshot startingPoint = new TxSnapshot(null, previousBlock);
    // instantiate editor;
    return new LedgerTransactionalEditor(ledgerHash, ledgerSetting.getCryptoSetting(), currBlock, startingPoint, ledgerKeyPrefix, txset, txStagedStorage, dataStructure);
}
Also used : BufferedKVStorage(com.jd.blockchain.storage.service.utils.BufferedKVStorage) HashDigest(com.jd.blockchain.crypto.HashDigest)

Example 5 with BufferedKVStorage

use of com.jd.blockchain.storage.service.utils.BufferedKVStorage in project jdchain-core by blockchain-jd-com.

the class TransactionSetTest method testSpecialCase_1.

/**
 * 根据实际运行中一个随机出现的错误中提取到的数据来建立的测试用例,可以更简化地验证正确性;
 *
 * <p>
 *
 * 注:重构了 {@link LedgerTransaction} 和 {@link TransactionContent}
 * 等交易结构相关的类型之后,此用例已经失效; by huanghaiquan on 2020-09-16;
 */
// @Test
public void testSpecialCase_1() {
    CryptoSetting defCryptoSetting = LedgerTestUtils.createDefaultCryptoSetting();
    MemoryKVStorage testStorage = new MemoryKVStorage();
    BufferedKVStorage bufferStorage = new BufferedKVStorage(null, testStorage, testStorage, false);
    // Create a new TransactionSet, it's empty;
    TransactionSetEditor txset = new TransactionSetEditor(defCryptoSetting, keyPrefix, bufferStorage, bufferStorage, LedgerDataStructure.MERKLE_TREE);
    assertTrue(txset.isUpdated());
    assertFalse(txset.isReadonly());
    assertNull(txset.getRootHash());
    HashDigest ledgerHash = Crypto.resolveAsHashDigest(Base58Utils.decode("j5iF5xJ7KN4kjRrhD3EUKVSPmHz2bExxp3h9avqxcnnzch"));
    assertEquals("j5iF5xJ7KN4kjRrhD3EUKVSPmHz2bExxp3h9avqxcnnzch", ledgerHash.toBase58());
    BlockchainKeypair parti0 = LedgerTestUtils.createKeyPair("7VeRLBwqTAz8oRazEazeaEfqei46sk2FzvBgyHMUBJvrUEGT", "7VeRUm27GbrsX9HbQSZguChLp24HZYub6s5FJ7FjBht8BmbA");
    BlockchainKeypair userKeypair1 = LedgerTestUtils.createKeyPair("7VeRKf3GFLFcBfzvtzmtyMXEoX2HYGEJ4j7CmHcnRV99W5Dp", "7VeRYQjeAaQY5Po8MMtmGNHA2SniqLXmJaZwBS5K8zTtMAU1");
    TransactionRequest transactionRequest1 = LedgerTestUtils.createTxRequest_UserReg_SHA256(userKeypair1, ledgerHash, 1580315317127L, parti0, parti0);
    // TransactionRequest transactionRequest1 = LedgerTestUtils.createTxRequest_UserReg(userKeypair1, ledgerHash, 202001202020L,
    // parti0, parti0);
    System.out.printf("\r\n ===||=== transactionRequest1.getTransactionHash()=[%s]\r\n", transactionRequest1.getTransactionHash().toBase58());
    // assertEquals("j5sXmpcomtM2QMUNWeQWsF8bNFFnyeXoCjVAekEeLSscgY", transactionRequest1.getTransactionHash().toBase58());
    assertEquals("j5wPGKT5CUzwi8j6VfCWaP2p9YZ6WVWtMANp9HbHWzvhgG", transactionRequest1.getTransactionHash().toBase58());
    TransactionStagedSnapshot txSnapshot = new TransactionStagedSnapshot();
    txSnapshot.setAdminAccountHash(Crypto.resolveAsHashDigest(Base58Utils.decode("j5taeK6cpmJGcn8QbEYCqadna6s7NDSheDTK6NJdU4mFhh")));
    txSnapshot.setUserAccountSetHash(Crypto.resolveAsHashDigest(Base58Utils.decode("j5oQDSob92mCoGSHtrXa9soqgAtMyjwfRMt2kj7igXXJrP")));
    TransactionResult tx = new TransactionResultData(transactionRequest1.getTransactionHash(), 1, TransactionState.SUCCESS, txSnapshot);
    txset.addTransaction(transactionRequest1, tx);
    LedgerTransaction tx_query = txset.getTransaction(transactionRequest1.getTransactionHash());
    assertNotNull(tx_query);
    txset.commit();
    bufferStorage.commit();
    tx_query = txset.getTransaction(transactionRequest1.getTransactionHash());
    TransactionState tx_state = txset.getState(transactionRequest1.getTransactionHash());
    assertNotNull(tx_query);
    assertEquals(0, tx_state.CODE);
    HashDigest txsetRootHash = txset.getRootHash();
    txset = new TransactionSetEditor(-1, txsetRootHash, defCryptoSetting, keyPrefix, testStorage, testStorage, LedgerDataStructure.MERKLE_TREE, false);
    tx_query = txset.getTransaction(transactionRequest1.getTransactionHash());
    tx_state = txset.getState(transactionRequest1.getTransactionHash());
    assertNotNull(tx_query);
    assertEquals(0, tx_state.CODE);
}
Also used : TransactionState(com.jd.blockchain.ledger.TransactionState) TransactionStagedSnapshot(com.jd.blockchain.ledger.core.TransactionStagedSnapshot) TransactionResult(com.jd.blockchain.ledger.TransactionResult) CryptoSetting(com.jd.blockchain.ledger.CryptoSetting) BufferedKVStorage(com.jd.blockchain.storage.service.utils.BufferedKVStorage) HashDigest(com.jd.blockchain.crypto.HashDigest) LedgerTransaction(com.jd.blockchain.ledger.LedgerTransaction) MemoryKVStorage(com.jd.blockchain.storage.service.utils.MemoryKVStorage) BlockchainKeypair(com.jd.blockchain.ledger.BlockchainKeypair) TransactionSetEditor(com.jd.blockchain.ledger.core.TransactionSetEditor) TransactionRequest(com.jd.blockchain.ledger.TransactionRequest) TransactionResultData(com.jd.blockchain.ledger.core.TransactionResultData)

Aggregations

BufferedKVStorage (com.jd.blockchain.storage.service.utils.BufferedKVStorage)5 HashDigest (com.jd.blockchain.crypto.HashDigest)2 BlockchainKeypair (com.jd.blockchain.ledger.BlockchainKeypair)1 CryptoSetting (com.jd.blockchain.ledger.CryptoSetting)1 LedgerTransaction (com.jd.blockchain.ledger.LedgerTransaction)1 TransactionRequest (com.jd.blockchain.ledger.TransactionRequest)1 TransactionResult (com.jd.blockchain.ledger.TransactionResult)1 TransactionState (com.jd.blockchain.ledger.TransactionState)1 TransactionResultData (com.jd.blockchain.ledger.core.TransactionResultData)1 TransactionSetEditor (com.jd.blockchain.ledger.core.TransactionSetEditor)1 TransactionStagedSnapshot (com.jd.blockchain.ledger.core.TransactionStagedSnapshot)1 MemoryKVStorage (com.jd.blockchain.storage.service.utils.MemoryKVStorage)1