Search in sources :

Example 1 with BlocksBloomStore

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());
}
Also used : BlocksBloom(co.rsk.logfilter.BlocksBloom) IndexedBlockStore(org.ethereum.db.IndexedBlockStore) BlockStore(org.ethereum.db.BlockStore) Block(org.ethereum.core.Block) BlocksBloomStore(co.rsk.logfilter.BlocksBloomStore) Test(org.junit.Test) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)

Example 2 with BlocksBloomStore

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);
    }
}
Also used : BlockStore(org.ethereum.db.BlockStore) RskContext(co.rsk.RskContext) BlocksBloomStore(co.rsk.logfilter.BlocksBloomStore)

Example 3 with 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);
}
Also used : Wallet(co.rsk.core.Wallet) Web3RskImpl(co.rsk.rpc.Web3RskImpl) TxPoolModuleImpl(co.rsk.rpc.modules.txpool.TxPoolModuleImpl) DebugModuleImpl(co.rsk.rpc.modules.debug.DebugModuleImpl) PersonalModuleWalletEnabled(co.rsk.rpc.modules.personal.PersonalModuleWalletEnabled) HashMapDB(org.ethereum.datasource.HashMapDB) EthModuleWalletEnabled(co.rsk.rpc.modules.eth.EthModuleWalletEnabled) BlocksBloomStore(co.rsk.logfilter.BlocksBloomStore) Web3InformationRetriever(co.rsk.rpc.Web3InformationRetriever) PersonalModule(co.rsk.rpc.modules.personal.PersonalModule) EthModule(co.rsk.rpc.modules.eth.EthModule) DebugModule(co.rsk.rpc.modules.debug.DebugModule) SimpleConfigCapabilities(org.ethereum.rpc.Simples.SimpleConfigCapabilities) BridgeSupportFactory(co.rsk.peg.BridgeSupportFactory) ExecutionBlockRetriever(co.rsk.rpc.ExecutionBlockRetriever) TxPoolModule(co.rsk.rpc.modules.txpool.TxPoolModule)

Aggregations

BlocksBloomStore (co.rsk.logfilter.BlocksBloomStore)3 BlockStore (org.ethereum.db.BlockStore)2 RskContext (co.rsk.RskContext)1 Wallet (co.rsk.core.Wallet)1 BlocksBloom (co.rsk.logfilter.BlocksBloom)1 BridgeSupportFactory (co.rsk.peg.BridgeSupportFactory)1 ExecutionBlockRetriever (co.rsk.rpc.ExecutionBlockRetriever)1 Web3InformationRetriever (co.rsk.rpc.Web3InformationRetriever)1 Web3RskImpl (co.rsk.rpc.Web3RskImpl)1 DebugModule (co.rsk.rpc.modules.debug.DebugModule)1 DebugModuleImpl (co.rsk.rpc.modules.debug.DebugModuleImpl)1 EthModule (co.rsk.rpc.modules.eth.EthModule)1 EthModuleWalletEnabled (co.rsk.rpc.modules.eth.EthModuleWalletEnabled)1 PersonalModule (co.rsk.rpc.modules.personal.PersonalModule)1 PersonalModuleWalletEnabled (co.rsk.rpc.modules.personal.PersonalModuleWalletEnabled)1 TxPoolModule (co.rsk.rpc.modules.txpool.TxPoolModule)1 TxPoolModuleImpl (co.rsk.rpc.modules.txpool.TxPoolModuleImpl)1 ActivationConfigsForTest (org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)1 Block (org.ethereum.core.Block)1 HashMapDB (org.ethereum.datasource.HashMapDB)1