use of io.nuls.consensus.poc.storage.po.RandomSeedPo in project nuls by nuls-io.
the class RandomSeedsStorageServiceImpl method getSeeds.
@Override
public List<byte[]> getSeeds(long maxHeight, int seedCount) {
List<byte[]> list = new ArrayList<>();
long minHeight = maxHeight - 1000L;
while (maxHeight > minHeight) {
RandomSeedPo po = getSeed(maxHeight--);
if (null != po && !ArraysTool.arrayEquals(po.getSeed(), ConsensusStorageConstant.EMPTY_SEED)) {
list.add(po.getSeed());
}
if (list.size() >= seedCount) {
break;
}
}
return list;
}
use of io.nuls.consensus.poc.storage.po.RandomSeedPo in project nuls by nuls-io.
the class RandomSeedsStorageServiceImpl method getSeed.
@Override
public RandomSeedPo getSeed(long height) {
byte[] bytes = dbService.get(ConsensusStorageConstant.DB_NAME_RANDOM_SEEDS, SerializeUtils.uint64ToByteArray(height));
if (null == bytes) {
return null;
}
RandomSeedPo po = new RandomSeedPo();
try {
po.parse(new NulsByteBuffer(bytes, 0));
po.setHeight(height);
} catch (NulsException e) {
Log.error(e);
}
return po;
}
use of io.nuls.consensus.poc.storage.po.RandomSeedPo in project nuls by nuls-io.
the class RandomSeedService method rollbackBlock.
public void rollbackBlock(BlockHeader header) {
if (NulsVersionManager.getMainVersion() < 3) {
return;
}
RandomSeedPo po = randomSeedsStorageService.getSeed(header.getHeight());
randomSeedsStorageService.deleteRandomSeed(header.getHeight());
if (null == po || po.getPreHeight() == 0L) {
randomSeedsStorageService.deleteAddressStatus(header.getPackingAddress());
} else {
randomSeedsStorageService.saveAddressStatus(header.getPackingAddress(), po.getPreHeight(), po.getSeed(), RandomSeedUtils.getLastDigestEightBytes(po.getSeed()));
}
}
use of io.nuls.consensus.poc.storage.po.RandomSeedPo in project nuls by nuls-io.
the class RandomSeedsStorageServiceImpl method saveRandomSeed.
@Override
public boolean saveRandomSeed(long height, long preHeight, byte[] seed, byte[] nextSeedHash) {
RandomSeedPo po = new RandomSeedPo();
po.setPreHeight(preHeight);
po.setSeed(seed);
po.setNextSeedHash(nextSeedHash);
try {
dbService.put(ConsensusStorageConstant.DB_NAME_RANDOM_SEEDS, SerializeUtils.uint64ToByteArray(height), po.serialize());
return true;
} catch (IOException e) {
Log.error(e);
}
return false;
}
use of io.nuls.consensus.poc.storage.po.RandomSeedPo in project nuls by nuls-io.
the class RandomSeedsStorageServiceImpl method getSeeds.
@Override
public List<byte[]> getSeeds(long startHeight, long endHeight) {
List<byte[]> list = new ArrayList<>();
long height = startHeight;
while (height <= endHeight) {
RandomSeedPo po = getSeed(height++);
if (null != po && !ArraysTool.arrayEquals(po.getSeed(), ConsensusStorageConstant.EMPTY_SEED)) {
list.add(po.getSeed());
}
}
return list;
}
Aggregations