use of io.nuls.core.chain.entity.Block in project nuls by nuls-io.
the class ConsensusManager method loadConfigration.
private void loadConfigration() {
Block bestBlock = null;
Block genesisBlock = GenesisBlock.getInstance();
NulsContext.getInstance().setGenesisBlock(genesisBlock);
try {
bestBlock = blockStorageService.getBlock(blockStorageService.getBestHeight());
} catch (Exception e) {
Log.error(e);
}
if (bestBlock == null) {
bestBlock = genesisBlock;
}
NulsContext.getInstance().setBestBlock(bestBlock);
partakePacking = NulsContext.MODULES_CONFIG.getCfgValue(PocConsensusConstant.CFG_CONSENSUS_SECTION, PocConsensusConstant.PROPERTY_PARTAKE_PACKING, false);
seedNodeList = new ArrayList<>();
Set<String> seedAddressSet = new HashSet<>();
String addresses = NulsContext.MODULES_CONFIG.getCfgValue(PocConsensusConstant.CFG_CONSENSUS_SECTION, PocConsensusConstant.PROPERTY_SEED_NODES, "");
if (StringUtils.isBlank(addresses)) {
return;
}
String[] array = addresses.split(PocConsensusConstant.SEED_NODES_DELIMITER);
if (null == array) {
return;
}
for (String address : array) {
seedAddressSet.add(address);
}
this.seedNodeList.addAll(seedAddressSet);
}
use of io.nuls.core.chain.entity.Block in project nuls by nuls-io.
the class BlockServiceImpl method getBlockList.
@Override
public List<Block> getBlockList(long startHeight, long endHeight) throws NulsException {
List<Block> blockList = blockStorageService.getBlockList(startHeight, endHeight);
if (blockList.size() < (endHeight - startHeight + 1)) {
long currentMaxHeight = blockList.get(blockList.size() - 1).getHeader().getHeight();
while (currentMaxHeight < endHeight) {
long next = currentMaxHeight + 1;
Block block = blockManager.getBlock(next);
if (null == block) {
try {
block = blockStorageService.getBlock(next);
} catch (Exception e) {
Log.error(e);
}
}
if (null != block) {
blockList.add(block);
}
}
}
Collections.sort(blockList, BlockHeightComparator.getInstance());
return blockList;
}
use of io.nuls.core.chain.entity.Block in project nuls by nuls-io.
the class BlockStorageService method getBlockList.
public List<Block> getBlockList(long startHeight, long endHeight) throws NulsException {
List<Block> blockList = new ArrayList<>();
List<BlockHeaderPo> poList = headerDao.getHeaderList(startHeight, endHeight);
List<Long> heightList = new ArrayList<>();
if (!poList.isEmpty()) {
List<Transaction> txList = null;
try {
txList = ledgerService.getTxList(startHeight, endHeight);
} catch (Exception e) {
Log.error(e);
}
Map<Long, List<Transaction>> txListGroup = txListGrouping(txList);
for (BlockHeaderPo po : poList) {
BlockHeader header = null;
try {
header = ConsensusTool.fromPojo(po);
} catch (NulsException e) {
throw e;
}
heightList.add(header.getHeight());
blockList.add(fillBlock(header, txListGroup.get(header.getHeight())));
}
}
if ((endHeight - startHeight + 1) > blockList.size()) {
for (long i = startHeight; i <= endHeight; i++) {
if (heightList.contains(i)) {
continue;
}
try {
blockList.add(this.getBlock(i));
} catch (Exception e) {
Log.error(e);
}
}
}
return blockList;
}
use of io.nuls.core.chain.entity.Block in project nuls by nuls-io.
the class BlockStorageService method fillBlock.
private Block fillBlock(BlockHeader header, List<Transaction> txList) {
Block block = new Block();
block.setTxs(txList);
block.setHeader(header);
return block;
}
use of io.nuls.core.chain.entity.Block in project nuls by nuls-io.
the class BlockStorageService method getBlockHeader.
public BlockHeader getBlockHeader(String hash) throws NulsException {
BlockHeader header = blockCacheManager.getBlockHeader(hash);
if (null != header) {
return header;
}
Block block = blockCacheManager.getBlock(hash);
if (null != block) {
return block.getHeader();
}
BlockHeaderPo po = this.headerDao.getHeader(hash);
return ConsensusTool.fromPojo(po);
}
Aggregations