Search in sources :

Example 1 with RandomSeedPo

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;
}
Also used : RandomSeedPo(io.nuls.consensus.poc.storage.po.RandomSeedPo) ArrayList(java.util.ArrayList)

Example 2 with RandomSeedPo

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;
}
Also used : RandomSeedPo(io.nuls.consensus.poc.storage.po.RandomSeedPo) NulsException(io.nuls.kernel.exception.NulsException) NulsByteBuffer(io.nuls.kernel.utils.NulsByteBuffer)

Example 3 with RandomSeedPo

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()));
    }
}
Also used : RandomSeedPo(io.nuls.consensus.poc.storage.po.RandomSeedPo)

Example 4 with RandomSeedPo

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;
}
Also used : RandomSeedPo(io.nuls.consensus.poc.storage.po.RandomSeedPo) IOException(java.io.IOException)

Example 5 with RandomSeedPo

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;
}
Also used : RandomSeedPo(io.nuls.consensus.poc.storage.po.RandomSeedPo) ArrayList(java.util.ArrayList)

Aggregations

RandomSeedPo (io.nuls.consensus.poc.storage.po.RandomSeedPo)5 ArrayList (java.util.ArrayList)2 NulsException (io.nuls.kernel.exception.NulsException)1 NulsByteBuffer (io.nuls.kernel.utils.NulsByteBuffer)1 IOException (java.io.IOException)1