use of co.rsk.logfilter.BlocksBloomStore in project rskj by rsksmart.
the class CliToolsTest method indexBlooms.
@Test
public void indexBlooms() {
Block block = mock(Block.class);
BlockStore blockStore = mock(BlockStore.class);
BlocksBloomStore blocksBloomStore = mock(BlocksBloomStore.class);
ArgumentCaptor<BlocksBloom> captor = ArgumentCaptor.forClass(BlocksBloom.class);
doReturn(new byte[Bloom.BLOOM_BYTES]).when(block).getLogBloom();
doReturn(block).when(blockStore).getChainBlockByNumber(anyLong());
doAnswer(i -> {
long num = i.getArgument(0);
return num - (num % 64);
}).when(blocksBloomStore).firstNumberInRange(anyLong());
doAnswer(i -> {
long num = i.getArgument(0);
return num - (num % 64) + 64 - 1;
}).when(blocksBloomStore).lastNumberInRange(anyLong());
IndexBlooms.execute(new IndexBlooms.Range(0, 63), blockStore, blocksBloomStore);
verify(blocksBloomStore, times(1)).addBlocksBloom(captor.capture());
verify(blockStore, times(64)).getChainBlockByNumber(anyLong());
BlocksBloom blocksBloom = captor.getValue();
assertEquals(0, blocksBloom.fromBlock());
assertEquals(63, blocksBloom.toBlock());
assertArrayEquals(new byte[Bloom.BLOOM_BYTES], blocksBloom.getBloom().getData());
clearInvocations(blocksBloomStore, blockStore);
IndexBlooms.execute(new IndexBlooms.Range(60, 300), blockStore, blocksBloomStore);
// saved 3 block blooms in range [60..300]
verify(blocksBloomStore, times(3)).addBlocksBloom(captor.capture());
int i = 0;
for (BlocksBloom bb : captor.getAllValues()) {
assertEquals(i * 64L, bb.fromBlock());
assertEquals(i * 64L + 63L, bb.toBlock());
assertArrayEquals(new byte[Bloom.BLOOM_BYTES], bb.getBloom().getData());
i++;
}
// [60..63] - ignored, [64..300] - processed
// 192 (3*64) processed and saved, and 45 processed but not saved
verify(blockStore, times(192 + 45)).getChainBlockByNumber(anyLong());
}
use of co.rsk.logfilter.BlocksBloomStore in project rskj by rsksmart.
the class IndexBlooms method main.
public static void main(String[] args) {
try (RskContext ctx = new RskContext(args)) {
BlockStore blockStore = ctx.getBlockStore();
BlocksBloomStore blocksBloomStore = ctx.getBlocksBloomStore();
execute(makeBlockRange(args, blockStore), blockStore, blocksBloomStore);
}
}
use of co.rsk.logfilter.BlocksBloomStore in project rskj by rsksmart.
the class Web3ImplLogsTest method createWeb3.
private Web3Impl createWeb3() {
Wallet wallet = WalletFactory.createWallet();
PersonalModule personalModule = new PersonalModuleWalletEnabled(config, eth, wallet, transactionPool);
EthModule ethModule = new EthModule(config.getNetworkConstants().getBridgeConstants(), config.getNetworkConstants().getChainId(), blockChain, transactionPool, null, new ExecutionBlockRetriever(mainchainView, blockChain, null, null), null, new EthModuleWalletEnabled(wallet), null, new BridgeSupportFactory(null, config.getNetworkConstants().getBridgeConstants(), config.getActivationConfig()), config.getGasEstimationCap());
TxPoolModule txPoolModule = new TxPoolModuleImpl(transactionPool);
DebugModule debugModule = new DebugModuleImpl(null, null, Web3Mocks.getMockMessageHandler(), null);
return new Web3RskImpl(eth, blockChain, config, Web3Mocks.getMockMinerClient(), Web3Mocks.getMockMinerServer(), personalModule, ethModule, null, txPoolModule, null, debugModule, null, null, Web3Mocks.getMockChannelManager(), null, null, blockStore, receiptStore, null, null, null, new SimpleConfigCapabilities(), null, new BlocksBloomStore(2, 0, new HashMapDB()), mock(Web3InformationRetriever.class), null);
}
Aggregations