private void executeBlock() { // Run Block // GET BEST BLOCK long bestBlock = metaStore.getBestBlock(); long lastExecuteBlock = metaStore.getLastExecuteBlockIndex(); // TODO Validate Block will be stored if (bestBlock > lastExecuteBlock) { runExecute = true; while (lastExecuteBlock < bestBlock) { lastExecuteBlock++; BlockHusk block = store.getBlockByIndex(lastExecuteBlock); if (block == null) { throw new FailedOperationException("Blockchain is not wired"); } // Block Execute // TODO get block execute root state runtime.invokeBlock(block); // Set Next ExecuteBlock metaStore.setLastExecuteBlock(block); log.info("Block "+block.getIndex()+" Execute Complite"); } runExecute = false; } } }
public void setBestBlock(BlockHusk block) { setBestBlockHash(block.getHash()); setBestBlock(block.getIndex()); }
@Test public void shouldBeLoaded() { ms = createMetaStore(); BlockHusk blockHusk = BlockChainTestUtils.genesisBlock(); ms.setBestBlockHash(blockHusk.getHash()); Sha3Hash sha3Hash = ms.getBestBlockHash(); Assertions.assertThat(sha3Hash).isEqualTo(blockHusk.getHash()); ms.close(); ms = createMetaStore(); Sha3Hash sha3HashAgain = ms.getBestBlockHash(); Assertions.assertThat(sha3HashAgain).isEqualTo(sha3Hash); }
@Test public void shouldBePutMeta() { ms = createMetaStore(); BlockHusk blockHusk = BlockChainTestUtils.genesisBlock(); ms.setBestBlock(blockHusk); Long bestBlock = ms.getBestBlock(); Assertions.assertThat(bestBlock).isEqualTo(blockHusk.getIndex()); }
@Test public void shouldBeBuiltMetaStore() { BlockHusk block = BlockChainTestUtils.genesisBlock(); StoreBuilder builder = new StoreBuilder(new DefaultConfig()); MetaStore store = builder.buildMetaStore(BRANCH_ID); store.setBestBlock(block); assertThat(store.contains(BlockchainMetaInfo.BRANCH.toString())).isTrue(); assertThat(store.getBestBlockHash()).isEqualTo(block.getHash()); }
metaStore.setBestBlock(nextBlock); if (nextBlock.getIndex() > metaStore.getLastExecuteBlockIndex()) { BlockRuntimeResult result = runtime.invokeBlock(nextBlock); metaStore.setLastExecuteBlock(nextBlock);
private void loadTransaction() { // load recent 1000 block // Start Block and End Block Long bestBlock = metaStore.getBestBlock(); Long loadStart = bestBlock > 1000 ? bestBlock - 1000 : 0; for (long i = loadStart; i <= bestBlock; i++) { // recent block load and update Cache BlockHusk block = blockStore.getBlockByIndex(i); transactionStore.updateCache(block.getBody()); // set Last Best Block if (i == bestBlock) { this.prevBlock = block; } } }
public void close() { this.blockStore.close(); this.transactionStore.close(); this.metaStore.close(); // TODO refactoring this.stateStore.close(); this.transactionReceiptStore.close(); }
private MetaStore createMetaStore() { LevelDbDataSource ds = new LevelDbDataSource(StoreTestUtils.getTestPath(), "meta"); return new MetaStore(ds); } }
public Long getLastExecuteBlockIndex() { return reStoreToLong(BlockchainMetaInfo.LAST_EXECUTE_BLOCK_INDEX.toString(), -1); }
public Long getBestBlock() { return reStoreToLong(BlockchainMetaInfo.BEST_BLOCK_INDEX.toString(), -1); }